7 releases

0.1.6 Mar 20, 2021
0.1.5 Mar 17, 2021

#2584 in Database interfaces

Download history 315/week @ 2024-03-14 635/week @ 2024-03-21 630/week @ 2024-03-28 576/week @ 2024-04-04 485/week @ 2024-04-11 705/week @ 2024-04-18 632/week @ 2024-04-25 800/week @ 2024-05-02 635/week @ 2024-05-09 895/week @ 2024-05-16 634/week @ 2024-05-23 1012/week @ 2024-05-30 967/week @ 2024-06-06 1327/week @ 2024-06-13 1438/week @ 2024-06-20 805/week @ 2024-06-27

4,670 downloads per month

MIT license

29KB
391 lines

Toxiproxy - Rust client

Build Status Crates.io

Rust client for Toxiproxy.

Usage

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");

Development

Tests:

$> cargo test -- --test-threads 1

Dependencies

~4–19MB
~245K SLoC