From 3507e96d8402ea681343a4b3d63aa87bdceb022f Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 21 Nov 2026 22:42:30 +0000 Subject: mycelium: the fake daemon's tests wait for its first poll, not one more They waited for one more request for the inbox than the daemon had had when they looked, after the transport had started: where its first request was in by then, they waited for a second, which an idle transport never makes (its first waits in the daemon), and failed after 2 s. Each test's daemon is new: its first request is the one meant. --- src/transport/mycelium/fake_daemon.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/transport') diff --git a/src/transport/mycelium/fake_daemon.rs b/src/transport/mycelium/fake_daemon.rs index de3e7e3..1032606 100644 --- a/src/transport/mycelium/fake_daemon.rs +++ b/src/transport/mycelium/fake_daemon.rs @@ -151,10 +151,11 @@ async fn taking( (transport, rx) } -/// Waits until `daemon` has had more requests for its inbox than `than`. -async fn polled_since(daemon: &Daemon, than: usize) { +/// Waits until `daemon` has had a request for its inbox: the transport's first, which +/// waits there while nothing comes in. +async fn polled(daemon: &Daemon) { tokio::time::timeout(SOON, async { - while daemon.polls() <= than { + while daemon.polls() == 0 { tokio::time::sleep(Duration::from_millis(10)).await; } }) @@ -188,7 +189,7 @@ async fn a_node_with_nothing_coming_in_sends_at_once() { let (daemon, url) = started().await; let (transport, _taken) = taking(url).await; // The inbox is waited for in the daemon by now. - polled_since(&daemon, daemon.polls()).await; + polled(&daemon).await; tokio::time::sleep(Duration::from_millis(100)).await; let message = encode_message(THEIRS, &a_message(), wire::VERSION).expect("encoded"); for n in 1..=3 { @@ -206,7 +207,7 @@ async fn a_node_with_nothing_coming_in_sends_at_once() { async fn a_message_is_taken_as_it_comes() { let (daemon, url) = started().await; let (_transport, mut taken) = taking(url).await; - polled_since(&daemon, daemon.polls()).await; + polled(&daemon).await; for _ in 0..3 { tokio::time::sleep(Duration::from_millis(100)).await; daemon.comes(inbound(&a_message())); @@ -236,7 +237,7 @@ async fn messages_coming_while_the_node_sends_all_come_in() { const MESSAGES: usize = 50; let (daemon, url) = started().await; let (transport, mut taken) = taking(url).await; - polled_since(&daemon, daemon.polls()).await; + polled(&daemon).await; let message = encode_message(THEIRS, &a_message(), wire::VERSION).expect("encoded"); let sending = tokio::spawn({ let transport = transport.clone(); -- cgit v1.3.1