Skip to content

Commit fa7a711

Browse files
author
MacroFake
committed
test: Fix out-of-range port collisions
1 parent c3daa32 commit fa7a711

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

test/functional/feature_bind_extra.py

+4-9
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

+4-8
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,15 @@
4040
"""
4141

4242
import socket
43-
import os
4443

4544
from test_framework.socks5 import Socks5Configuration, Socks5Command, Socks5Server, AddressType
4645
from test_framework.test_framework import BitcoinTestFramework
4746
from test_framework.util import (
48-
PORT_MIN,
49-
PORT_RANGE,
5047
assert_equal,
48+
p2p_port,
5149
)
5250
from test_framework.netutil import test_ipv6_local
5351

54-
RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
55-
5652
# Networks returned by RPC getpeerinfo.
5753
NET_UNROUTABLE = "not_publicly_routable"
5854
NET_IPV4 = "ipv4"
@@ -75,19 +71,19 @@ def setup_nodes(self):
7571
# Create two proxies on different ports
7672
# ... one unauthenticated
7773
self.conf1 = Socks5Configuration()
78-
self.conf1.addr = ('127.0.0.1', RANGE_BEGIN + (os.getpid() % 1000))
74+
self.conf1.addr = ('127.0.0.1', p2p_port(self.num_nodes))
7975
self.conf1.unauth = True
8076
self.conf1.auth = False
8177
# ... one supporting authenticated and unauthenticated (Tor)
8278
self.conf2 = Socks5Configuration()
83-
self.conf2.addr = ('127.0.0.1', RANGE_BEGIN + 1000 + (os.getpid() % 1000))
79+
self.conf2.addr = ('127.0.0.1', p2p_port(self.num_nodes + 1))
8480
self.conf2.unauth = True
8581
self.conf2.auth = True
8682
if self.have_ipv6:
8783
# ... one on IPv6 with similar configuration
8884
self.conf3 = Socks5Configuration()
8985
self.conf3.af = socket.AF_INET6
90-
self.conf3.addr = ('::1', RANGE_BEGIN + 2000 + (os.getpid() % 1000))
86+
self.conf3.addr = ('::1', p2p_port(self.num_nodes + 2))
9187
self.conf3.unauth = True
9288
self.conf3.auth = True
9389
else:

test/functional/p2p_getaddr_caching.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class AddrTest(BitcoinTestFramework):
4444
def set_test_params(self):
4545
self.num_nodes = 1
4646
# Use some of the remaining p2p ports for the onion binds.
47-
self.onion_port1 = p2p_port(1)
48-
self.onion_port2 = p2p_port(2)
47+
self.onion_port1 = p2p_port(self.num_nodes)
48+
self.onion_port2 = p2p_port(self.num_nodes + 1)
4949
self.extra_args = [
5050
[f"-bind=127.0.0.1:{self.onion_port1}=onion", f"-bind=127.0.0.1:{self.onion_port2}=onion"],
5151
]

0 commit comments

Comments
 (0)