Crates.io | toxiproxy_rust |
lib.rs | toxiproxy_rust |
version | 0.1.6 |
source | src |
created_at | 2021-03-07 21:03:02.181444 |
updated_at | 2021-03-20 21:31:56.174742 |
description | Lightweight client for Toxiproxy |
homepage | |
repository | |
max_upload_size | |
id | 365359 |
size | 34,776 |
Rust client for Toxiproxy.
Populating proxies:
let proxies = TOXIPROXY.populate(vec![
Proxy::new(
"socket_service".into(),
"localhost:2001".into(),
"localhost:2000".into(),
),
Proxy::new(
"redis".into(),
"localhost:6000".into(),
"localhost:6379".into(),
)
])?;
Testing with an unavailable connection:
TOXIPROXY.find_and_reset_proxy("redis")?.with_down(|| {
// Calling the desired service...
})?;
Testing with toxics (for full documentation on available toxics see the original docs):
TOXIPROXY.find_and_reset_proxy("redis")?.with_latency("downstream".into(), 2000, 0, 1.0).apply(|| {
// Calling the desired service...
})?;
Or without a safe lambda (that takes care of resetting a proxy):
TOXIPROXY.find_proxy("redis")?.with_latency("downstream".into(), 2000, 0, 1.0)
// Calling the desired service...
TOXIPROXY.find_proxy("redis")?.disable();
// Test unavailability.
TOXIPROXY.find_proxy("redis")?.enable();
Supported toxics:
Using a custom address for Toxiproxy server:
let toxiclient: Client = toxiproxy_rust::Client::new("1.2.3.4:5678");
Tests:
$> cargo test -- --test-threads 1