2
2
import threading
3
3
import time
4
4
from unittest import mock
5
- import unittest
6
5
import pytest
7
6
try :
8
7
from engineio .async_socket import AsyncSocket as EngineIOSocket
@@ -38,13 +37,13 @@ def connect(sid, environ, auth):
38
37
pass
39
38
40
39
async def shutdown ():
41
- await instrumented_server .shutdown ()
40
+ await self . isvr .shutdown ()
42
41
await sio .shutdown ()
43
42
44
43
if 'server_stats_interval' not in ikwargs :
45
44
ikwargs ['server_stats_interval' ] = 0.25
46
45
47
- instrumented_server = sio .instrument (auth = auth , ** ikwargs )
46
+ self . isvr = sio .instrument (auth = auth , ** ikwargs )
48
47
server = SocketIOWebServer (sio , on_shutdown = shutdown )
49
48
server .start ()
50
49
@@ -56,10 +55,11 @@ async def shutdown():
56
55
EngineIOSocket .schedule_ping = mock .MagicMock ()
57
56
58
57
try :
59
- ret = f (self , instrumented_server , * args , ** kwargs )
58
+ ret = f (self , * args , ** kwargs )
60
59
finally :
61
60
server .stop ()
62
- instrumented_server .uninstrument ()
61
+ self .isvr .uninstrument ()
62
+ self .isvr = None
63
63
64
64
EngineIOSocket .schedule_ping = original_schedule_ping
65
65
@@ -80,12 +80,12 @@ async def _async_custom_auth(auth):
80
80
return auth == {'foo' : 'bar' }
81
81
82
82
83
- class TestAsyncAdmin ( unittest . TestCase ) :
84
- def setUp (self ):
83
+ class TestAsyncAdmin :
84
+ def setup_method (self ):
85
85
print ('threads at start:' , threading .enumerate ())
86
86
self .thread_count = threading .active_count ()
87
87
88
- def tearDown (self ):
88
+ def teardown_method (self ):
89
89
print ('threads at end:' , threading .enumerate ())
90
90
assert self .thread_count == threading .active_count ()
91
91
@@ -107,15 +107,15 @@ def test_missing_auth(self):
107
107
sio .instrument ()
108
108
109
109
@with_instrumented_server (auth = False )
110
- def test_admin_connect_with_no_auth (self , isvr ):
110
+ def test_admin_connect_with_no_auth (self ):
111
111
with socketio .SimpleClient () as admin_client :
112
112
admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
113
113
with socketio .SimpleClient () as admin_client :
114
114
admin_client .connect ('http://localhost:8900' , namespace = '/admin' ,
115
115
auth = {'foo' : 'bar' })
116
116
117
117
@with_instrumented_server (auth = {'foo' : 'bar' })
118
- def test_admin_connect_with_dict_auth (self , isvr ):
118
+ def test_admin_connect_with_dict_auth (self ):
119
119
with socketio .SimpleClient () as admin_client :
120
120
admin_client .connect ('http://localhost:8900' , namespace = '/admin' ,
121
121
auth = {'foo' : 'bar' })
@@ -131,7 +131,7 @@ def test_admin_connect_with_dict_auth(self, isvr):
131
131
132
132
@with_instrumented_server (auth = [{'foo' : 'bar' },
133
133
{'u' : 'admin' , 'p' : 'secret' }])
134
- def test_admin_connect_with_list_auth (self , isvr ):
134
+ def test_admin_connect_with_list_auth (self ):
135
135
with socketio .SimpleClient () as admin_client :
136
136
admin_client .connect ('http://localhost:8900' , namespace = '/admin' ,
137
137
auth = {'foo' : 'bar' })
@@ -148,7 +148,7 @@ def test_admin_connect_with_list_auth(self, isvr):
148
148
namespace = '/admin' )
149
149
150
150
@with_instrumented_server (auth = _custom_auth )
151
- def test_admin_connect_with_function_auth (self , isvr ):
151
+ def test_admin_connect_with_function_auth (self ):
152
152
with socketio .SimpleClient () as admin_client :
153
153
admin_client .connect ('http://localhost:8900' , namespace = '/admin' ,
154
154
auth = {'foo' : 'bar' })
@@ -162,7 +162,7 @@ def test_admin_connect_with_function_auth(self, isvr):
162
162
namespace = '/admin' )
163
163
164
164
@with_instrumented_server (auth = _async_custom_auth )
165
- def test_admin_connect_with_async_function_auth (self , isvr ):
165
+ def test_admin_connect_with_async_function_auth (self ):
166
166
with socketio .SimpleClient () as admin_client :
167
167
admin_client .connect ('http://localhost:8900' , namespace = '/admin' ,
168
168
auth = {'foo' : 'bar' })
@@ -176,7 +176,7 @@ def test_admin_connect_with_async_function_auth(self, isvr):
176
176
namespace = '/admin' )
177
177
178
178
@with_instrumented_server ()
179
- def test_admin_connect_only_admin (self , isvr ):
179
+ def test_admin_connect_only_admin (self ):
180
180
with socketio .SimpleClient () as admin_client :
181
181
admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
182
182
sid = admin_client .sid
@@ -201,7 +201,7 @@ def test_admin_connect_only_admin(self, isvr):
201
201
events ['server_stats' ]['namespaces' ]
202
202
203
203
@with_instrumented_server ()
204
- def test_admin_connect_with_others (self , isvr ):
204
+ def test_admin_connect_with_others (self ):
205
205
with socketio .SimpleClient () as client1 , \
206
206
socketio .SimpleClient () as client2 , \
207
207
socketio .SimpleClient () as client3 , \
@@ -210,12 +210,12 @@ def test_admin_connect_with_others(self, isvr):
210
210
client1 .emit ('enter_room' , 'room' )
211
211
sid1 = client1 .sid
212
212
213
- saved_check_for_upgrade = isvr ._check_for_upgrade
214
- isvr ._check_for_upgrade = AsyncMock ()
213
+ saved_check_for_upgrade = self . isvr ._check_for_upgrade
214
+ self . isvr ._check_for_upgrade = AsyncMock ()
215
215
client2 .connect ('http://localhost:8900' , namespace = '/foo' ,
216
216
transports = ['polling' ])
217
217
sid2 = client2 .sid
218
- isvr ._check_for_upgrade = saved_check_for_upgrade
218
+ self . isvr ._check_for_upgrade = saved_check_for_upgrade
219
219
220
220
client3 .connect ('http://localhost:8900' , namespace = '/admin' )
221
221
sid3 = client3 .sid
@@ -251,7 +251,7 @@ def test_admin_connect_with_others(self, isvr):
251
251
assert socket ['rooms' ] == [sid3 ]
252
252
253
253
@with_instrumented_server (mode = 'production' , read_only = True )
254
- def test_admin_connect_production (self , isvr ):
254
+ def test_admin_connect_production (self ):
255
255
with socketio .SimpleClient () as admin_client :
256
256
admin_client .connect ('http://localhost:8900' , namespace = '/admin' )
257
257
events = self ._expect ({'config' : 1 , 'server_stats' : 2 },
@@ -272,7 +272,7 @@ def test_admin_connect_production(self, isvr):
272
272
events ['server_stats' ]['namespaces' ]
273
273
274
274
@with_instrumented_server ()
275
- def test_admin_features (self , isvr ):
275
+ def test_admin_features (self ):
276
276
with socketio .SimpleClient () as client1 , \
277
277
socketio .SimpleClient () as client2 , \
278
278
socketio .SimpleClient () as admin_client :
0 commit comments