tokio-rs / turmoil

Add hardship to your tests
MIT License
790 stars 50 forks source link

Return errors instead of panicking, when sending invalid packets. #127

Closed PetrichorIT closed 1 year ago

PetrichorIT commented 1 year ago

Currently turmoil will panic, if a packet is send to an ip address that does not exist, since this will result in an invalid access to the index map in top.rs.

This does not mirror the behavior if tokio or std sockets and panicking seems too extrem, especially since some applications may create such sockets, expecting errors instead of panics.

Therefore it might be advantageous to return errors instead of panicking in World::send_message.

Example

This example will panic.

fn main() -> Result {
     let mut sim = Builder::new().build();
     sim.client("client", async move {
         let _ = net::TcpStream::connect("192.168.30.1:80").await?;
         Ok(())
     });

     sim.run()
 }
thread 'main' panicked at 'IndexMap: key not found', ~/dev/turmoil/src/top.rs:221:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: JoinError::Panic(Id(1), ...)
mcches commented 1 year ago

This seems like a good change to make. Do you want to take a stab at it?

PetrichorIT commented 1 year ago

Yeah, I would like to do it.