Skip to content

Commit

Permalink
Fix a test flake (#1626)
Browse files Browse the repository at this point in the history
Avoid a race in a test of read only downstairs that can connect before
or after IO is sent.  We avoid this race by waiting for all downstairs we
expect to be present to show up before we send the IO.

Fixes #1623
  • Loading branch information
leftwo authored Feb 21, 2025
1 parent 6834003 commit 029cd07
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion upstairs/src/dummy_downstairs_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2988,14 +2988,34 @@ async fn test_ro_activate_from_list(activate: [bool; 3]) {
guest,
};

// Wait for all downstairs we expect to be active to actually be active.
// If we don't do this, it's possible for a downstairs to join after
// we send the IO, which will cause the read to be skipped, and we
// will end up acking the following flush.
loop {
tokio::time::sleep(Duration::from_secs(1)).await;
let ds = harness.guest.downstairs_state().await.unwrap();
if activate[0] && ds[ClientId::new(0)] != DsState::Active {
continue;
}
if activate[1] && ds[ClientId::new(1)] != DsState::Active {
continue;
}
if activate[2] && ds[ClientId::new(2)] != DsState::Active {
continue;
}
break;
}

// We must `spawn` here because `read` will wait for the response to
// come back before returning
let h = harness.spawn(|guest| async move {
let mut buffer = Buffer::new(1, 512);
guest.read(BlockIndex(0), &mut buffer).await.unwrap();
});

// Ack the read on the downstairs that are active.
// Ack the read on the downstairs that are active, but, only if a
// downstairs has actually joined.
if activate[0] {
harness.ds1().ack_read().await;
}
Expand Down

0 comments on commit 029cd07

Please sign in to comment.