You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose you have multiple tests that need to bind to the same port for some reason. By using
#[netsim::isolate] you can run your test suite without having to use --test-threads=1 and
without having to stop any daemons running on your dev machine.
#[test]
#[netsim::isolate]
fn a_test() {
let _listener = std::net::TcpListener::bind("0.0.0.0:80").unwrap();
}
#[test]
#[netsim::isolate]
fn another_test_that_runs_in_parallel() {
let _listener = std::net::TcpListener::bind("0.0.0.0:80").unwrap();
}
Example 2: Capturing a packet.
The #[netsim::isolate] attribute showcased above is just a convenient way to setup a Machine
and spawn a task onto it. To capture a packet you'll need to do these steps yourself. You'll also
need to give the machine a network interface to send the packet on.
In this example we create a UDP socket and use it to send the message "hello" towards an arbitary
address. The packet then arrives on our IpIface, hoping to be routed somewhere, and we can check
that it still contains the correct message.