tower_fault_injector/
lib.rs

1#![warn(missing_debug_implementations, missing_docs, unreachable_pub)]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3//! # Fault injection utilities for `tower`
4//!
5//! This crate provides [`tower::Layer`]s that can be used to inject various
6//! faults into a [`tower::Service`].
7//!
8//! ## Layers
9//!
10//! You can use the following layers to inject faults into a service:
11//!
12//! * [`ErrorLayer`](error/struct.ErrorLayer.html) - randomly inject errors into a service.
13//! * [`LatencyLayer`](latency/struct.LatencyLayer.html) - randomly add latency into a service.
14//!
15//! ## Example
16//!
17//! ```rust
18//! use tower_fault_injector::latency::LatencyLayer;
19//! use tower::{service_fn, ServiceBuilder};
20//! # async fn my_service() -> Result<(), ()> {
21//! #     Ok(())
22//! # }
23//!
24//! // Initialize a LatencyLayer with a 10% probability of injecting
25//! // 200 to 500 milliseconds of latency.
26//! let latency_layer = LatencyLayer::new(0.1, 200..500).unwrap();
27//!
28//! let service = ServiceBuilder::new()
29//!     .layer(latency_layer)
30//!     .service(service_fn(my_service));
31//! ```
32
33#[cfg(feature = "latency")]
34#[cfg_attr(docsrs, doc(cfg(feature = "latency")))]
35pub mod latency;
36
37#[cfg(feature = "error")]
38#[cfg_attr(docsrs, doc(cfg(feature = "error")))]
39pub mod error;
40
41#[cfg(test)]
42mod test_utils;