Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self, host, port):
# that the asyncio server thread has finished startup.
self._server_started_event = threading.Event()
self._server_thread = threading.Thread(target=self._run_server_thread)
self._current_connection = None

def __enter__(self):
# main thread is entering the `with` block: start the server...
Expand Down Expand Up @@ -179,6 +180,13 @@ async def _run_connection(self, server_connection: websockets_server_3rdparty.Se
self._current_connection = None

def send_async(self, msg):
# Wait for a connection to be established before trying to send
max_wait = time() + TIMEOUT
while self._current_connection is None:
if time() > max_wait:
raise RuntimeError("Timeout waiting for WebSocket connection to be established")
sleep(0.01)

asyncio.run_coroutine_threadsafe(self._current_connection.send(msg), self._server_loop)


Expand Down