Skip to content

Add focused tests for wait_or_shutdown timeout and shutdown paths #89

@coderabbitai

Description

@coderabbitai

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

Metadata

Metadata

Assignees

Labels

lowAin't annoying anyone but the QA department

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions