@@ -89,6 +89,18 @@ def tearDown(self):
89
89
print ('threads at end:' , threading .enumerate ())
90
90
assert self .thread_count == threading .active_count ()
91
91
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
+
92
104
def test_missing_auth (self ):
93
105
sio = socketio .AsyncServer (async_mode = 'asgi' )
94
106
with pytest .raises (ValueError ):
@@ -168,13 +180,8 @@ def test_admin_connect_only_admin(self, isvr):
168
180
with socketio .SimpleClient () as admin_client :
169
181
admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
170
182
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 )
178
185
179
186
assert 'supportedFeatures' in events ['config' ]
180
187
assert 'ALL_EVENTS' in events ['config' ]['supportedFeatures' ]
@@ -215,13 +222,8 @@ def test_admin_connect_with_others(self, isvr):
215
222
216
223
admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
217
224
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 )
225
227
226
228
assert 'supportedFeatures' in events ['config' ]
227
229
assert 'ALL_EVENTS' in events ['config' ]['supportedFeatures' ]
@@ -252,13 +254,8 @@ def test_admin_connect_with_others(self, isvr):
252
254
def test_admin_connect_production (self , isvr ):
253
255
with socketio .SimpleClient () as admin_client :
254
256
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 )
262
259
263
260
assert 'supportedFeatures' in events ['config' ]
264
261
assert 'ALL_EVENTS' not in events ['config' ]['supportedFeatures' ]
0 commit comments