Skip to main content

Crate test_better_async

Crate test_better_async 

Source
Expand description

test-better-async: async and timing helpers.

Home of the runtime-agnostic timeout abstraction that backs check!(fut).completes_within(..).

§The runtime gate

Timing out a future needs a runtime-provided sleep. The runtime is chosen at compile time by the mutually-exclusive tokio, async-std, and smol cargo features (in that priority order if more than one is on, which only happens under --all-features). One private function, selected_sleep, is the single place that cfg-branches on them.

If no runtime feature is enabled, the crate still compiles: the RuntimeAvailable marker trait simply has no implementation. Because run_within is bounded where F: RuntimeAvailable on its generic future type, that bound is deferred to the call site (a bound on a concrete type would be rejected at the definition instead). The user who calls completes_within without a runtime feature is the one who sees the error, and the #[diagnostic::on_unimplemented] message on RuntimeAvailable points them at the feature flags.

§Polling: eventually

eventually retries a bool-returning probe until it passes or a deadline is reached, sleeping with exponential Backoff in between. The async form needs the same runtime gate as the timeout (its inter-probe sleep is runtime-provided), so its probe closure carries the deferred RuntimeAvailable bound. eventually_blocking is the runtime-free sibling: it sleeps with std::thread::sleep, so a non-async codebase can use it with no runtime feature at all.

Structs§

Backoff
The inter-probe sleep schedule for eventually and eventually_blocking.
Elapsed
The error returned by run_within when the future outlives its limit.

Traits§

RuntimeAvailable
A marker trait, implemented for every type when (and only when) a runtime feature is enabled.

Functions§

eventually
Retries probe until it resolves to true, or fails once timeout elapses.
eventually_blocking
The runtime-free eventually: retries probe until it returns true or timeout elapses, sleeping between attempts with std::thread::sleep.
eventually_blocking_with
eventually_blocking with an explicit Backoff schedule instead of the default.
eventually_with
eventually with an explicit Backoff schedule instead of the default.
run_within
Awaits fut, but gives up after limit.