diff --git a/server/src/db.rs b/server/src/db.rs index c2d5ef8a2c..ae79f37ff9 100644 --- a/server/src/db.rs +++ b/server/src/db.rs @@ -3747,15 +3747,21 @@ mod tests { let chunks = db.catalog.chunks(); assert_eq!(chunks.len(), 1); + let (sender, receiver) = tokio::sync::oneshot::channel(); + let chunk_a = Arc::clone(&chunks[0]); let chunk_b = Arc::clone(&chunks[0]); let chunk_b = chunk_b.write(); let task = tokio::spawn(async move { + sender.send(()).unwrap(); let _ = chunk_a.read(); }); + // Wait for background task to reach lock + let _ = receiver.await.unwrap(); + // Hold lock for 100 milliseconds blocking background task std::thread::sleep(std::time::Duration::from_millis(100));