pub struct FaultInjectingTimer { /* private fields */ }test-util only.Expand description
A deterministic Timer fixture that fails registration or completion.
The fixture owns a private manual clock domain. Foreign deadlines and
already reached deadlines retain the normal Timer contract; only valid
future deadlines reach the configured failure point.
§Examples
use qubit_clock::{
Timer,
test_util::{FaultInjectingTimer, TimerFailurePoint},
};
use std::time::Duration;
let timer = FaultInjectingTimer::backend_unavailable(
TimerFailurePoint::Registration,
"example",
"backend offline",
);
assert!(timer.after(Duration::from_secs(1)).is_err());
assert_eq!(1, timer.registration_count());Implementations§
Source§impl FaultInjectingTimer
impl FaultInjectingTimer
Sourcepub fn new<F>(failure_point: TimerFailurePoint, error_factory: F) -> Self
pub fn new<F>(failure_point: TimerFailurePoint, error_factory: F) -> Self
Creates a Timer that invokes error_factory at failure_point.
§Parameters
failure_point- Registration or completion stage to fail.error_factory- Thread-safe factory returning one fresh error for every failed future-deadline registration.
§Returns
A fault-injecting Timer with a new private monotonic clock domain.
§Panics
Panics if process-wide clock-domain identifiers are exhausted.
Creates a Timer reporting a custom backend-unavailable error.
§Parameters
failure_point- Registration or completion stage to fail.backend- Stable static name identifying the unavailable backend.message- Error message copied into each fresh source error.
§Returns
A fault-injecting Timer producing
TimerUnavailableError::BackendUnavailable.
§Panics
Panics if process-wide clock-domain identifiers are exhausted.
Sourcepub fn failure_point(&self) -> TimerFailurePoint
pub fn failure_point(&self) -> TimerFailurePoint
Returns the configured Timer lifecycle failure point.
§Returns
Registration or completion according to fixture construction.
Sourcepub fn registration_count(&self) -> usize
pub fn registration_count(&self) -> usize
Returns the number of valid future-deadline registrations attempted.
Foreign and already reached deadlines do not increment this count.
§Returns
The current registration count. Concurrent observations are intended for test diagnostics and use relaxed ordering.
Trait Implementations§
Source§impl Timer for FaultInjectingTimer
impl Timer for FaultInjectingTimer
Source§fn clock(&self) -> &dyn MonotonicClock
fn clock(&self) -> &dyn MonotonicClock
Returns the fixture’s private manual monotonic clock.
§Returns
The clock defining valid deadlines for this Timer.
Source§fn at(&self, deadline: MonotonicInstant) -> Result<TimerFuture, TimeError>
fn at(&self, deadline: MonotonicInstant) -> Result<TimerFuture, TimeError>
Registers a future deadline and injects the configured failure.
§Parameters
deadline- Absolute deadline expected in this Timer’s clock domain.
§Returns
An immediately ready successful future for a reached deadline, or a failing future when completion failure is configured.
§Errors
Returns TimeError::ClockDomainMismatch for a foreign deadline.
Returns the error factory’s value directly when registration failure is
configured.
§Panics
Propagates a panic raised by the configured error factory.