Skip to main content

FaultInjector

Struct FaultInjector 

Source
pub struct FaultInjector { /* private fields */ }
Expand description

Fault injector for testing resilience scenarios.

Thread-safe structure that can be shared across provider and tests to inject faults dynamically during test execution.

Implementations§

Source§

impl FaultInjector

Source

pub fn new() -> Self

Create a new fault injector with no faults enabled.

Source

pub fn disable_notifier(&self)

Disable the notifier - prevents it from being spawned.

When called before provider creation, the notifier thread will not start, simulating a notifier failure scenario.

Source

pub fn is_notifier_disabled(&self) -> bool

Check if the notifier is disabled.

Source

pub fn set_notifier_should_panic(&self, should_panic: bool)

Set whether the notifier should panic on next iteration.

Source

pub fn should_notifier_panic(&self) -> bool

Check if the notifier should panic.

Source

pub fn set_refresh_delay(&self, delay: Duration)

Set artificial delay for refresh queries (simulates slow database).

Source

pub fn get_refresh_delay(&self) -> Duration

Get the current refresh delay.

Source

pub fn set_refresh_should_error(&self, should_error: bool)

Set whether the next refresh query should return an error.

Source

pub fn should_refresh_error(&self) -> bool

Check and consume the refresh error flag.

Source

pub fn trigger_reconnect(&self)

Force the notifier to reconnect (simulates connection drop).

Source

pub fn should_reconnect(&self) -> bool

Check and consume the reconnect flag.

Source

pub fn set_clock_skew(&self, skew: Duration)

Set clock skew offset in milliseconds.

Positive values simulate a clock that is ahead (future timestamps). Negative values simulate a clock that is behind (past timestamps).

This offset is added to all now_millis() calculations in the provider, allowing simulation of clock drift between nodes.

§Example
use duroxide_pg_opt::FaultInjector;
use std::time::Duration;

let fi = FaultInjector::new();
// Simulate clock 500ms ahead
fi.set_clock_skew(Duration::from_millis(500));

// Simulate clock 200ms behind
fi.set_clock_skew_signed(-200);
Source

pub fn set_clock_skew_signed(&self, skew_ms: i64)

Set clock skew offset in milliseconds (signed).

Positive values simulate a clock that is ahead. Negative values simulate a clock that is behind.

Source

pub fn get_clock_skew_ms(&self) -> i64

Get the current clock skew offset in milliseconds.

Source

pub fn clear_clock_skew(&self)

Clear the clock skew (reset to 0).

Trait Implementations§

Source§

impl Debug for FaultInjector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FaultInjector

Source§

fn default() -> FaultInjector

Returns the “default value” for a type. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more