mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-09 22:28:51 +02:00
test: use dynamic port allocation to avoid test conflicts
Use port=0 for dynamic port allocation in test framework components to avoid "address already in use" errors from concurrent tests or ports stuck in TIME_WAIT state from previous test runs. Changes: - socks5.py: Update conf.addr after bind() to reflect actual port - p2p.py: Retrieve actual port after create_server() when port=0 - feature_proxy.py: Use port=0 for all SOCKS5 proxy servers - feature_anchors.py: Use port=0 for onion proxy server
This commit is contained in:
@@ -787,13 +787,14 @@ class NetworkThread(threading.Thread):
|
||||
cls.protos[(addr, port)] = None
|
||||
return response
|
||||
|
||||
if (addr, port) not in cls.listeners:
|
||||
if port == 0 or (addr, port) not in cls.listeners:
|
||||
# When creating a listener on a given (addr, port) we only need to
|
||||
# do it once. If we want different behaviors for different
|
||||
# connections, we can accomplish this by providing different
|
||||
# `proto` functions
|
||||
|
||||
listener = await cls.network_event_loop.create_server(peer_protocol, addr, port)
|
||||
port = listener.sockets[0].getsockname()[1]
|
||||
logger.debug("Listening server on %s:%d should be started" % (addr, port))
|
||||
cls.listeners[(addr, port)] = listener
|
||||
|
||||
|
||||
@@ -203,6 +203,9 @@ class Socks5Server():
|
||||
self.s = socket.socket(conf.af)
|
||||
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self.s.bind(conf.addr)
|
||||
# When port=0, the OS assigns an available port. Update conf.addr
|
||||
# to reflect the actual bound address so callers can use it.
|
||||
self.conf.addr = self.s.getsockname()
|
||||
self.s.listen(5)
|
||||
self.running = False
|
||||
self.thread = None
|
||||
|
||||
Reference in New Issue
Block a user