Skip to content

Commit e8ce52e

Browse files
committed
check that tests still pass
1 parent 7855472 commit e8ce52e

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},
@@ -2402,29 +2402,51 @@ pub struct Node {
24022402
pub sockets: Sockets,
24032403
}
24042404

2405+
const NODE_BASE_PORT: u16 = 40000;
24052406
impl Node {
2407+
/// create localhost node for tests
24062408
pub fn new_localhost() -> Self {
24072409
let pubkey = solana_pubkey::new_rand();
24082410
Self::new_localhost_with_pubkey(&pubkey)
24092411
}
24102412

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

24302452
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)