| 248 | |
| 249 | @with_instrumented_server() |
| 250 | def test_admin_features(self): |
| 251 | with socketio.SimpleClient(reconnection=False) as client1, \ |
| 252 | socketio.SimpleClient(reconnection=False) as client2, \ |
| 253 | socketio.SimpleClient(reconnection=False) as admin_client: |
| 254 | client1.connect('http://localhost:8900') |
| 255 | client2.connect('http://localhost:8900') |
| 256 | admin_client.connect('http://localhost:8900', namespace='/admin') |
| 257 | |
| 258 | # emit from admin |
| 259 | admin_client.emit( |
| 260 | 'emit', ('/', client1.sid, 'foo', {'bar': 'baz'}, 'extra')) |
| 261 | data = client1.receive(timeout=5) |
| 262 | assert data == ['foo', {'bar': 'baz'}, 'extra'] |
| 263 | |
| 264 | # emit from regular client |
| 265 | client1.emit('emit', 'foo') |
| 266 | data = client2.receive(timeout=5) |
| 267 | assert data == ['foo'] |
| 268 | |
| 269 | # join and leave |
| 270 | admin_client.emit('join', ('/', 'room', client1.sid)) |
| 271 | time.sleep(0.2) |
| 272 | admin_client.emit( |
| 273 | 'emit', ('/', 'room', 'foo', {'bar': 'baz'})) |
| 274 | data = client1.receive(timeout=5) |
| 275 | assert data == ['foo', {'bar': 'baz'}] |
| 276 | admin_client.emit('leave', ('/', 'room')) |
| 277 | |
| 278 | # disconnect |
| 279 | admin_client.emit('_disconnect', ('/', False, client1.sid)) |
| 280 | for _ in range(10): |
| 281 | if not client1.connected: |
| 282 | break |
| 283 | time.sleep(0.2) |
| 284 | assert not client1.connected |