Expand description
Task related testing utilities.
This module provides utilities for creating test
Context
s,
Waker
s and
Spawn
implementations.
Test contexts:
noop_context
creates a context that ignores calls tocx.waker().wake_by_ref()
.panic_context
creates a context that panics whencx.waker().wake_by_ref()
is called.
Test wakers:
noop_waker
creates a waker that ignores calls towake
.panic_waker
creates a waker that panics whenwake
is called.new_count_waker
creates a waker that increments a counter wheneverwake
is called.
Test spawners:
NoopSpawner
ignores calls tospawn
PanicSpawner
panics ifspawn
is called.RecordSpawner
records the spawned futures.
For convenience there additionally exist various functions that directly
return waker/spawner references: noop_waker_ref
, panic_waker_ref
,
noop_spawner_mut
and panic_spawner_mut
.
Structs§
- Awoken
Count - Number of times the waker was awoken.
- Noop
Spawner - An implementation of
Spawn
that discards spawned futures when used. - Panic
Spawner - An implementation of
Spawn
that panics when used. - Record
Spawner - An implementation of
Spawn
that records anyFuture
s spawned on it.
Functions§
- new_
count_ waker - Create a new
Waker
that counts the number of times it’s awoken. - noop_
context - Create a new
Context
where the waker will ignore any uses. - noop_
spawner_ mut - Get a reference to a singleton instance of
NoopSpawner
. - noop_
waker - Create a new
Waker
which does nothing whenwake()
is called on it. - noop_
waker_ ref - Get a static reference to a
Waker
which does nothing whenwake()
is called on it. - panic_
context - Create a new
Context
where the waker will panic if used. - panic_
spawner_ mut - Get a reference to a singleton instance of
PanicSpawner
. - panic_
waker - Create a new
Waker
which will panic whenwake()
is called on it. TheWaker
can be converted into aWaker
which will behave the same way. - panic_
waker_ ref - Get a global reference to a
Waker
referencing a singleton instance of aWaker
which panics when woken.