Function repeated_assert::that
source · pub fn that<A, R>(repetitions: usize, delay: Duration, assert: A) -> Rwhere
A: Fn() -> R,
Expand description
Run the provided function assert
up to repetitions
times with a delay
in between tries.
Panics (including failed assertions) will be caught and ignored until the last try is executed.
Examples
Waiting for a file to appear (re-try up to 10 times, wait 50 ms between tries)
repeated_assert::that(10, Duration::from_millis(50), || {
assert!(Path::new("should_appear_soon.txt").exists());
});
Info
Behind the scene std::panic::set_hook
is used to set a custom panic handler.
For every iteration but the last, panics are ignored and re-tried after a delay.
Only when the last iteration is reached, panics are handled by the panic handler that was registered prior to calling repeated_assert
.
The panic handler can only be registerd for the entire process, and it is done on demand the first time repeated_assert
is used.
repeated_assert
works with multiple threads. Each thread is identified by its name, which is automatically set for tests.