Skip to content

Commit c7e32fd

Browse files
committed
Wait for the RPC Server to start before testing
When creating the RPC Server thread, a dummy event is added to the event loop. When the event loop has fully started, the dummy event unregisters itself and allows setup_env() to return. This fixes a race condition on my system, where test_connect_failed would fail so fast that the server ioloop didn't start by the time the test teardown would request the ioloop to stop.
1 parent 8630237 commit c7e32fd

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

test/test_msgpackrpc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,22 @@ def setUp(self):
7070
self._address = msgpackrpc.Address('localhost', helper.unused_port())
7171

7272
def setup_env(self):
73+
def _on_started():
74+
self._server._loop.dettach_periodic_callback()
75+
lock.release()
7376
def _start_server(server):
77+
server._loop.attach_periodic_callback(_on_started, 1)
7478
server.start()
7579
server.close()
7680

7781
self._server = msgpackrpc.Server(TestMessagePackRPC.TestServer())
7882
self._server.listen(self._address)
7983
self._thread = threading.Thread(target=_start_server, args=(self._server,))
84+
85+
lock = threading.Lock()
8086
self._thread.start()
87+
lock.acquire()
88+
lock.acquire() # wait for the server to start
8189

8290
self._client = msgpackrpc.Client(self._address, unpack_encoding='utf-8')
8391
return self._client;

0 commit comments

Comments
 (0)