From eeae8e293419bcda48b941f9f270c397e025ea4d Mon Sep 17 00:00:00 2001 From: Michel de Graaf Date: Thu, 10 Sep 2026 14:29:36 +0200 Subject: [PATCH] test(resume): bound what a paused transfer may still take, not when The pause test slept 1.2 s so a read already in flight could time out before bytes were queued "while paused", then required that none of them were taken. The reader's read timeout is 1 s, so any scheduling delay past 200 ms let the in-flight read take the probe and failed the test. The guarantee is that the pause is checked before every read, so after it lands at most the one read already in flight completes. The test now queues more than a read buffer while paused and asserts no more than one buffer was taken, which holds however the reader is scheduled and still fails a transfer that ignores the pause. It also drops the 1.2 s sleep. --- soulseek-rs-lib/tests/resume_e2e.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/soulseek-rs-lib/tests/resume_e2e.rs b/soulseek-rs-lib/tests/resume_e2e.rs index 7271c25..89ef307 100644 --- a/soulseek-rs-lib/tests/resume_e2e.rs +++ b/soulseek-rs-lib/tests/resume_e2e.rs @@ -379,18 +379,21 @@ fn a_live_download_pauses_and_resumes_on_the_same_connection() { matches!(status, DownloadStatus::Paused { .. }) }); - // Give a read already in flight one timeout cycle to observe the pause. - std::thread::sleep(Duration::from_millis(1_200)); + // The pause is checked before every read, so once it lands only the read + // already in flight can finish: one 64 KiB buffer at most. Queue more + // than that, which a transfer ignoring the pause would take all of. let stable_len = fs::metadata(&part_path).expect("paused partial").len(); - let queued_while_paused = 8 * 1024; + let in_flight = 64 * 1024; + let queued_while_paused = in_flight + 8 * 1024; peer.write_all(&content[first_chunk..first_chunk + queued_while_paused]) .expect("queue bytes while paused"); peer.flush().expect("flush bytes while paused"); std::thread::sleep(Duration::from_millis(300)); - assert_eq!( - fs::metadata(&part_path).expect("paused partial").len(), - stable_len, - "a paused transfer must stop consuming its socket" + let paused_len = fs::metadata(&part_path).expect("paused partial").len(); + assert!( + paused_len <= stable_len + in_flight as u64, + "a paused transfer must stop consuming its socket: {paused_len} \ + bytes after pausing at {stable_len}" ); assert!(subject.client.resume_download(&control.username, filename));