repeated-assert
Run assertions multiple times
repeated_assert runs assertions until they either pass
or the maximum amount of repetitions has been reached.
The current thread will be blocked between tries.
This is useful when waiting for events from another thread (or process). Waiting for a short time might result in a failing test, while waiting too long is a waste of time.
Crate features
- async - Enables the
that_asyncandwith_catch_asyncfunctions. It depends on thefuturesandtokiocrates, which is why it's disabled by default.
Examples
Waiting for a file to appear (re-try up to 10 times, wait 50 ms between tries)
that;
Waiting for variable x to equal 3
that;
Temporary variables
that;
Return result
that?;
Async
that_async.await;
Catch failing tests
It's also possible to "catch" failing tests by executing some code if the expressions couldn't be asserted in order to trigger an alternate strategy. This can be useful if the tested program relies on an unreliable service. This counters the idea of a test to some degree, so use it only if the unreliable service is not critical for your program.
Poke unreliable service after 5 unsuccessful assertion attempts
with_catch;