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:
woltx
2025-12-30 23:30:17 -08:00
parent aeaa67a9ea
commit ce63d37ebe
4 changed files with 16 additions and 11 deletions

View File

@@ -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