Skip to content
8 changes: 4 additions & 4 deletions streamer/src/nonblocking/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ pub mod test {
crossbeam_channel::{unbounded, Receiver},
quinn::{ApplicationClose, ConnectionError},
solana_keypair::Keypair,
solana_net_utils::bind_to_localhost,
solana_net_utils::sockets::bind_to_localhost_unique,
solana_signer::Signer,
std::collections::HashMap,
tokio::time::sleep,
Expand Down Expand Up @@ -1830,7 +1830,7 @@ pub mod test {
},
);

let client_socket = bind_to_localhost().unwrap();
let client_socket = bind_to_localhost_unique().expect("should bind - client");
let mut endpoint = quinn::Endpoint::new(
EndpointConfig::default(),
None,
Expand Down Expand Up @@ -1993,7 +1993,7 @@ pub mod test {
#[tokio::test(flavor = "multi_thread")]
async fn test_quic_server_unstaked_node_connect_failure() {
solana_logger::setup();
let s = bind_to_localhost().unwrap();
let s = bind_to_localhost_unique().expect("should bind");
let exit = Arc::new(AtomicBool::new(false));
let (sender, _) = unbounded();
let keypair = Keypair::new();
Expand Down Expand Up @@ -2026,7 +2026,7 @@ pub mod test {
#[tokio::test(flavor = "multi_thread")]
async fn test_quic_server_multiple_streams() {
solana_logger::setup();
let s = bind_to_localhost().unwrap();
let s = bind_to_localhost_unique().expect("should bind");
let exit = Arc::new(AtomicBool::new(false));
let (sender, receiver) = unbounded();
let keypair = Keypair::new();
Expand Down
11 changes: 4 additions & 7 deletions streamer/src/nonblocking/testing_utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ use {
TokioRuntime, TransportConfig,
},
solana_keypair::Keypair,
solana_net_utils::{
bind_to_localhost,
sockets::{
localhost_port_range_for_tests, multi_bind_in_range_with_config,
SocketConfiguration as SocketConfig,
},
solana_net_utils::sockets::{
bind_to_localhost_unique, localhost_port_range_for_tests, multi_bind_in_range_with_config,
SocketConfiguration as SocketConfig,
},
solana_perf::packet::PacketBatch,
solana_quic_definitions::{QUIC_KEEP_ALIVE, QUIC_MAX_TIMEOUT, QUIC_SEND_FAIRNESS},
Expand Down Expand Up @@ -123,7 +120,7 @@ pub async fn make_client_endpoint(
addr: &SocketAddr,
client_keypair: Option<&Keypair>,
) -> Connection {
let client_socket = bind_to_localhost().unwrap();
let client_socket = bind_to_localhost_unique().expect("should bind - client");
let mut endpoint = quinn::Endpoint::new(
EndpointConfig::default(),
None,
Expand Down
15 changes: 9 additions & 6 deletions streamer/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,11 @@ pub fn send_to(
mod tests {
use {
super::{recv_from as recv_from_impl, *},
solana_net_utils::bind_to_localhost,
std::{io, io::Write, net::SocketAddr},
solana_net_utils::sockets::bind_to_localhost_unique,
std::{
io::{self, Write},
net::SocketAddr,
},
};

#[test]
Expand Down Expand Up @@ -332,9 +335,9 @@ mod tests {
#[test]
pub fn packet_send_recv() {
solana_logger::setup();
let recv_socket = bind_to_localhost().expect("bind");
let recv_socket = bind_to_localhost_unique().expect("should bind - receiver");
let addr = recv_socket.local_addr().unwrap();
let send_socket = bind_to_localhost().expect("bind");
let send_socket = bind_to_localhost_unique().expect("should bind - sender");
let saddr = send_socket.local_addr().unwrap();

let mut batch = PinnedPacketBatch::with_capacity(PACKETS_PER_BATCH);
Expand Down Expand Up @@ -389,9 +392,9 @@ mod tests {
#[test]
fn test_packet_resize() {
solana_logger::setup();
let recv_socket = bind_to_localhost().expect("bind");
let recv_socket = bind_to_localhost_unique().expect("should bind - receiver");
let addr = recv_socket.local_addr().unwrap();
let send_socket = bind_to_localhost().expect("bind");
let send_socket = bind_to_localhost_unique().expect("should bind - sender");
let mut batch = PinnedPacketBatch::with_capacity(PACKETS_PER_BATCH);
batch.resize(PACKETS_PER_BATCH, Packet::default());

Expand Down
8 changes: 4 additions & 4 deletions streamer/src/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ mod test {
super::*,
crate::nonblocking::{quic::test::*, testing_utilities::check_multiple_streams},
crossbeam_channel::unbounded,
solana_net_utils::bind_to_localhost,
solana_net_utils::sockets::bind_to_localhost_unique,
std::net::SocketAddr,
};

Expand All @@ -711,7 +711,7 @@ mod test {
crossbeam_channel::Receiver<PacketBatch>,
SocketAddr,
) {
let s = bind_to_localhost().unwrap();
let s = bind_to_localhost_unique().expect("should bind");
let exit = Arc::new(AtomicBool::new(false));
let (sender, receiver) = unbounded();
let keypair = Keypair::new();
Expand Down Expand Up @@ -766,7 +766,7 @@ mod test {
#[test]
fn test_quic_server_multiple_streams() {
solana_logger::setup();
let s = bind_to_localhost().unwrap();
let s = bind_to_localhost_unique().expect("should bind");
let exit = Arc::new(AtomicBool::new(false));
let (sender, receiver) = unbounded();
let keypair = Keypair::new();
Expand Down Expand Up @@ -811,7 +811,7 @@ mod test {
#[test]
fn test_quic_server_unstaked_node_connect_failure() {
solana_logger::setup();
let s = bind_to_localhost().unwrap();
let s = bind_to_localhost_unique().expect("should bind");
let exit = Arc::new(AtomicBool::new(false));
let (sender, _) = unbounded();
let keypair = Keypair::new();
Expand Down
26 changes: 13 additions & 13 deletions streamer/src/sendmmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ mod tests {
sendmmsg::{batch_send, multi_target_send, SendPktsError},
},
assert_matches::assert_matches,
solana_net_utils::{bind_to_localhost, bind_to_unspecified},
solana_net_utils::sockets::bind_to_localhost_unique,
solana_packet::PACKET_DATA_SIZE,
std::{
io::ErrorKind,
Expand All @@ -257,9 +257,9 @@ mod tests {

#[test]
pub fn test_send_mmsg_one_dest() {
let reader = bind_to_localhost().expect("bind");
let reader = bind_to_localhost_unique().expect("should bind - reader");
let addr = reader.local_addr().unwrap();
let sender = bind_to_localhost().expect("bind");
let sender = bind_to_localhost_unique().expect("should bind - sender");

let packets: Vec<_> = (0..32).map(|_| vec![0u8; PACKET_DATA_SIZE]).collect();
let packet_refs: Vec<_> = packets.iter().map(|p| (&p[..], &addr)).collect();
Expand All @@ -274,13 +274,13 @@ mod tests {

#[test]
pub fn test_send_mmsg_multi_dest() {
let reader = bind_to_localhost().expect("bind");
let reader = bind_to_localhost_unique().expect("should bind - reader 1");
let addr = reader.local_addr().unwrap();

let reader2 = bind_to_localhost().expect("bind");
let reader2 = bind_to_localhost_unique().expect("should bind - reader 2");
let addr2 = reader2.local_addr().unwrap();

let sender = bind_to_localhost().expect("bind");
let sender = bind_to_localhost_unique().expect("should bind - sender");

let packets: Vec<_> = (0..32).map(|_| vec![0u8; PACKET_DATA_SIZE]).collect();
let packet_refs: Vec<_> = packets
Expand Down Expand Up @@ -309,19 +309,19 @@ mod tests {

#[test]
pub fn test_multicast_msg() {
let reader = bind_to_localhost().expect("bind");
let reader = bind_to_localhost_unique().expect("should bind - reader 1");
let addr = reader.local_addr().unwrap();

let reader2 = bind_to_localhost().expect("bind");
let reader2 = bind_to_localhost_unique().expect("should bind - reader 2");
let addr2 = reader2.local_addr().unwrap();

let reader3 = bind_to_localhost().expect("bind");
let reader3 = bind_to_localhost_unique().expect("should bind - reader 3");
let addr3 = reader3.local_addr().unwrap();

let reader4 = bind_to_localhost().expect("bind");
let reader4 = bind_to_localhost_unique().expect("should bind - reader 4");
let addr4 = reader4.local_addr().unwrap();

let sender = bind_to_localhost().expect("bind");
let sender = bind_to_localhost_unique().expect("should bind - reader 5");

let packet = Packet::default();

Expand Down Expand Up @@ -362,7 +362,7 @@ mod tests {
];
let dest_refs: Vec<_> = vec![&ip4, &ip6, &ip4];

let sender = bind_to_unspecified().expect("bind");
let sender = bind_to_localhost_unique().expect("should bind - sender");
let res = batch_send(&sender, packet_refs);
assert_matches!(res, Err(SendPktsError::IoError(_, /*num_failed*/ 1)));
let res = multi_target_send(&sender, &packets[0], &dest_refs);
Expand All @@ -374,7 +374,7 @@ mod tests {
let packets: Vec<_> = (0..5).map(|_| vec![0u8; PACKET_DATA_SIZE]).collect();
let ipv4local = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 8080);
let ipv4broadcast = SocketAddr::new(IpAddr::V4(Ipv4Addr::BROADCAST), 8080);
let sender = bind_to_unspecified().expect("bind");
let sender = bind_to_localhost_unique().expect("should bind - sender");

// test intermediate failures for batch_send
let packet_refs: Vec<_> = vec![
Expand Down
10 changes: 4 additions & 6 deletions streamer/src/streamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,10 @@ mod test {
streamer::{receiver, responder},
},
crossbeam_channel::unbounded,
solana_net_utils::bind_to_localhost,
solana_net_utils::sockets::bind_to_localhost_unique,
solana_perf::recycler::Recycler,
std::{
io,
io::Write,
io::{self, Write},
sync::{
atomic::{AtomicBool, Ordering},
Arc,
Expand Down Expand Up @@ -663,11 +662,10 @@ mod test {
}
#[test]
fn streamer_send_test() {
let read = bind_to_localhost().expect("bind");
let read = bind_to_localhost_unique().expect("should bind reader");
read.set_read_timeout(Some(SOCKET_READ_TIMEOUT)).unwrap();

let addr = read.local_addr().unwrap();
let send = bind_to_localhost().expect("bind");
let send = bind_to_localhost_unique().expect("should bind sender");
let exit = Arc::new(AtomicBool::new(false));
let (s_reader, r_reader) = unbounded();
let stats = Arc::new(StreamerReceiveStats::new("test"));
Expand Down
6 changes: 3 additions & 3 deletions streamer/tests/recvmmsg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(target_os = "linux")]

use {
solana_net_utils::bind_to_localhost,
solana_net_utils::sockets::bind_to_localhost_unique,
solana_streamer::{
packet::{Meta, Packet, PACKET_DATA_SIZE},
recvmmsg::*,
Expand All @@ -11,9 +11,9 @@ use {

#[test]
pub fn test_recv_mmsg_batch_size() {
let reader = bind_to_localhost().expect("bind");
let reader = bind_to_localhost_unique().expect("should bind - reader");
let addr = reader.local_addr().unwrap();
let sender = bind_to_localhost().expect("bind");
let sender = bind_to_localhost_unique().expect("should bind - sender");

const TEST_BATCH_SIZE: usize = 64;
let sent = TEST_BATCH_SIZE;
Expand Down
Loading