Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(iroh): Make test_relay_datagram_queue less timing dependent #3106

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions iroh/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4096,26 +4096,20 @@ mod tests {
tasks.spawn({
let queue = queue.clone();
async move {
let mut expected_msgs = vec![false; capacity];

while let Ok(datagram) = tokio::time::timeout(
Duration::from_millis(100),
futures_lite::future::poll_fn(|cx| {
let mut expected_msgs: BTreeSet<usize> = (0..capacity).collect();
while !expected_msgs.is_empty() {
let datagram = futures_lite::future::poll_fn(|cx| {
queue.poll_recv(cx).map(|result| result.unwrap())
}),
)
.await
{
})
.await;

let msg_num = usize::from_le_bytes(datagram.buf.as_ref().try_into().unwrap());
debug!("Received {msg_num}");

if expected_msgs[msg_num] {
panic!("Received message number {msg_num} more than once (duplicated)");
if !expected_msgs.remove(&msg_num) {
panic!("Received message number {msg_num} twice or more, but expected it only exactly once.");
}

expected_msgs[msg_num] = true;
}

assert!(expected_msgs.into_iter().all(|is_set| is_set));
}
});

Expand All @@ -4124,6 +4118,7 @@ mod tests {
let queue = queue.clone();
let url = url.clone();
async move {
debug!("Sending {i}");
queue
.try_send(RelayRecvDatagram {
url,
Expand All @@ -4135,7 +4130,13 @@ mod tests {
});
}

tasks.join_all().await;
// We expect all of this work to be done in 10 seconds max.
if tokio::time::timeout(Duration::from_secs(10), tasks.join_all())
.await
.is_err()
{
panic!("Timeout - not all messages between 0 and {capacity} received.");
}
}

#[tokio::test]
Expand Down
Loading