tokio-rs / turmoil

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

support ephemeral port assignments #104

Closed camshaft closed 1 year ago

camshaft commented 1 year ago

I tried the following code:

#[test]
fn ephemeral_port() -> Result {
    let mut sim = Builder::new().build();

    sim.client("client", async {
        let sock = bind_to(0).await?;

        // turmoil should assign a port to the ephemeral range
        assert_ne!(sock.local_addr()?.port(), 0);
        assert!(sock.local_addr()?.port() >= 49152);

        Ok(())
    });

    sim.run()
}

It would be nice to support ephemeral port assignment. This is useful for clients that don't care about the specific port number; they just need a free port.

From https://www.rfc-editor.org/rfc/rfc6335#section-6:

o the System Ports, also known as the Well Known Ports, from 0-1023 (assigned by IANA)

o the User Ports, also known as the Registered Ports, from 1024- 49151 (assigned by IANA)

o the Dynamic Ports, also known as the Private or Ephemeral Ports, from 49152-65535 (never assigned)

th7nder commented 1 year ago

Happy to help with this one, let's assign it to me.