@@ -203,6 +203,60 @@ async def mock_connect():
203203 assert c .connected is True
204204 assert c .namespaces == {'/bar' : '123' , '/foo' : '456' }
205205
206+ async def test_connect_wait_one_namespaces_error (self ):
207+ c = async_client .AsyncClient ()
208+ c .eio .connect = mock .AsyncMock ()
209+ c ._connect_event = mock .MagicMock ()
210+
211+ async def mock_connect ():
212+ if c .failed_namespaces == []:
213+ c .failed_namespaces = ['/foo' ]
214+ return True
215+ return False
216+
217+ c ._connect_event .wait = mock_connect
218+ with pytest .raises (exceptions .ConnectionError ,
219+ match = 'failed to connect: /foo' ):
220+ await c .connect (
221+ 'url' ,
222+ namespaces = ['/foo' ],
223+ wait = True ,
224+ wait_timeout = 0.01 ,
225+ )
226+ assert c .connected is False
227+ assert c .namespaces == {}
228+ assert c .failed_namespaces == ['/foo' ]
229+
230+ async def test_connect_wait_three_namespaces_error (self ):
231+ c = async_client .AsyncClient ()
232+ c .eio .connect = mock .AsyncMock ()
233+ c ._connect_event = mock .MagicMock ()
234+
235+ async def mock_connect ():
236+ if c .namespaces == {}:
237+ c .namespaces = {'/bar' : '123' }
238+ return True
239+ elif c .namespaces == {'/bar' : '123' } and c .failed_namespaces == []:
240+ c .failed_namespaces = ['/baz' ]
241+ return True
242+ elif c .failed_namespaces == ['/baz' ]:
243+ c .failed_namespaces = ['/baz' , '/foo' ]
244+ return True
245+ return False
246+
247+ c ._connect_event .wait = mock_connect
248+ with pytest .raises (exceptions .ConnectionError ,
249+ match = 'failed to connect: /baz, /foo' ):
250+ await c .connect (
251+ 'url' ,
252+ namespaces = ['/foo' , '/bar' , '/baz' ],
253+ wait = True ,
254+ wait_timeout = 0.01 ,
255+ )
256+ assert c .connected is False
257+ assert c .namespaces == {'/bar' : '123' }
258+ assert c .failed_namespaces == ['/baz' , '/foo' ]
259+
206260 async def test_connect_timeout (self ):
207261 c = async_client .AsyncClient ()
208262 c .eio .connect = mock .AsyncMock ()
0 commit comments