Skip to content

Commit a54372e

Browse files
committed
Fix AddrInUse error in cli tests.
1 parent a229b52 commit a54372e

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

lighthouse/tests/beacon_node.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ use types::{
2323
Address, Checkpoint, Epoch, ExecutionBlockHash, ForkName, Hash256, MainnetEthSpec,
2424
ProgressiveBalancesMode,
2525
};
26+
use unused_port::{unused_tcp4_port, unused_tcp6_port, unused_udp4_port, unused_udp6_port};
2627

2728
const DEFAULT_ETH1_ENDPOINT: &str = "http://localhost:8545/";
29+
30+
// These dummy ports should ONLY be used for `enr-xxx-port` flags that do not bind.
2831
const DUMMY_ENR_TCP_PORT: u16 = 7777;
2932
const DUMMY_ENR_UDP_PORT: u16 = 8888;
3033
const DUMMY_ENR_QUIC_PORT: u16 = 9999;
@@ -871,7 +874,7 @@ fn network_port_flag_over_ipv4() {
871874
);
872875
});
873876

874-
let port = 9000;
877+
let port = unused_tcp4_port().expect("Unable to find unused port.");
875878
CommandLineTest::new()
876879
.flag("port", Some(port.to_string().as_str()))
877880
.flag("allow-insecure-genesis-sync", None)
@@ -908,7 +911,7 @@ fn network_port_flag_over_ipv6() {
908911
);
909912
});
910913

911-
let port = 9000;
914+
let port = unused_tcp4_port().expect("Unable to find unused port.");
912915
CommandLineTest::new()
913916
.flag("listen-address", Some("::1"))
914917
.flag("port", Some(port.to_string().as_str()))
@@ -958,8 +961,8 @@ fn network_port_flag_over_ipv4_and_ipv6() {
958961
);
959962
});
960963

961-
let port = 19000;
962-
let port6 = 29000;
964+
let port = unused_tcp4_port().expect("Unable to find unused port.");
965+
let port6 = unused_tcp6_port().expect("Unable to find unused port.");
963966
CommandLineTest::new()
964967
.flag("listen-address", Some("127.0.0.1"))
965968
.flag("listen-address", Some("::1"))
@@ -1300,9 +1303,8 @@ fn enr_tcp6_port_flag() {
13001303
fn enr_match_flag_over_ipv4() {
13011304
let addr = "127.0.0.2".parse::<Ipv4Addr>().unwrap();
13021305

1303-
// the reason we use the ENR dummy values is because, due to the nature of the `--enr-match` flag, these will eventually become ENR ports (as well as listening ports).
1304-
let udp4_port = DUMMY_ENR_UDP_PORT;
1305-
let tcp4_port = DUMMY_ENR_TCP_PORT;
1306+
let udp4_port = unused_udp4_port().expect("Unable to find unused port.");
1307+
let tcp4_port = unused_tcp4_port().expect("Unable to find unused port.");
13061308

13071309
CommandLineTest::new()
13081310
.flag("enr-match", None)
@@ -1332,9 +1334,8 @@ fn enr_match_flag_over_ipv6() {
13321334
const ADDR: &str = "::1";
13331335
let addr = ADDR.parse::<Ipv6Addr>().unwrap();
13341336

1335-
// the reason we use the ENR dummy values is because, due to the nature of the `--enr-match` flag, these will eventually become ENR ports (as well as listening ports).
1336-
let udp6_port = DUMMY_ENR_UDP_PORT;
1337-
let tcp6_port = DUMMY_ENR_TCP_PORT;
1337+
let udp6_port = unused_udp6_port().expect("Unable to find unused port.");
1338+
let tcp6_port = unused_tcp6_port().expect("Unable to find unused port.");
13381339

13391340
CommandLineTest::new()
13401341
.flag("enr-match", None)
@@ -1363,15 +1364,13 @@ fn enr_match_flag_over_ipv6() {
13631364
fn enr_match_flag_over_ipv4_and_ipv6() {
13641365
const IPV6_ADDR: &str = "::1";
13651366

1366-
// the reason we use the ENR dummy values is because, due to the nature of the `--enr-match` flag, these will eventually become ENR ports (as well as listening ports).
1367-
let udp6_port = DUMMY_ENR_UDP_PORT;
1368-
let tcp6_port = DUMMY_ENR_TCP_PORT;
1367+
let udp6_port = unused_udp6_port().expect("Unable to find unused port.");
1368+
let tcp6_port = unused_tcp6_port().expect("Unable to find unused port.");
13691369
let ipv6_addr = IPV6_ADDR.parse::<Ipv6Addr>().unwrap();
13701370

13711371
const IPV4_ADDR: &str = "127.0.0.1";
1372-
// the reason we use the ENR dummy values is because, due to the nature of the `--enr-match` flag, these will eventually become ENR ports (as well as listening ports).
1373-
let udp4_port = DUMMY_ENR_UDP_PORT;
1374-
let tcp4_port = DUMMY_ENR_TCP_PORT;
1372+
let udp4_port = unused_udp4_port().expect("Unable to find unused port.");
1373+
let tcp4_port = unused_tcp4_port().expect("Unable to find unused port.");
13751374
let ipv4_addr = IPV4_ADDR.parse::<Ipv4Addr>().unwrap();
13761375

13771376
CommandLineTest::new()

0 commit comments

Comments
 (0)