1 unstable release

0.0.5 Feb 24, 2022

#12 in #fault

Download history 29/week @ 2024-07-20 56/week @ 2024-07-27 10/week @ 2024-08-03 40/week @ 2024-08-10 20/week @ 2024-08-17 48/week @ 2024-08-24 398/week @ 2024-08-31 381/week @ 2024-09-07 113/week @ 2024-09-14 191/week @ 2024-09-21 136/week @ 2024-09-28 102/week @ 2024-10-05 47/week @ 2024-10-12 56/week @ 2024-10-19 50/week @ 2024-10-26 58/week @ 2024-11-02

226 downloads per month

MIT license

21KB
334 lines

tower-fault Latest Version

tower-fault 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::{
    error::ErrorLayer,
    latency::LatencyLayer,
};
use tower::{service_fn, ServiceBuilder};

struct MyRequest {
    value: u64
}

async fn my_service(req: MyRequest) -> Result<(), String> {
    Ok(())
}

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

// ErrorLayer that injects an error if the request value is greater than 10.
let error_layer = ErrorLayer::new(|req: &MyRequest| req.value > 10, |_: &MyRequest| String::from("error"));

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

Dependencies

~1.4–7.5MB
~61K SLoC