Skip to content

Commit ce8d94d

Browse files
authored
tests(iroh-net): Make dht_discovery_smoke test less flaky (#2884)
## Description This test had a hardcoded sleep(1) in there, which is a recipe for flaky tests on CI. Write this more defensively. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions I'm kind of tempted to also remove the flaky marker, but who knows. ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [x] Tests if relevant. - [x] All breaking changes documented.
1 parent 4bfa58e commit ce8d94d

File tree

1 file changed

+21
-13
lines changed
  • iroh-net/src/discovery/pkarr

1 file changed

+21
-13
lines changed

iroh-net/src/discovery/pkarr/dht.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ mod tests {
413413
#[tokio::test]
414414
#[ignore = "flaky"]
415415
async fn dht_discovery_smoke() -> TestResult {
416-
let _ = tracing_subscriber::fmt::try_init();
416+
let _logging_guard = iroh_test::logging::setup();
417417
let ep = crate::Endpoint::builder().bind().await?;
418418
let secret = ep.secret_key().clone();
419419
let testnet = mainline::dht::Testnet::new(2);
@@ -438,19 +438,27 @@ mod tests {
438438
});
439439

440440
// publish is fire and forget, so we have no way to wait until it is done.
441-
tokio::time::sleep(Duration::from_secs(1)).await;
442-
let items = discovery
443-
.resolve(ep, secret.public())
444-
.unwrap()
445-
.collect::<Vec<_>>()
446-
.await;
447-
let mut found_relay_urls = BTreeSet::new();
448-
for item in items.into_iter().flatten() {
449-
if let Some(url) = item.addr_info.relay_url {
450-
found_relay_urls.insert(url);
441+
tokio::time::timeout(Duration::from_secs(30), async move {
442+
loop {
443+
tokio::time::sleep(Duration::from_millis(200)).await;
444+
let mut found_relay_urls = BTreeSet::new();
445+
let items = discovery
446+
.resolve(ep.clone(), secret.public())
447+
.unwrap()
448+
.collect::<Vec<_>>()
449+
.await;
450+
for item in items.into_iter().flatten() {
451+
if let Some(url) = item.addr_info.relay_url {
452+
found_relay_urls.insert(url);
453+
}
454+
}
455+
if found_relay_urls.contains(&relay_url) {
456+
break;
457+
}
451458
}
452-
}
453-
assert!(found_relay_urls.contains(&relay_url));
459+
})
460+
.await
461+
.expect("timeout, relay_url not found on DHT");
454462
Ok(())
455463
}
456464
}

0 commit comments

Comments
 (0)