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
impl FaultProxy
Sourcepub async fn spawn(upstream_addr: impl ToSocketAddrs) -> Result<FaultProxy>
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.
Sourcepub fn addr(&self) -> SocketAddr
pub fn addr(&self) -> SocketAddr
The local address clients should connect to.
Sourcepub fn set_delay(&self, direction: Direction, delay: Delay)
pub fn set_delay(&self, direction: Direction, delay: Delay)
Set (or replace) the delay applied before forwarding data in direction.
Sourcepub fn clear_delay(&self, direction: Direction)
pub fn clear_delay(&self, direction: Direction)
Remove any delay configured for direction.
Sourcepub fn close_after(&self, direction: Direction, bytes: u64)
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.
Sourcepub fn clear_close_after(&self, direction: Direction)
pub fn clear_close_after(&self, direction: Direction)
Remove the close-after threshold configured for direction.
Sourcepub fn set_chunk_size(&self, size: usize)
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.
Sourcepub fn clear_chunk_size(&self)
pub fn clear_chunk_size(&self)
Stop chunking writes; forward reads in whatever size they arrive.
Sourcepub fn set_drop_all(&self, drop_all: bool)
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.
Trait Implementations§
Source§impl Drop for FaultProxy
impl Drop for FaultProxy
Auto Trait Implementations§
impl Freeze for FaultProxy
impl RefUnwindSafe for FaultProxy
impl Send for FaultProxy
impl Sync for FaultProxy
impl Unpin for FaultProxy
impl UnsafeUnpin for FaultProxy
impl UnwindSafe for FaultProxy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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