Skip to content

Commit 8f55ea5

Browse files
Fix slow room opening (#264)
* Fix slow room opening * Add fix
1 parent 35a515c commit 8f55ea5

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

jupyter_collaboration/handlers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,14 @@ async def _clean_room(self) -> None:
330330
contains a copy of the document. In addition, we remove the file if there is no rooms
331331
subscribed to it.
332332
"""
333-
async with self._room_lock(self._room_id):
334-
assert isinstance(self.room, DocumentRoom)
333+
assert isinstance(self.room, DocumentRoom)
335334

336-
if self._cleanup_delay is None:
337-
return
335+
if self._cleanup_delay is None:
336+
return
338337

339-
await asyncio.sleep(self._cleanup_delay)
338+
await asyncio.sleep(self._cleanup_delay)
340339

340+
async with self._room_lock(self._room_id):
341341
# Remove the room from the websocket server
342342
self.log.info("Deleting Y document from memory: %s", self.room.room_id)
343343
self._websocket_server.delete_room(room=self.room)

tests/test_documents.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,25 @@ async def connect(file_format, file_type, file_path):
5959
tg.start_soon(connect, file_format, file_type, file_path)
6060
t1 = time()
6161
assert t1 - t0 < 0.5
62+
63+
64+
async def test_room_sequential_opening(
65+
rtc_create_file,
66+
rtc_connect_doc_client,
67+
):
68+
file_format = "text"
69+
file_type = "file"
70+
file_path = "dummy.txt"
71+
await rtc_create_file(file_path)
72+
73+
async def connect(file_format, file_type, file_path):
74+
t0 = time()
75+
async with await rtc_connect_doc_client(file_format, file_type, file_path) as ws:
76+
pass
77+
t1 = time()
78+
return t1 - t0
79+
80+
dt = await connect(file_format, file_type, file_path)
81+
assert dt < 1
82+
dt = await connect(file_format, file_type, file_path)
83+
assert dt < 1

0 commit comments

Comments
 (0)