Description
Exercise both branches and edge cases of the wait_or_shutdown function to meet testing guidelines.
Problem
The wait_or_shutdown function currently lacks focused unit tests that verify both the timeout and shutdown paths work correctly.
Solution
Add a new async test module with rstest:
#[cfg(test)]
mod tests {
use super::*;
use rstest::rstest;
use tokio::sync::watch;
#[tokio::test]
async fn returns_immediately_on_zero_secs() {
let (_tx, mut rx) = watch::channel(());
WorkerHooks::wait_or_shutdown(Duration::from_secs(0), &mut rx).await;
}
#[tokio::test]
async fn returns_on_shutdown_before_timeout() {
let (tx, mut rx) = watch::channel(());
let mut rx2 = tx.subscribe();
let fut = WorkerHooks::wait_or_shutdown(Duration::from_secs(60), &mut rx2);
tx.send(()).expect("notify");
fut.await;
}
}
Location
- File:
crates/comenqd/src/worker.rs
- Lines: 122-127
References
Description
Exercise both branches and edge cases of the
wait_or_shutdownfunction to meet testing guidelines.Problem
The
wait_or_shutdownfunction currently lacks focused unit tests that verify both the timeout and shutdown paths work correctly.Solution
Add a new async test module with rstest:
Location
crates/comenqd/src/worker.rsReferences