pub async fn assert_holds_for<F, Fut>(
duration: Duration,
what: impl Display + Send,
check: F,
) -> Result<()>Expand description
Asserts that the condition checked by check holds for duration.
Use this instead of a fixed sleep followed by an assertion to verify that something does not
happen, e.g. that a transaction stays in the pool. check returns whether the condition still
holds, as a future like the poll of poll_until, so it can query the node over RPC and
return errors with ?.
The first check starts immediately, every further check POLL_INTERVAL after the previous
one returned, and the last check starts at duration after the call, so the condition is
verified at both ends of duration. A condition that breaks and recovers between two checks
goes unnoticed. Checks are not cancelled, so a successful call takes duration plus the time of
the last check.
Returns the first error returned by check, or an error as soon as a check returns false,
naming what and the time from the call to the start of that check, e.g. expected transaction to stay in the pool for 2s, but it did not hold after 1.24s.
what is held across awaits, so it must be Send for the returned future to be Send. This
rules out format_args!, use format! instead.