Skip to content

Commit 697bc7f

Browse files
committed
Merge bitcoin#34300: test: use ephemeral ports in p2p_private_broadcast.py
3e34067 test: use ephemeral ports in p2p_private_broadcast.py (w0xlt) Pull request description: The test `p2p_private_broadcast.py` gets some Python P2P nodes to listen and instructs the SOCKS5 proxy to redirect connections to them instead of to the requested addresses. This way the `bitcoind` which uses the proxy is tricked to think it has connected to real routable internet IP addresses or `.onion` addresses. Picking the ports where to Python P2P nodes to listen however is tricky to be done in a non-conflicting way, given that other tests may run in parallel. bitcoin#34186 made it possible to let the OS select a free port, so use that in `p2p_private_broadcast.py`. --- _Suggested in bitcoin#29415 (comment) ACKs for top commit: l0rinc: code review ACK 3e34067 polespinasa: tACK 3e34067 mzumsande: utACK 3e34067 Tree-SHA512: e94efd33a1845e1767aaada55f91c60bc5fc1166c281ef578a391e95e2791a922d84aa6ed1ce06e7d6ca1a65f84da52fd79d9b2f40705c1944a53c67b7392e4d
2 parents 37cb209 + 3e34067 commit 697bc7f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

test/functional/p2p_private_broadcast.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
BitcoinTestFramework,
3737
)
3838
from test_framework.util import (
39-
MAX_NODES,
4039
assert_equal,
4140
assert_not_equal,
4241
assert_raises_rpc_error,
@@ -181,9 +180,6 @@ def setup_nodes(self):
181180
self.socks5_server = Socks5Server(socks5_server_config)
182181
self.socks5_server.start()
183182

184-
# Tor ports are the highest among p2p/rpc/tor, so this should be the first available port.
185-
ports_base = tor_port(MAX_NODES) + 1
186-
187183
self.destinations = []
188184

189185
self.destinations_lock = threading.Lock()
@@ -215,9 +211,12 @@ def on_listen_done(addr, port):
215211
actual_to_addr = addr
216212
actual_to_port = port
217213

214+
# Use port=0 to let the OS assign an available port. This
215+
# avoids "address already in use" errors when tests run
216+
# concurrently or ports are still in TIME_WAIT state.
218217
self.network_thread.listen(
219218
addr="127.0.0.1",
220-
port=ports_base + i,
219+
port=0,
221220
p2p=listener,
222221
callback=on_listen_done)
223222
# Wait until the callback has been called.

0 commit comments

Comments
 (0)