diff --git a/jupyter_collaboration/handlers.py b/jupyter_collaboration/handlers.py index a4d05e72..46ab8e09 100644 --- a/jupyter_collaboration/handlers.py +++ b/jupyter_collaboration/handlers.py @@ -330,14 +330,14 @@ async def _clean_room(self) -> None: contains a copy of the document. In addition, we remove the file if there is no rooms subscribed to it. """ - async with self._room_lock(self._room_id): - assert isinstance(self.room, DocumentRoom) + assert isinstance(self.room, DocumentRoom) - if self._cleanup_delay is None: - return + if self._cleanup_delay is None: + return - await asyncio.sleep(self._cleanup_delay) + await asyncio.sleep(self._cleanup_delay) + async with self._room_lock(self._room_id): # Remove the room from the websocket server self.log.info("Deleting Y document from memory: %s", self.room.room_id) self._websocket_server.delete_room(room=self.room) diff --git a/tests/test_documents.py b/tests/test_documents.py index 20efb8dc..ae43fd8d 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -59,3 +59,25 @@ async def connect(file_format, file_type, file_path): tg.start_soon(connect, file_format, file_type, file_path) t1 = time() assert t1 - t0 < 0.5 + + +async def test_room_sequential_opening( + rtc_create_file, + rtc_connect_doc_client, +): + file_format = "text" + file_type = "file" + file_path = "dummy.txt" + await rtc_create_file(file_path) + + async def connect(file_format, file_type, file_path): + t0 = time() + async with await rtc_connect_doc_client(file_format, file_type, file_path) as ws: + pass + t1 = time() + return t1 - t0 + + dt = await connect(file_format, file_type, file_path) + assert dt < 1 + dt = await connect(file_format, file_type, file_path) + assert dt < 1