axum_test/util/
new_random_port.rs

1
2
3
4
5
6
7
8
use anyhow::anyhow;
use anyhow::Result;
use reserve_port::ReservedPort;

/// Returns a randomly selected port that is not in use.
pub fn new_random_port() -> Result<u16> {
    ReservedPort::random_permanently_reserved().map_err(|_| anyhow!("No free port was found"))
}