diff --git a/.changelog/bugfix-fix-protocol-mock-server-ready.json b/.changelog/bugfix-fix-protocol-mock-server-ready.json new file mode 100644 index 00000000000..8ce064b8537 --- /dev/null +++ b/.changelog/bugfix-fix-protocol-mock-server-ready.json @@ -0,0 +1,6 @@ +{ + "type": "bugfix", + "category": "tools", + "contributor": "sbiscigl", + "description": "Wait for the protocol tests mock server to accept connections before running each protocol test binary, so the first test no longer fails with a connection refused error when the server is slow to start." +} diff --git a/tools/scripts/run_protocol_tests.py b/tools/scripts/run_protocol_tests.py index baead62b86d..93a4f90c1b1 100644 --- a/tools/scripts/run_protocol_tests.py +++ b/tools/scripts/run_protocol_tests.py @@ -12,6 +12,7 @@ import os import shutil import signal +import socket import subprocess import time @@ -276,6 +277,14 @@ def __init__(self): python_cmd = [shutil.which("python3"), PROTO_TEST_MOCK_HANDLER] self.process = subprocess.Popen(python_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(f"Started mock server with PID {self.process.pid}") + seconds_waited = 0 + while seconds_waited < 30: + try: + with socket.create_connection(("127.0.0.1", 1994)): + break + except ConnectionRefusedError: + time.sleep(1) + seconds_waited += 1 except Exception as exc: print(f"ERROR: unable to start Mock server:\n{exc}") raise exc