diff --git a/src/daemon/filter.rs b/src/daemon/filter.rs index 689e410..269c8d2 100644 --- a/src/daemon/filter.rs +++ b/src/daemon/filter.rs @@ -218,15 +218,20 @@ impl FilterManager { let triggers = self.triggers.clone(); let m = m.clone(); let t = *t; + let shutdown = self.shutdown.clone(); tokio::spawn(async move { - tokio::time::sleep(sleep_duration).await; - triggers - .fetch_and_update_ext::, _>(&m, |set| { - let mut set = set.unwrap_or_default(); - set.remove(&t); - Some(set) - }) - .unwrap(); + if tokio::select! { + _ = shutdown.wait() => false, + _ = tokio::time::sleep(sleep_duration) => true + } { + triggers + .fetch_and_update_ext::, _>(&m, |set| { + let mut set = set.unwrap_or_default(); + set.remove(&t); + Some(set) + }) + .unwrap(); + } }); } } diff --git a/tests/simple.rs b/tests/simple.rs index 77b870c..30ae52e 100644 --- a/tests/simple.rs +++ b/tests/simple.rs @@ -148,9 +148,12 @@ async fn simple() { file_with_contents(out_path, ""); - assert!(daemon(config_path.into(), socket_path.into()) - .await - .is_err()); + let daemon_exit = daemon(config_path.into(), socket_path.into()).await; + assert!(daemon_exit.is_err()); + assert_eq!( + daemon_exit.unwrap_err().to_string(), + "quitting because all streams finished" + ); // 36 from DB // 12 from DB @@ -183,8 +186,11 @@ async fn simple() { file_with_contents(out_path, ""); let daemon_exit = daemon(config_path.into(), socket_path.into()).await; - eprintln!("daemon exit with {:?}", daemon_exit); assert!(daemon_exit.is_err()); + assert_eq!( + daemon_exit.unwrap_err().to_string(), + "quitting because all streams finished" + ); // make sure all numbers appear in the output assert_eq!(