Expand description
Task leak detection utilities for testing.
This module provides a mechanism to verify that all spawned tasks have exited after a test completes, similar to goleak for Go goroutines.
§Example
ⓘ
use crate::shared::task_leak::TaskTracker;
use crate::shared::shutdown::Shutdown;
#[tokio::test]
async fn test_no_task_leaks() {
let shutdown = Shutdown::new();
let tracker = TaskTracker::new();
// Spawn tasks using the tracker
let mut shutdown_rx = shutdown.subscribe();
tracker.spawn("MyTask", async move {
let _ = shutdown_rx.recv().await;
Ok(())
});
// Trigger shutdown
shutdown.trigger();
// Verify all tasks complete within timeout
tracker.verify_no_leaks(Duration::from_secs(5)).await.unwrap();
}Structs§
- Task
Tracker - Tracks spawned tasks and detects leaks.
- Tracked
Task 🔒