Skip to content

Commit

Permalink
tests(iroh-net): Make some tests less flaky (#2457)
Browse files Browse the repository at this point in the history
## Description

This removes the flaky marker from a test that I haven't seen being
flaky in a while.

It also tries to put some waiting time in another test to make it less
flaky.

## Breaking Changes

<!-- Optional, if there are any breaking changes document them,
including how to migrate older code. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [x] Self-review.
- ~~[ ] Documentation updates if relevant.~~
- [x] Tests if relevant.
- ~~[ ] All breaking changes documented.~~

Co-authored-by: Rüdiger Klaehn <[email protected]>
  • Loading branch information
flub and rklaehn authored Jul 4, 2024
1 parent 32b23e6 commit bc0b397
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
27 changes: 23 additions & 4 deletions iroh-net/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,13 +1237,12 @@ mod tests {

/// Test that peers saved on shutdown are correctly loaded
#[tokio::test]
#[cfg_attr(target_os = "windows", ignore = "flaky")]
async fn save_load_peers() {
let _guard = iroh_test::logging::setup();

let secret_key = SecretKey::generate();
let root = testdir::testdir!();
let path = root.join("peers");
let peers_path = root.join("peers");

/// Create an endpoint for the test.
async fn new_endpoint(secret_key: SecretKey, peers_path: PathBuf) -> Endpoint {
Expand All @@ -1269,17 +1268,37 @@ mod tests {
info!("setting up first endpoint");
// first time, create a magic endpoint without peers but a peers file and add addressing
// information for a peer
let endpoint = new_endpoint(secret_key.clone(), path.clone()).await;
let endpoint = new_endpoint(secret_key.clone(), peers_path.clone()).await;
assert!(endpoint.connection_infos().is_empty());
endpoint.add_node_addr(node_addr).unwrap();

info!("closing endpoint");
// close the endpoint and restart it
endpoint.close(0u32.into(), b"done").await.unwrap();

// Give the destructors some time to create the file. We use sync code to read the
// file here, it's just a test.
let now = Instant::now();
let mut previous_size = None;
while now.elapsed() < Duration::from_secs(10) {
if peers_path.is_file() {
let size = peers_path.metadata().unwrap().len();
match previous_size {
None => previous_size = Some(size),
Some(previous_size) => {
if previous_size == size {
// File is fully written
break;
}
}
}
}
tokio::time::sleep(Duration::from_millis(100)).await;
}

info!("restarting endpoint");
// now restart it and check the addressing info of the peer
let endpoint = new_endpoint(secret_key, path).await;
let endpoint = new_endpoint(secret_key, peers_path).await;
let ConnectionInfo { mut addrs, .. } = endpoint.connection_info(peer_id).unwrap();
let conn_addr = addrs.pop().unwrap().addr;
assert_eq!(conn_addr, direct_addr);
Expand Down
1 change: 0 additions & 1 deletion iroh-net/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3027,7 +3027,6 @@ mod tests {
}

#[tokio::test(flavor = "multi_thread")]
#[ignore = "flaky"]
async fn test_two_devices_roundtrip_network_change() -> Result<()> {
time::timeout(
Duration::from_secs(50),
Expand Down

0 comments on commit bc0b397

Please sign in to comment.