pub(crate) fn unused_port_on_localhost() -> u16 {
    // Previous iterations of this implementation tried other approaches such as binding an
    // ephemeral port and using that. This ran into race condition issues when the port was reused
    // in the timespan where it was released and rebound.

    // The simpler approach is to select a random port from the non-ephemeral range and hope that no
    // daemons are already bound/listening on it, which should not be the case on a CI system.

    // We use a random offset and stride to stretch this a little bit, should two processes run at
    // the same time.
    static NEXT_PORT: Lazy<AtomicU16> = Lazy::new(|| {
        rand::thread_rng()
            .gen_range(TEST_PORT_RANGE.start..(TEST_PORT_RANGE.start + TEST_PORT_STRIDE))
            .into()
    });

    NEXT_PORT.fetch_add(TEST_PORT_STRIDE, Ordering::SeqCst)
}
/// Create an unused port on localhost.
///
/// Returns a random port on localhost, provided that no other applications are binding ports inside
/// `TEST_PORT_RANGE` and no other testing process is run in parallel. Should the latter happen,
/// some randomization is used to avoid conflicts, without guarantee of success.
Create an unused port on localhost.
Returns a random port on localhost, provided that no other applications are binding ports inside
`TEST_PORT_RANGE` and no other testing process is run in parallel. Should the latter happen,
some randomization is used to avoid conflicts, without guarantee of success.
Create an unused port on localhost . Returns a random port on localhost provided that no other applications are binding ports inside ` TEST_PORT_RANGE ` and no other testing process is run in parallel . Should the latter happen some randomization is used to avoid conflicts without guarantee of success .
pub(crate) fn unused_port_on_localhost() -> u16 {
    // Previous iterations of this implementation tried other approaches such as binding an
    // ephemeral port and using that. This ran into race condition issues when the port was reused
    // in the timespan where it was released and rebound.
    // The simpler approach is to select a random port from the non-ephemeral range and hope that no
    // daemons are already bound/listening on it, which should not be the case on a CI system.
    // We use a random offset and stride to stretch this a little bit, should two processes run at
    // the same time.
    static NEXT_PORT: Lazy<AtomicU16> = Lazy::new(|| {
        rand::thread_rng()
            .gen_range(TEST_PORT_RANGE.start..(TEST_PORT_RANGE.start + TEST_PORT_STRIDE))
            .into()
    });
    NEXT_PORT.fetch_add(TEST_PORT_STRIDE, Ordering::SeqCst)
}
pub ( crate ) fn unused_port_on_localhost ( ) -> u16 { // Previous iterations of this implementation tried other approaches such as binding an // ephemeral port and using that. This ran into race condition issues when the port was reused // in the timespan where it was released and rebound. // The simpler approach is to select a random port from the non-ephemeral range and hope that no // daemons are already bound/listening on it, which should not be the case on a CI system. // We use a random offset and stride to stretch this a little bit, should two processes run at // the same time. static NEXT_PORT : Lazy < AtomicU16 > = Lazy :: new ( | | { rand :: thread_rng ( ) . gen_range ( TEST_PORT_RANGE . start .. ( TEST_PORT_RANGE . start + TEST_PORT_STRIDE ) ) . into ( ) } ) ; NEXT_PORT . fetch_add ( TEST_PORT_STRIDE , Ordering :: SeqCst ) }
Create an unused port on localhost.
Create an unused port on localhost .