Avoid using real sleeps or delays in tests as they significantly slow down the test suite and can introduce flakiness. Instead, use simulated time with the `start_paused` parameter for time-dependent tests:
Avoid using real sleeps or delays in tests as they significantly slow down the test suite and can introduce flakiness. Instead, use simulated time with the start_paused
parameter for time-dependent tests:
// Instead of this:
#[tokio::test]
async fn slow_test() {
// This will actually wait 500ms, making tests slow
tokio::time::sleep(Duration::from_millis(500)).await;
// test logic...
}
// Do this:
#[tokio::test(start_paused = true)]
async fn fast_test() {
// This will execute immediately with simulated time
tokio::time::sleep(Duration::from_millis(500)).await;
// test logic...
}
For tests that need to respond to events or could potentially hang (like waiting for signals), consider:
With hundreds of tests in the codebase, even small performance improvements per test can significantly reduce the overall test execution time.
Enter the URL of a public GitHub repository