Skip to main content

FaultProxy

Struct FaultProxy 

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

A TCP proxy that forwards bytes between test clients and an upstream Redis node while injecting configurable network faults.

Construct with FaultProxy::spawn. Fault controls can be changed at any time via the returned handle; delay, close-after, and chunk-size take effect on data already in flight (checked on every read), while FaultProxy::set_drop_all is snapshotted once per accepted connection. The proxy stops accepting new connections when the handle is dropped; already-established connections run to completion.

Implementations§

Source§

impl FaultProxy

Source

pub async fn spawn(upstream_addr: impl ToSocketAddrs) -> Result<FaultProxy>

Bind an ephemeral local TCP listener that proxies to upstream_addr and return a handle to it. The proxy starts in clean-passthrough mode.

Source

pub fn addr(&self) -> SocketAddr

The local address clients should connect to.

Source

pub fn set_delay(&self, direction: Direction, delay: Delay)

Set (or replace) the delay applied before forwarding data in direction.

Source

pub fn clear_delay(&self, direction: Direction)

Remove any delay configured for direction.

Source

pub fn close_after(&self, direction: Direction, bytes: u64)

Close the connection once bytes total have been forwarded in direction, cutting mid-buffer if the triggering read straddles the threshold. Applies independently to every connection accepted while this setting is active.

Source

pub fn clear_close_after(&self, direction: Direction)

Remove the close-after threshold configured for direction.

Source

pub fn set_chunk_size(&self, size: usize)

Split forwarded writes into pieces of at most size bytes, in both directions. Use size == 1 to exercise incremental decoders.

Source

pub fn clear_chunk_size(&self)

Stop chunking writes; forward reads in whatever size they arrive.

Source

pub fn set_drop_all(&self, drop_all: bool)

Enable or disable black-hole mode. While enabled, newly accepted connections are held open (no upstream connection is made, nothing is ever forwarded or written back) until the client disconnects or the proxy is dropped. Existing connections are unaffected.

Source

pub fn reset(&self)

Clear every fault control, returning the proxy to clean passthrough for new connections.

Trait Implementations§

Source§

impl Drop for FaultProxy

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> 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, 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.