Attribute Macro flaky_test::flaky_test
source · #[flaky_test]
Expand description
A flaky test will be run multiple times until it passes.
Example
use flaky_test::flaky_test;
// By default it will be retried up to 3 times.
#[flaky_test]
fn test_default() {
println!("should pass");
}
// The number of max attempts can be adjusted via `times`.
#[flaky_test(times = 5)]
fn usage_with_named_args() {
println!("should pass");
}
// Async tests can be run by passing `tokio`.
// Make sure `tokio` is added in your `Cargo.toml`.
#[flaky_test(tokio)]
async fn async_test() {
let res = async_operation().await.unwrap();
assert_eq!(res, 42);
}
// `tokio` and `times` can be combined.
#[flaky_test(tokio, times = 5)]
async fn async_test_five_times() {
let res = async_operation().await.unwrap();
assert_eq!(res, 42);
}
// Any arguments that `#[tokio::test]` supports can be specified.
#[flaky_test(tokio(flavor = "multi_thraed", worker_threads = 2))]
async fn async_test_complex() {
let res = async_operation().await.unwrap();
assert_eq!(res, 42);
}