@@ -89,6 +89,18 @@ def tearDown(self):
8989 print ('threads at end:' , threading .enumerate ())
9090 assert self .thread_count == threading .active_count ()
9191
92+ def _expect (self , expected , admin_client ):
93+ events = {}
94+ while expected :
95+ data = admin_client .receive (timeout = 5 )
96+ if data [0 ] in expected :
97+ if expected [data [0 ]] == 1 :
98+ events [data [0 ]] = data [1 ]
99+ del expected [data [0 ]]
100+ else :
101+ expected [data [0 ]] -= 1
102+ return events
103+
92104 def test_missing_auth (self ):
93105 sio = socketio .AsyncServer (async_mode = 'asgi' )
94106 with pytest .raises (ValueError ):
@@ -168,13 +180,8 @@ def test_admin_connect_only_admin(self, isvr):
168180 with socketio .SimpleClient () as admin_client :
169181 admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
170182 sid = admin_client .sid
171- expected = ['config' , 'all_sockets' , 'server_stats' ]
172- events = {}
173- while expected :
174- data = admin_client .receive (timeout = 5 )
175- if data [0 ] in expected :
176- events [data [0 ]] = data [1 ]
177- expected .remove (data [0 ])
183+ events = self ._expect ({'config' : 1 , 'all_sockets' : 1 ,
184+ 'server_stats' : 2 }, admin_client )
178185
179186 assert 'supportedFeatures' in events ['config' ]
180187 assert 'ALL_EVENTS' in events ['config' ]['supportedFeatures' ]
@@ -215,13 +222,8 @@ def test_admin_connect_with_others(self, isvr):
215222
216223 admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
217224 sid = admin_client .sid
218- expected = ['config' , 'all_sockets' , 'server_stats' ]
219- events = {}
220- while expected :
221- data = admin_client .receive (timeout = 5 )
222- if data [0 ] in expected :
223- events [data [0 ]] = data [1 ]
224- expected .remove (data [0 ])
225+ events = self ._expect ({'config' : 1 , 'all_sockets' : 1 ,
226+ 'server_stats' : 2 }, admin_client )
225227
226228 assert 'supportedFeatures' in events ['config' ]
227229 assert 'ALL_EVENTS' in events ['config' ]['supportedFeatures' ]
@@ -252,13 +254,8 @@ def test_admin_connect_with_others(self, isvr):
252254 def test_admin_connect_production (self , isvr ):
253255 with socketio .SimpleClient () as admin_client :
254256 admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
255- expected = ['config' , 'server_stats' ]
256- events = {}
257- while expected :
258- data = admin_client .receive (timeout = 5 )
259- if data [0 ] in expected :
260- events [data [0 ]] = data [1 ]
261- expected .remove (data [0 ])
257+ events = self ._expect ({'config' : 1 , 'server_stats' : 2 },
258+ admin_client )
262259
263260 assert 'supportedFeatures' in events ['config' ]
264261 assert 'ALL_EVENTS' not in events ['config' ]['supportedFeatures' ]
0 commit comments