tower-fault-injector

Crates.iotower-fault-injector
lib.rstower-fault-injector
version0.0.4
sourcesrc
created_at2022-01-28 12:23:49.376237
updated_at2022-02-23 20:02:04.461365
descriptionTower layers for fault injection
homepage
repositoryhttps://github.com/nmoutschen/tower-fault-injector
max_upload_size
id523059
size42,830
Nicolas Moutschen (nmoutschen)

documentation

README

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));
Commit count: 20

cargo fmt