Skip to main content

max / audiofiles

Fix flaky cleanup worker test cleanup_no_orphans_completes_immediately slept a fixed 100ms waiting on the worker thread, and lost that race under a loaded parallel run (failed 2 of 3 full-suite runs). Poll try_recv to a 10s deadline instead, exiting as soon as the event lands. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author: Max Johnson <me@maxj.phd> · 2026-07-20 18:25 UTC
Commit: 50e3cb36a804cdd6a062f6712277253f398fd423
Parent: 242a6ec
1 file changed, +17 insertions, -9 deletions
@@ -163,17 +163,25 @@ mod tests {
163 163 let handle = spawn_cleanup_worker(db_path, store_root).unwrap();
164 164 assert!(handle.send(CleanupCommand::RemoveOrphans));
165 165
166 - // Give the worker a moment to process
167 - std::thread::sleep(std::time::Duration::from_millis(100));
168 -
166 + // Poll to a deadline rather than sleeping a fixed interval: the worker
167 + // runs on its own thread, and a loaded parallel test run can push it
168 + // well past any single "should be plenty" sleep. The deadline is a
169 + // failure bound, not an expected wait — the loop exits as soon as the
170 + // event lands.
171 + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);
169 172 let mut got_complete = false;
170 - while let Some(event) = handle.try_recv() {
171 - if let CleanupEvent::Complete { removed, errors } = event {
172 - assert_eq!(removed, 0);
173 - assert_eq!(errors, 0);
174 - got_complete = true;
173 + while !got_complete && std::time::Instant::now() < deadline {
174 + while let Some(event) = handle.try_recv() {
175 + if let CleanupEvent::Complete { removed, errors } = event {
176 + assert_eq!(removed, 0);
177 + assert_eq!(errors, 0);
178 + got_complete = true;
179 + }
180 + }
181 + if !got_complete {
182 + std::thread::sleep(std::time::Duration::from_millis(10));
175 183 }
176 184 }
177 - assert!(got_complete);
185 + assert!(got_complete, "worker did not report Complete within 10s");
178 186 }
179 187 }