Skip to content

Commit 4c80dc0

Browse files
committed
check that tests still pass
1 parent 5e2682b commit 4c80dc0

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

gossip/src/cluster_info.rs

+29-7
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ use {
9090
rc::Rc,
9191
result::Result,
9292
sync::{
93-
atomic::{AtomicBool, Ordering},
93+
atomic::{AtomicBool, AtomicU16, Ordering},
9494
Arc, Mutex, RwLock, RwLockReadGuard,
9595
},
9696
thread::{sleep, Builder, JoinHandle},
@@ -2405,29 +2405,51 @@ pub struct Node {
24052405
pub sockets: Sockets,
24062406
}
24072407

2408+
const NODE_BASE_PORT: u16 = 40000;
24082409
impl Node {
2410+
/// create localhost node for tests
24092411
pub fn new_localhost() -> Self {
24102412
let pubkey = solana_pubkey::new_rand();
24112413
Self::new_localhost_with_pubkey(&pubkey)
24122414
}
24132415

2416+
fn localhost_port_range_for_tests() -> (u16, u16) {
2417+
static SLICE: AtomicU16 = AtomicU16::new(NODE_BASE_PORT);
2418+
let start = match std::env::var("NEXTEST_TEST_GLOBAL_SLOT") {
2419+
Ok(slot) => {
2420+
let slot: u16 = slot.parse().unwrap();
2421+
NODE_BASE_PORT + slot * 25
2422+
}
2423+
Err(_) => SLICE.fetch_add(100, Ordering::Relaxed),
2424+
};
2425+
assert!(start < 65500, "ran out of port numbers!");
2426+
(start, start + 25)
2427+
}
2428+
2429+
/// create localhost node for tests with provided pubkey
2430+
/// unlike the public IP version, this will also bind RPC sockets.
24142431
pub fn new_localhost_with_pubkey(pubkey: &Pubkey) -> Self {
2415-
let localhost_ip_addr = IpAddr::V4(Ipv4Addr::LOCALHOST);
2416-
let port_range = (1024, 65535);
2417-
let gossip_port = find_available_port_in_range(localhost_ip_addr, port_range)
2432+
let addr = IpAddr::V4(Ipv4Addr::LOCALHOST);
2433+
let port_range = Self::localhost_port_range_for_tests();
2434+
let gossip_port = find_available_port_in_range(addr, port_range)
24182435
.expect("At least one open port should be available");
24192436
let config = NodeConfig {
2420-
gossip_addr: SocketAddr::new(localhost_ip_addr, gossip_port),
2437+
gossip_addr: SocketAddr::new(addr, gossip_port),
24212438
port_range,
2422-
bind_ip_addr: localhost_ip_addr,
2439+
bind_ip_addr: addr,
24232440
public_tpu_addr: None,
24242441
public_tpu_forwards_addr: None,
24252442
num_tvu_receive_sockets: NonZero::new(1).unwrap(),
24262443
num_tvu_retransmit_sockets: NonZero::new(1).unwrap(),
24272444
num_quic_endpoints: NonZero::new(DEFAULT_QUIC_ENDPOINTS)
24282445
.expect("Number of QUIC endpoints can not be zero"),
24292446
};
2430-
Self::new_with_external_ip(pubkey, config)
2447+
let mut node = Self::new_with_external_ip(pubkey, config);
2448+
let rpc_port = find_available_port_in_range(addr, port_range).unwrap();
2449+
let rpc_pubsub_port = find_available_port_in_range(addr, port_range).unwrap();
2450+
node.info.set_rpc((addr, rpc_port)).unwrap();
2451+
node.info.set_rpc_pubsub((addr, rpc_pubsub_port)).unwrap();
2452+
node
24312453
}
24322454

24332455
fn get_gossip_port(

net-utils/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! The `net_utils` module assists with networking
22
mod ip_echo_client;
33
mod ip_echo_server;
4+
pub mod sockets;
45

56
#[cfg(feature = "dev-context-only-utils")]
67
pub mod tooling_for_tests;

0 commit comments

Comments
 (0)