Skip to content

reset_node doesn't seem to work #234

Description

@mlowicki

Tested on fresh main

#[madsim::test]
async fn foo() {
    let handle = Handle::current();
    let addr0 = "10.0.0.1:50051".parse::<SocketAddr>().unwrap();
    let node0 = handle.create_node().name("server").ip(addr0.ip()).build();
    let id0 = node0.id();
    node0.spawn(async move {
        let listener = TcpListener::bind("10.0.0.1:50051").await.unwrap();

        loop {
            let (mut socket, _) = listener.accept().await.unwrap();

            let nb = socket.read_u8().await.unwrap();
            println!("got: {:?}", nb);
            let mut sum = 0_i64;

            for _ in 0..nb {
                let n = socket.read_u8().await.unwrap();
                sum += n as i64;
            }

            socket.write_i64(sum).await.unwrap();
            socket.flush().await.unwrap();
        }
    });

    let ip1 = "10.0.0.2".parse().unwrap();
    let node1 = handle.create_node().name("client").ip(ip1).build();
    let id1 = node1.id();

    let t1 = node1.spawn(async move {
        let mut stream = TcpStream::connect("10.0.0.1:50051").await.unwrap();
        NetSim::current().reset_node(id0);
        NetSim::current().reset_node(id1);
        //NetSim::current().clog_link(id, id2);
        //NetSim::current().clog_link(id2, id);
        //Handle::current().kill(id);
        stream.write_all(&[2,4,8]).await.unwrap();
        stream.flush().await.unwrap();
        let sum = stream.read_i64().await.unwrap();
        println!("SUM: {:?}", sum);
    });

    t1.await.unwrap();
}

With Handle::current().kill(id); commented out the test just hangs forever and I would expect that following reads from the socket to fail. If Handle::current().kill(id); is being used then I see Kind(UnexpectedEof).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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