Skip to main content

FaultInjectingTimer

Struct FaultInjectingTimer 

Source
pub struct FaultInjectingTimer { /* private fields */ }
Available on crate feature 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

Source

pub fn new<F>(failure_point: TimerFailurePoint, error_factory: F) -> Self
where F: Fn() -> TimeError + Send + Sync + 'static,

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.

Source

pub fn backend_unavailable( failure_point: TimerFailurePoint, backend: &'static str, message: &str, ) -> Self

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.

Source

pub fn failure_point(&self) -> TimerFailurePoint

Returns the configured Timer lifecycle failure point.

§Returns

Registration or completion according to fixture construction.

Source

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

Source§

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>

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.

Source§

fn after(&self, duration: Duration) -> Result<TimerFuture, TimeError>

Registers a notification after a relative duration. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.