Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,18 @@ pub(crate) fn random_storage_path() -> PathBuf {
temp_path
}

pub(crate) fn random_port() -> u16 {
let mut rng = rng();
rng.random_range(5000..32768)
}

pub(crate) fn random_listening_addresses() -> Vec<SocketAddress> {
let num_addresses = 2;
let mut listening_addresses = Vec::with_capacity(num_addresses);
let mut listening_addresses = HashSet::new();

for _ in 0..num_addresses {
let rand_port = random_port();
while listening_addresses.len() < num_addresses {
let socket = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
let rand_port = socket.local_addr().unwrap().port();
let address: SocketAddress = format!("127.0.0.1:{}", rand_port).parse().unwrap();
listening_addresses.push(address);
listening_addresses.insert(address);
}

listening_addresses
listening_addresses.into_iter().collect()
}

pub(crate) fn random_node_alias() -> Option<NodeAlias> {
Expand Down