Skip to content

Commit 0e8a681

Browse files
committed
test: add freenet-test-network integration diagnostics
1 parent 5003947 commit 0e8a681

File tree

5 files changed

+305
-11
lines changed

5 files changed

+305
-11
lines changed

Cargo.lock

Lines changed: 142 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ arbitrary = { features = ["derive"], version = "1" }
9090
chrono = { features = ["arbitrary"], workspace = true }
9191
freenet-stdlib = { features = ["net", "testing"], workspace = true }
9292
freenet-macros = { path = "../freenet-macros" }
93+
freenet-test-network = "0.1.1"
9394
httptest = "0.16"
9495
statrs = "0.18"
9596
tempfile = "3"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//! Diagnostic test to understand connectivity failures
2+
3+
use freenet_test_network::{BuildProfile, FreenetBinary, TestNetwork};
4+
use std::time::Duration;
5+
6+
#[tokio::test]
7+
async fn diagnose_connectivity_failure() {
8+
// Build network with more relaxed settings
9+
let result = TestNetwork::builder()
10+
.gateways(1)
11+
.peers(2)
12+
.binary(FreenetBinary::CurrentCrate(BuildProfile::Debug))
13+
.require_connectivity(0.5) // Lower threshold - just need 50%
14+
.connectivity_timeout(Duration::from_secs(60)) // Longer timeout
15+
.preserve_temp_dirs_on_failure(true)
16+
.build()
17+
.await;
18+
19+
match result {
20+
Ok(network) => {
21+
println!("\n✓ Network started successfully!");
22+
23+
// Print network info
24+
println!("\nNetwork topology:");
25+
println!(" Gateway: {}", network.gateway(0).ws_url());
26+
for i in 0..2 {
27+
println!(" Peer {}: {}", i, network.peer(i).ws_url());
28+
}
29+
30+
// Read and print logs
31+
println!("\n=== Network Logs ===");
32+
if let Ok(logs) = network.read_logs() {
33+
for entry in logs.iter().take(200) {
34+
println!(
35+
"[{}] {}: {}",
36+
entry.peer_id,
37+
entry.level.as_deref().unwrap_or("INFO"),
38+
entry.message
39+
);
40+
}
41+
println!("\n(Showing first 200 log lines, total: {})", logs.len());
42+
}
43+
}
44+
Err(e) => {
45+
eprintln!("\n✗ Network failed to start: {:?}", e);
46+
panic!("Network startup failed - see logs above");
47+
}
48+
}
49+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! Manual test to inspect network logs
2+
3+
use freenet_test_network::{BuildProfile, FreenetBinary, TestNetwork};
4+
use std::time::Duration;
5+
6+
#[tokio::test]
7+
#[ignore] // Run manually with: cargo test manual_network_test -- --ignored --nocapture
8+
async fn manual_network_test() {
9+
let network = TestNetwork::builder()
10+
.gateways(1)
11+
.peers(1)
12+
.binary(FreenetBinary::CurrentCrate(BuildProfile::Debug))
13+
.require_connectivity(0.5)
14+
.connectivity_timeout(Duration::from_secs(10)) // Short timeout so we can inspect quickly
15+
.preserve_temp_dirs_on_failure(true)
16+
.build()
17+
.await;
18+
19+
match network {
20+
Ok(ref net) => {
21+
println!("\n=== Network Started ===");
22+
println!("Gateway: {}", net.gateway(0).ws_url());
23+
println!("Peer: {}", net.peer(0).ws_url());
24+
25+
// Print all logs
26+
if let Ok(logs) = net.read_logs() {
27+
println!("\n=== Logs ===");
28+
for entry in logs {
29+
println!(
30+
"[{}] {}: {}",
31+
entry.peer_id,
32+
entry.level.as_deref().unwrap_or("INFO"),
33+
entry.message
34+
);
35+
}
36+
}
37+
38+
// Keep network alive for inspection
39+
println!("\nNetwork is running. Press Ctrl+C to exit.");
40+
tokio::time::sleep(Duration::from_secs(300)).await;
41+
}
42+
Err(e) => {
43+
eprintln!("\n✗ Network failed: {:?}", e);
44+
// Try to read logs anyway if temp dirs still exist
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)