max / audiofiles
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 | } |