diff --git a/.github/workflows/coverage_runner.yml b/.github/workflows/coverage_runner.yml index ea320d0428..4ee215502d 100644 --- a/.github/workflows/coverage_runner.yml +++ b/.github/workflows/coverage_runner.yml @@ -139,7 +139,7 @@ jobs: chmod +x rcd-ubuntu-latest ./rcd-ubuntu-latest -version $HZ_VERSION & # wait for a bit for RCD to download artifacts - sleep 10 + python3 ./tests/hzrc/waitport.py pytest --verbose --cov=hazelcast --cov-report=xml - name: Run tests (Windows) @@ -149,7 +149,7 @@ jobs: run: | Start-Process -FilePath .\rcd-windows-latest -ArgumentList '-version', $Env:HZ_VERSION -RedirectStandardOutput rcd-stdout.log -RedirectStandardError rcd-stderr.log # wait for a bit for RCD to download artifacts - sleep 10 + python3 ./tests/hzrc/waitport.py echo "RCD Log:" cat rcd-stdout.log cat rcd-stderr.log diff --git a/tests/hzrc/waitport.py b/tests/hzrc/waitport.py new file mode 100644 index 0000000000..5b3022f9db --- /dev/null +++ b/tests/hzrc/waitport.py @@ -0,0 +1,47 @@ +import asyncio +import socket +import sys + + +class Protocol(asyncio.BaseProtocol): + pass + + +async def connect(host: str, port: int): + loop = asyncio.get_running_loop() + while True: + try: + return await loop.create_connection( + lambda: Protocol(), + host, + port, + family=socket.AF_INET, + ) + except ConnectionRefusedError: + await asyncio.sleep(0.1) + + +async def print_waiting_msg(host, port): + await asyncio.sleep(1) + print(f"Waiting for {host}:{port} to become available...") + + +async def amain(): + host = "127.0.0.1" + port = 9701 + timeout = 120 # seconds + msg_task = asyncio.create_task(print_waiting_msg(host, port)) + + try: + await asyncio.wait_for(connect(host, port), timeout) + except TimeoutError: + print(f"FAILED to connect in {timeout} seconds.") + sys.exit(1) + + msg_task.cancel() + print(f"OK, {host}:{port} is up.") + await asyncio.sleep(1) + + +if __name__ == "__main__": + asyncio.run(amain())