This is very experimental
Add hardship to your tests.
Turmoil is a framework for developing and testing distributed systems. It provides deterministic execution by running multiple concurrent hosts within a single thread. It introduces "hardship" into the system via changes in the simulated network. The network can be controlled manually or with a seeded rng.
Add this to your Cargo.toml
.
toml
[dev-dependencies]
turmoil = "0.2"
Next, create a test file and add a test:
```rust use turmoil::{Builder, Io};
enum Message { Echo(String), }
impl turmoil::Message for Message { fn write_json(&self, _dst: &mut dyn std::io::Write) { todo!("not yet implemented") } }
fn simulation() { let mut sim = Builder::new().build();
// register a client
let client = sim.client("client");
// register a host
sim.register("server", |host: Io<Message>| async move {
loop {
let (msg, src) = host.recv().await;
host.send(src, msg);
}
});
// run the simulation
sim.run_until(async move {
client.send("server", Message::Echo("hello, server!".to_string()));
let (msg, _) = client.recv().await;
let echo = match msg {
Message::Echo(e) => e,
};
assert_eq!("hello, server!", echo);
});
}
```
This project is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in turmoil
by you, shall be licensed as MIT,
without any additional terms or conditions.