Skip to content

Commit

Permalink
test: wait until the server to test shutdown is ready to accept conne…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
lars-reimann committed May 2, 2024
1 parent c2e8ea3 commit 88f6f56
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/safeds_runner/server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import itertools
import json
import multiprocessing
import sys
import threading

import psutil
Expand Down Expand Up @@ -439,9 +440,18 @@ async def test_runtime_error(

async def test_shutdown() -> None:
# Start the server that should be shut down
process = multiprocessing.Process(target=run_server_to_shutdown)
stdout_r, stdout_w = multiprocessing.Pipe()
process = multiprocessing.Process(target=run_server_to_shutdown, args=[stdout_w])
process.start()

# Wait until the server is ready to accept connections
for _ in range(10 * BASE_TIMEOUT):
if not stdout_r.poll(0.1):
continue

if "Started server process" in str(stdout_r.recv()).strip():
break

try:
# Send a shutdown message
async with socketio.AsyncSimpleClient() as client_:
Expand All @@ -466,7 +476,10 @@ async def test_shutdown() -> None:
assert process.exitcode == 0


def run_server_to_shutdown():
def run_server_to_shutdown(pipe: multiprocessing.connection.Connection):
sys.stdout.write = lambda value: pipe.send(value) # type: ignore[method-assign, assignment]
sys.stderr.write = lambda value: pipe.send(value) # type: ignore[method-assign, assignment]

server = SafeDsServer()
server._sio.eio.start_service_task = False
asyncio.run(server.startup(SHUTDOWN_PORT))

0 comments on commit 88f6f56

Please sign in to comment.