File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ;
@@ -160,7 +168,8 @@ def test_async_result(self):
160168
161169 def test_connect_failed (self ):
162170 client = self .setup_env ();
163- client = msgpackrpc .Client (msgpackrpc .Address ('localhost' , self ._address .port - 10 ), unpack_encoding = 'utf-8' )
171+ port = helper .unused_port ()
172+ client = msgpackrpc .Client (msgpackrpc .Address ('localhost' , port ), unpack_encoding = 'utf-8' )
164173 self .assertRaises (error .TransportError , lambda : client .call ('hello' ))
165174
166175 def test_timeout (self ):
You can’t perform that action at this time.
0 commit comments