From 3b775a23c8697def324154fba5662c3abb32ce39 Mon Sep 17 00:00:00 2001 From: Eureka Date: Wed, 11 Nov 2026 00:06:27 +0000 Subject: [PATCH] Desk door tests: a peer that never reads fails the suite by assertion in five seconds, not by hanging it Co-Authored-By: Claude Sonnet 5.5 --- crates/huginn-daemon/src/desk_door_tests.rs | 25 ++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/huginn-daemon/src/desk_door_tests.rs b/crates/huginn-daemon/src/desk_door_tests.rs index b8b48f6..4eabdca 100644 --- a/crates/huginn-daemon/src/desk_door_tests.rs +++ b/crates/huginn-daemon/src/desk_door_tests.rs @@ -992,17 +992,26 @@ mod bounds { fn a_peer_that_never_reads_is_cut_off_at_one_second() { let (_peer, server) = UnixStream::pair().unwrap(); let mut stream = Deadlined::new(server, DESK_CONNECTION_DEADLINE); - let (chunk, started) = (vec![0_u8; 64 * 1024], Instant::now()); - let error = loop { - if let Err(error) = stream.write(&chunk) { - break error; - } - }; - let took = started.elapsed(); + // The writer runs on its own thread and the test waits for it with a clock of its own: without + // the deadline the write blocks for good, and that must fail this test, not hang the suite. + let (sent, heard) = std::sync::mpsc::channel(); + let writer = std::thread::spawn(move || { + let (chunk, started) = (vec![0_u8; 64 * 1024], Instant::now()); + let error = loop { + if let Err(error) = stream.write(&chunk) { + break error; + } + }; + let took = started.elapsed(); + let again = stream.write(&chunk).unwrap_err().kind(); + let _ = sent.send((error, took, again)); + }); + let (error, took, again) = heard.recv_timeout(Duration::from_secs(5)).expect("a peer that never reads is cut off within seconds, not waited on"); + writer.join().unwrap(); // The kernel's send timeout reads as WouldBlock; the deadline already spent reads as TimedOut. assert!(matches!(error.kind(), std::io::ErrorKind::WouldBlock | std::io::ErrorKind::TimedOut), "{error:?}"); assert!(took >= Duration::from_millis(950) && took < Duration::from_millis(1250), "the write was cut after {took:?}"); - assert_eq!(stream.write(&chunk).unwrap_err().kind(), std::io::ErrorKind::TimedOut, "once spent, nothing more is written"); + assert_eq!(again, std::io::ErrorKind::TimedOut, "once spent, nothing more is written"); } /// A catalog is a reply like any other and is measured against the response bound: one that