From 7e8d6fa7a4416930372edbebc46f27e953cc94b6 Mon Sep 17 00:00:00 2001 From: giswqs Date: Wed, 11 Nov 2026 08:31:41 -0500 Subject: [PATCH 1/3] test(tiles): end the unknown-size download once the test has looked a_part_of_unknown_size_leaves_the_total_unknown served its chunked part as 200 one-kilobyte chunks with a 20 ms sleep after each, at least 4 s, and waited 20 s for the download to end. On a busy macOS runner the sleeps stretch past that and the wait times out (main runs 42972747124 and 43025563929). The test only needs the download still under way when it reads the progress. The server now stops sleeping once the test has done so, and the rest of the body comes at once: the test takes 0.1 s. --- crates/tiles/src/cache.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/tiles/src/cache.rs b/crates/tiles/src/cache.rs index e931e59e03..b71d31d820 100644 --- a/crates/tiles/src/cache.rs +++ b/crates/tiles/src/cache.rs @@ -4244,6 +4244,10 @@ mod tests { let _turn = crate::cache::turn(); let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); let addr = listener.local_addr().unwrap(); + // Set once the test has looked at the progress mid-download: the rest comes at once, so + // the download's end doesn't wait on 200 sleeps a busy runner stretches (macOS CI). + let looked = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); + let done_looking = looked.clone(); std::thread::spawn(move || { for stream in listener.incoming() { let Ok(mut stream) = stream else { return }; @@ -4252,13 +4256,15 @@ mod tests { let _ = write!(stream, "HTTP/1.1 200 OK\r\nContent-Length: 10\r\nConnection: close\r\n\r\n0123456789"); continue; } - // Chunked, so no length: a 1 kB chunk every 20 ms. + // Chunked, so no length: a 1 kB chunk every 20 ms until the test has looked. let _ = write!(stream, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n"); for _ in 0..200 { if write!(stream, "3e8\r\n{}\r\n", "x".repeat(1000)).is_err() { return; } - std::thread::sleep(std::time::Duration::from_millis(20)); + if !looked.load(std::sync::atomic::Ordering::SeqCst) { + std::thread::sleep(std::time::Duration::from_millis(20)); + } } let _ = write!(stream, "0\r\n\r\n"); } @@ -4280,6 +4286,7 @@ mod tests { std::thread::sleep(std::time::Duration::from_millis(20)); } assert_eq!(progress.fraction(), None, "{progress:?}"); + done_looking.store(true, std::sync::atomic::Ordering::SeqCst); assert!(rx.recv_timeout(std::time::Duration::from_secs(20)).unwrap().is_ok()); } From 015c670b63a7eb605689af090ac76fa9a9f4cecc Mon Sep 17 00:00:00 2001 From: giswqs Date: Wed, 11 Nov 2026 09:06:00 -0500 Subject: [PATCH 2/3] test(tiles): hold the unknown-size part open until the test has looked Review follow-up. The server sent its chunks without sleeping once the test had looked, but a delayed test thread could still see the whole response arrive before it read the progress. It now sends 10 kB, past the 5 kB the test waits for, holds the response open until the test has looked (30 s at most), then sends the rest in one write. Chunks go out as single writes with Nagle's algorithm off. --- crates/tiles/src/cache.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/crates/tiles/src/cache.rs b/crates/tiles/src/cache.rs index b71d31d820..1ffa14afc3 100644 --- a/crates/tiles/src/cache.rs +++ b/crates/tiles/src/cache.rs @@ -4244,27 +4244,33 @@ mod tests { let _turn = crate::cache::turn(); let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); let addr = listener.local_addr().unwrap(); - // Set once the test has looked at the progress mid-download: the rest comes at once, so - // the download's end doesn't wait on 200 sleeps a busy runner stretches (macOS CI). + // Set once the test has looked at the progress mid-download. The server holds the + // response open until then, so the progress is read while bytes are still to come, and + // then sends the rest at once: no sleeps for a busy runner to stretch (macOS CI). let looked = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); let done_looking = looked.clone(); std::thread::spawn(move || { for stream in listener.incoming() { let Ok(mut stream) = stream else { return }; + let _ = stream.set_nodelay(true); let path = read_request(&mut stream).split_whitespace().nth(1).unwrap_or("").to_string(); if path == "/a.shp" { let _ = write!(stream, "HTTP/1.1 200 OK\r\nContent-Length: 10\r\nConnection: close\r\n\r\n0123456789"); continue; } - // Chunked, so no length: a 1 kB chunk every 20 ms until the test has looked. - let _ = write!(stream, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n"); - for _ in 0..200 { - if write!(stream, "3e8\r\n{}\r\n", "x".repeat(1000)).is_err() { - return; - } - if !looked.load(std::sync::atomic::Ordering::SeqCst) { - std::thread::sleep(std::time::Duration::from_millis(20)); - } + // Chunked, so no length: 10 kB, past the 5 kB the test waits for, then a pause + // until the test has looked (bounded, so a failed test doesn't hang the server). + let chunk = format!("3e8\r\n{}\r\n", "x".repeat(1000)); + let head = format!("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n{}", chunk.repeat(10)); + if stream.write_all(head.as_bytes()).is_err() { + return; + } + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30); + while !looked.load(std::sync::atomic::Ordering::SeqCst) && std::time::Instant::now() < deadline { + std::thread::sleep(std::time::Duration::from_millis(5)); + } + if stream.write_all(chunk.repeat(190).as_bytes()).is_err() { + return; } let _ = write!(stream, "0\r\n\r\n"); } From a76deceece43a39b3ef046cf417b771f8b7616c8 Mon Sep 17 00:00:00 2001 From: giswqs Date: Wed, 11 Nov 2026 09:44:13 -0500 Subject: [PATCH 3/3] test(tiles): close the held part at once when the test fails Review follow-up. The server held the unknown-size part open until a flag was set after the progress assertion, for up to 30 s. A failed assertion never set it, so the download stayed in flight while the next tiles test waited for in_flight() to reach zero. The release is now a channel: the test sends on it once it has looked, and a panic drops the sender, so the server closes the response at once. --- crates/tiles/src/cache.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/tiles/src/cache.rs b/crates/tiles/src/cache.rs index 1ffa14afc3..5a2bdbbd6a 100644 --- a/crates/tiles/src/cache.rs +++ b/crates/tiles/src/cache.rs @@ -4244,11 +4244,12 @@ mod tests { let _turn = crate::cache::turn(); let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); let addr = listener.local_addr().unwrap(); - // Set once the test has looked at the progress mid-download. The server holds the + // Sent once the test has looked at the progress mid-download. The server holds the // response open until then, so the progress is read while bytes are still to come, and - // then sends the rest at once: no sleeps for a busy runner to stretch (macOS CI). - let looked = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); - let done_looking = looked.clone(); + // then sends the rest at once: no sleeps for a busy runner to stretch (macOS CI). A + // failed assertion drops the sender, and the server closes the response at once rather + // than holding a download in flight for the tests after this one. + let (release, released) = std::sync::mpsc::channel::<()>(); std::thread::spawn(move || { for stream in listener.incoming() { let Ok(mut stream) = stream else { return }; @@ -4259,15 +4260,14 @@ mod tests { continue; } // Chunked, so no length: 10 kB, past the 5 kB the test waits for, then a pause - // until the test has looked (bounded, so a failed test doesn't hang the server). + // until the test has looked. let chunk = format!("3e8\r\n{}\r\n", "x".repeat(1000)); let head = format!("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nConnection: close\r\n\r\n{}", chunk.repeat(10)); if stream.write_all(head.as_bytes()).is_err() { return; } - let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30); - while !looked.load(std::sync::atomic::Ordering::SeqCst) && std::time::Instant::now() < deadline { - std::thread::sleep(std::time::Duration::from_millis(5)); + if released.recv_timeout(std::time::Duration::from_secs(30)).is_err() { + return; } if stream.write_all(chunk.repeat(190).as_bytes()).is_err() { return; @@ -4292,7 +4292,7 @@ mod tests { std::thread::sleep(std::time::Duration::from_millis(20)); } assert_eq!(progress.fraction(), None, "{progress:?}"); - done_looking.store(true, std::sync::atomic::Ordering::SeqCst); + let _ = release.send(()); assert!(rx.recv_timeout(std::time::Duration::from_secs(20)).unwrap().is_ok()); }