From 85feca305b6cb12b6da4dca61283ff4cf157ac3b Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 9 Apr 2020 19:03:25 -0700 Subject: [PATCH] Avoid port conflict in new_with_external_ip_test_gossip --- core/src/cluster_info.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index 96533074fa..df01c6b264 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -1998,20 +1998,16 @@ mod tests { #[test] fn new_with_external_ip_test_gossip() { - let ip = IpAddr::V4(Ipv4Addr::from(0)); - let port = { - bind_in_range(ip, VALIDATOR_PORT_RANGE) - .expect("Failed to bind") - .0 - }; - let node = Node::new_with_external_ip( - &Pubkey::new_rand(), - &socketaddr!(0, port), - VALIDATOR_PORT_RANGE, - ip, - ); + // Can't use VALIDATOR_PORT_RANGE because if this test runs in parallel with others, the + // port returned by `bind_in_range()` might be snatched up before `Node::new_with_external_ip()` runs + let port_range = (VALIDATOR_PORT_RANGE.1 + 10, VALIDATOR_PORT_RANGE.1 + 20); - check_node_sockets(&node, ip, VALIDATOR_PORT_RANGE); + let ip = IpAddr::V4(Ipv4Addr::from(0)); + let port = bind_in_range(ip, port_range).expect("Failed to bind").0; + let node = + Node::new_with_external_ip(&Pubkey::new_rand(), &socketaddr!(0, port), port_range, ip); + + check_node_sockets(&node, ip, port_range); assert_eq!(node.sockets.gossip.local_addr().unwrap().port(), port); }