Skip to content

Commit 1fae0c2

Browse files
MacroFakePastaPastaPasta
authored andcommitted
Merge bitcoin#25333: test: Fix out-of-range port collisions
fa7a711 test: Fix out-of-range port collisions (MacroFake) Pull request description: Otherwise the test will fail if two tests running in parallel use the same port. See bitcoin#25096 (comment) and bitcoin#25312 ACKs for top commit: dergoegge: ACK fa7a711 - This gets rid of some rather arbitrary choices for ports in some of our functional tests that can cause port collisions across test runs, resulting in intermittent failures. Tree-SHA512: ac73da8a498230b992ab12e1ee3c4ff3d868cd63c00d2c71537d156cb7c8f8be8598ec574646b17c5a44ae3ac5bb54bf29d300f054a36cec6f6ce8054a0da0a4
1 parent b750896 commit 1fae0c2

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

test/functional/feature_bind_extra.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
SkipTest,
1919
)
2020
from test_framework.util import (
21-
PORT_MIN,
22-
PORT_RANGE,
2321
assert_equal,
22+
p2p_port,
2423
rpc_port,
2524
)
2625

26+
2727
class BindExtraTest(BitcoinTestFramework):
2828
def set_test_params(self):
2929
self.setup_clean_chain = True
@@ -33,20 +33,15 @@ def set_test_params(self):
3333
self.num_nodes = 2
3434

3535
def setup_network(self):
36-
# Override setup_network() because we want to put the result of
37-
# p2p_port() in self.extra_args[], before the nodes are started.
38-
# p2p_port() is not usable in set_test_params() because PortSeed.n is
39-
# not set at that time.
40-
4136
# Due to OS-specific network stats queries, we only run on Linux.
4237
self.log.info("Checking for Linux")
4338
if not sys.platform.startswith('linux'):
4439
raise SkipTest("This test can only be run on Linux.")
4540

4641
loopback_ipv4 = addr_to_hex("127.0.0.1")
4742

48-
# Start custom ports after p2p and rpc ports.
49-
port = PORT_MIN + 2 * PORT_RANGE
43+
# Start custom ports by reusing unused p2p ports
44+
port = p2p_port(self.num_nodes)
5045

5146
# Array of tuples [command line arguments, expected bind addresses].
5247
self.expected = []

test/functional/feature_proxy.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@
3131
"""
3232

3333
import socket
34-
import os
3534

3635
from test_framework.socks5 import Socks5Configuration, Socks5Command, Socks5Server, AddressType
3736
from test_framework.test_framework import BitcoinTestFramework
3837
from test_framework.util import (
39-
PORT_MIN,
40-
PORT_RANGE,
4138
assert_equal,
39+
p2p_port,
4240
)
4341
from test_framework.netutil import test_ipv6_local
4442

45-
RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
46-
4743
# Networks returned by RPC getpeerinfo.
4844
NET_UNROUTABLE = "not_publicly_routable"
4945
NET_IPV4 = "ipv4"
@@ -65,19 +61,19 @@ def setup_nodes(self):
6561
# Create two proxies on different ports
6662
# ... one unauthenticated
6763
self.conf1 = Socks5Configuration()
68-
self.conf1.addr = ('127.0.0.1', RANGE_BEGIN + (os.getpid() % 1000))
64+
self.conf1.addr = ('127.0.0.1', p2p_port(self.num_nodes))
6965
self.conf1.unauth = True
7066
self.conf1.auth = False
7167
# ... one supporting authenticated and unauthenticated (Tor)
7268
self.conf2 = Socks5Configuration()
73-
self.conf2.addr = ('127.0.0.1', RANGE_BEGIN + 1000 + (os.getpid() % 1000))
69+
self.conf2.addr = ('127.0.0.1', p2p_port(self.num_nodes + 1))
7470
self.conf2.unauth = True
7571
self.conf2.auth = True
7672
if self.have_ipv6:
7773
# ... one on IPv6 with similar configuration
7874
self.conf3 = Socks5Configuration()
7975
self.conf3.af = socket.AF_INET6
80-
self.conf3.addr = ('::1', RANGE_BEGIN + 2000 + (os.getpid() % 1000))
76+
self.conf3.addr = ('::1', p2p_port(self.num_nodes + 2))
8177
self.conf3.unauth = True
8278
self.conf3.auth = True
8379
else:

test/functional/p2p_getaddr_caching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class AddrTest(BitcoinTestFramework):
4242
def set_test_params(self):
4343
self.num_nodes = 1
4444
# Use some of the remaining p2p ports for the onion binds.
45-
self.onion_port1 = p2p_port(1)
46-
self.onion_port2 = p2p_port(2)
45+
self.onion_port1 = p2p_port(self.num_nodes)
46+
self.onion_port2 = p2p_port(self.num_nodes + 1)
4747
self.extra_args = [
4848
[f"-bind=127.0.0.1:{self.onion_port1}=onion", f"-bind=127.0.0.1:{self.onion_port2}=onion"],
4949
]

0 commit comments

Comments
 (0)