tokio-test-shutdown-timeout

Crates.iotokio-test-shutdown-timeout
lib.rstokio-test-shutdown-timeout
version0.0.2
created_at2025-02-23 10:20:49.116882+00
updated_at2025-02-23 10:20:49.116882+00
descriptionTokio test attribute with a shutdown timeout
homepage
repository
max_upload_size
id1566215
size15,808
Lauri Koskela (luryus)

documentation

README

tokio-test-shutdown-timeout

A wrapper for #[tokio::test] that allows specifying a shutdown timeout.

Useful in situations where normal tokio tests hang because dropping the tokio runtime waits forever for all tasks to finish.

Usage

#[tokio_test_shutdown_timeout::test(1)]
#[should_panic]
async fn minimal_async_test() {

    // Start a forever-running blocking tokio task
    tokio::task::spawn_blocking(|| thread::sleep(Duration::MAX));

    // panic to fail the test
    panic!();
    
    // Normal tokio::test would block here, as dropping the tokio runtime
    // blocks until all tasks quit, and we have a task that never quits.
    // This custom version uses tokio's shutdown_timeout to avoid the deadlock.
}
Commit count: 0

cargo fmt