Pick ports more randomly for integration tests (#315)
This commit is contained in:
parent
5391382928
commit
ebbdf14406
|
@ -4,27 +4,18 @@ pub use nodes::NomosNode;
|
|||
// std
|
||||
use std::fmt::Debug;
|
||||
use std::net::TcpListener;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
|
||||
//crates
|
||||
use fraction::Fraction;
|
||||
use once_cell::sync::Lazy;
|
||||
use rand::SeedableRng;
|
||||
use rand_xoshiro::Xoshiro256PlusPlus;
|
||||
|
||||
static RNG: Lazy<Mutex<Xoshiro256PlusPlus>> =
|
||||
Lazy::new(|| Mutex::new(Xoshiro256PlusPlus::seed_from_u64(42)));
|
||||
|
||||
static NET_PORT: Mutex<u16> = Mutex::new(8000);
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
pub fn get_available_port() -> u16 {
|
||||
let mut port = NET_PORT.lock().unwrap();
|
||||
*port += 1;
|
||||
while TcpListener::bind(("127.0.0.1", *port)).is_err() {
|
||||
*port += 1;
|
||||
let mut port: u16 = thread_rng().gen_range(8000..10000);
|
||||
while TcpListener::bind(("127.0.0.1", port)).is_err() {
|
||||
port += 1;
|
||||
}
|
||||
*port
|
||||
port
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::net::SocketAddr;
|
|||
use std::process::{Child, Command, Stdio};
|
||||
use std::time::Duration;
|
||||
// internal
|
||||
use crate::{get_available_port, Node, SpawnConfig, RNG};
|
||||
use crate::{get_available_port, Node, SpawnConfig};
|
||||
use consensus_engine::overlay::{FlatOverlaySettings, RoundRobin};
|
||||
use consensus_engine::NodeId;
|
||||
use nomos_consensus::{CarnotInfo, CarnotSettings};
|
||||
|
@ -22,7 +22,7 @@ use waku_bindings::{Multiaddr, PeerId};
|
|||
// crates
|
||||
use fraction::Fraction;
|
||||
use once_cell::sync::Lazy;
|
||||
use rand::Rng;
|
||||
use rand::{thread_rng, Rng};
|
||||
use reqwest::Client;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
|
@ -174,7 +174,7 @@ impl Node for NomosNode {
|
|||
} => {
|
||||
let mut ids = vec![[0; 32]; n_participants];
|
||||
for id in &mut ids {
|
||||
RNG.lock().unwrap().fill(id);
|
||||
thread_rng().fill(id);
|
||||
}
|
||||
let mut configs = ids
|
||||
.iter()
|
||||
|
|
Loading…
Reference in New Issue