From 1c9c6d40901121bafbde467f99871cf660a75f8d Mon Sep 17 00:00:00 2001 From: Eureka Date: Tue, 17 Nov 2026 01:59:41 +0000 Subject: [PATCH] huginn-sources: test that a run holds the lock for its whole life Co-Authored-By: Claude Sonnet 5.5 --- .../huginn-daemon/src/bin/huginn-sources.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/huginn-daemon/src/bin/huginn-sources.rs b/crates/huginn-daemon/src/bin/huginn-sources.rs index 829ae34..5347c04 100644 --- a/crates/huginn-daemon/src/bin/huginn-sources.rs +++ b/crates/huginn-daemon/src/bin/huginn-sources.rs @@ -339,6 +339,28 @@ mod tests { drop(held); } + #[test] + fn the_lock_is_held_for_the_whole_run() { + let dir = tempfile::tempdir().unwrap(); + let lock = dir.path().join("lock"); + // A qdrant that accepts the run's first request and says nothing: the run is mid-flight while we probe the lock. + let qdrant = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + let url = format!("http://{}", qdrant.local_addr().unwrap()); + let run = parse(args(&format!("--state-root /s --qdrant-url {url} --ollama-url http://127.0.0.1:1 --embedding-model m --lock-file {}", lock.display())), now()).unwrap(); + let worker = std::thread::spawn(move || execute(run)); + let (connection, _) = qdrant.accept().unwrap(); + assert!(matches!(take_lock(&lock), Err(Stop::Locked)), "the run must hold the lock while it works"); + drop(connection); + // Refuse any retry the same way until the run gives up. + qdrant.set_nonblocking(true).unwrap(); + while !worker.is_finished() { + drop(qdrant.accept()); + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert!(worker.join().unwrap().is_ok()); + assert!(take_lock(&lock).is_ok(), "the lock is released when the run ends"); + } + #[test] fn a_held_lock_stops_the_run_untouched() { let dir = tempfile::tempdir().unwrap();