4 releases

0.0.4 Feb 23, 2022
0.0.3 Feb 21, 2022
0.0.2 Jan 28, 2022
0.0.1 Jan 28, 2022

#7 in #tower-layer

38 downloads per month

MIT license

15KB
276 lines

tower-fault-injector Latest Version

tower-fault-injector is a library for injecting various faults into a tower::Service.

Layers

You can use the following layers to inject faults into a service:

  • ErrorLayer - randomly inject errors into a service.
  • LatencyLayer - randomly add latency into a service.

Example usage

use tower_fault_injector::latency::LatencyLayer;
use tower::{service_fn, ServiceBuilder};

async fn my_service() -> Result<(), ()> {
    Ok(())
}

// Initialize a LatencyLayer with a 10% probability of injecting
// 200 to 500 milliseconds of latency.
let latency_layer = LatencyLayer::new(0.1, 200..500);

let service = ServiceBuilder::new()
    .layer(latency_layer)
    .service(service_fn(my_service));

lib.rs:

Fault injection utilities for tower

This crate provides tower::Layers that can be used to inject various faults into a tower::Service.

Layers

You can use the following layers to inject faults into a service:

Example

use tower_fault_injector::latency::LatencyLayer;
use tower::{service_fn, ServiceBuilder};

// Initialize a LatencyLayer with a 10% probability of injecting
// 200 to 500 milliseconds of latency.
let latency_layer = LatencyLayer::new(0.1, 200..500).unwrap();

let service = ServiceBuilder::new()
    .layer(latency_layer)
    .service(service_fn(my_service));

Dependencies

~1.3–3MB
~59K SLoC