Meets nondeterministic behavior using turmoil #149
-
Sorry for another question. I've met some puzzle . I want to simulate an scenario below, all of which happens sequentially:
And the codes are: #[test]
fn test_main() -> turmoil::Result {
use rand::SeedableRng;
use tokio::time::{timeout, Duration};
use turmoil::net::{TcpListener, TcpStream};
let mut sim = Builder::new()
.epoch(SystemTime::UNIX_EPOCH)
.rng(rand::rngs::StdRng::seed_from_u64(10))
.ip_version(turmoil::IpVersion::V6)
.build();
sim.host("s1", || async {
let sock = TcpListener::bind("[::]:80").await?;
println!("s1 start");
loop {
sock.accept().await?;
}
});
sim.client("c1", async {
TcpStream::connect("s1:80").await?;
println!("c1 connect succees");
Ok(())
});
sim.step()?;
sim.step()?;
sim.crash("s1");
sim.client("c2", async {
assert!(
timeout(Duration::from_millis(1), TcpStream::connect("s1:80"))
.await
.is_err()
);
println!("c2 connect should timeout");
Ok(())
});
sim.step()?;
sim.step()?;
sim.bounce("s1");
sim.client("c3", async {
TcpStream::connect("s1:80").await?;
println!("c1 connect succees");
Ok(())
});
sim.run()
} There are two questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you check out the documentation for
Can you switch to |
Beta Was this translation helpful? Give feedback.
If you check out the documentation for
step()
you'll see that this simply steps things forward once for each host. Userun()
to step until clients have completed.Can you switch to
run()
and we can debug further if necessary?