Skip to content

Commit 232cef1

Browse files
Correctly handle emits to multiple rooms in the async server (Fixes #1081)
1 parent 81f872c commit 232cef1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/socketio/asyncio_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def emit(self, event, data, namespace, room=None, skip_sid=None,
1515
1616
Note: this method is a coroutine.
1717
"""
18-
if namespace not in self.rooms or room not in self.rooms[namespace]:
18+
if namespace not in self.rooms:
1919
return
2020
tasks = []
2121
if not isinstance(skip_sid, list):

tests/asyncio/test_asyncio_manager.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,29 @@ def test_emit_to_room(self):
244244
'456', 'my event', {'foo': 'bar'}, '/foo', None
245245
)
246246

247+
def test_emit_to_rooms(self):
248+
sid1 = self.bm.connect('123', '/foo')
249+
self.bm.enter_room(sid1, '/foo', 'bar')
250+
sid2 = self.bm.connect('456', '/foo')
251+
self.bm.enter_room(sid2, '/foo', 'bar')
252+
self.bm.enter_room(sid2, '/foo', 'baz')
253+
sid3 = self.bm.connect('789', '/foo')
254+
self.bm.enter_room(sid3, '/foo', 'baz')
255+
_run(
256+
self.bm.emit('my event', {'foo': 'bar'}, namespace='/foo',
257+
room=['bar', 'baz'])
258+
)
259+
assert self.bm.server._emit_internal.mock.call_count == 3
260+
self.bm.server._emit_internal.mock.assert_any_call(
261+
'123', 'my event', {'foo': 'bar'}, '/foo', None
262+
)
263+
self.bm.server._emit_internal.mock.assert_any_call(
264+
'456', 'my event', {'foo': 'bar'}, '/foo', None
265+
)
266+
self.bm.server._emit_internal.mock.assert_any_call(
267+
'789', 'my event', {'foo': 'bar'}, '/foo', None
268+
)
269+
247270
def test_emit_to_all(self):
248271
sid1 = self.bm.connect('123', '/foo')
249272
self.bm.enter_room(sid1, '/foo', 'bar')

0 commit comments

Comments
 (0)