Skip to content

Injected network faults don't affect messages on links #251

@teskje

Description

@teskje

I was expecting to be able to use the network fault injection abilities (e.g. Sim::partition and Sim::hold), to prevent/delay the delivery of messages after I've observed them on a link. In other words, I expected this code to pass the assert at the end, due to the client timing out:

use tokio::io::{AsyncReadExt, AsyncWriteExt};
use turmoil::net::{TcpListener, TcpStream};
use turmoil::Protocol::Tcp;
use turmoil::Segment::Data;

fn main() {
    let mut sim = turmoil::Builder::new().build();

    sim.host("host", || async {
        let listener = TcpListener::bind("0.0.0.0:7777").await?;
        let (mut sock, _) = listener.accept().await?;
        sock.write_u8(1).await?;
        Ok(())
    });

    sim.client("client", async {
        let mut sock = TcpStream::connect("host:7777").await?;
        sock.read_u8().await?;
        Ok(())
    });

    let mut message_sent = false;
    while !message_sent {
        sim.step().unwrap();

        sim.links(|mut links| {
            let mut messages = links.next().unwrap();
            message_sent = messages.any(|m| matches!(m.protocol(), Tcp(Data(..))));
        });
    }

    sim.partition("host", "client");

    assert!(sim.run().is_err());
}

However, I found that Sim::partition and co. only have an effect on messages that are put on the link subsequently. For messages on the link, the delivery time has already been determined, and is not changed in response to a network fault.

It seems quite useful for network fault to also affect messages on links. It allows for writing tests where you wait for a certain message to arrive on the link, as a way to catch the right moment to inject a fault. Currently, you can't do that if you also need to prevent that message from being delivered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions