From b92aefdaf39719bee79ae47198e9eae512fe1857 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Thu, 21 Mar 2024 09:28:41 +0100 Subject: [PATCH] Add rtc_document_save_delay fixture --- tests/conftest.py | 8 +++++++- tests/test_documents.py | 15 +++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 17fc6ef6..943e2172 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,7 +23,12 @@ @pytest.fixture -def jp_server_config(jp_root_dir, jp_server_config): +def rtc_document_save_delay(): + return 1 + + +@pytest.fixture +def jp_server_config(jp_root_dir, jp_server_config, rtc_document_save_delay): return { "ServerApp": { "jpserver_extensions": {"jupyter_collaboration": True, "jupyter_server_fileid": True}, @@ -37,6 +42,7 @@ def jp_server_config(jp_root_dir, jp_server_config): "db_path": str(jp_root_dir.joinpath(".fid_test.db")), "db_journal_mode": "OFF", }, + "YDocExtension": {"document_save_delay": rtc_document_save_delay}, } diff --git a/tests/test_documents.py b/tests/test_documents.py index f398eb89..35b1f213 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -8,15 +8,22 @@ else: from importlib.metadata import entry_points +import pytest from anyio import sleep from pycrdt_websocket import WebsocketProvider jupyter_ydocs = {ep.name: ep.load() for ep in entry_points(group="jupyter_ydoc")} +@pytest.fixture +def rtc_document_save_delay(): + return 0.5 + + async def test_dirty( rtc_create_file, rtc_connect_doc_client, + rtc_document_save_delay, ): file_format = "text" file_type = "file" @@ -26,7 +33,7 @@ async def test_dirty( async with await rtc_connect_doc_client(file_format, file_type, file_path) as ws: async with WebsocketProvider(jupyter_ydoc.ydoc, ws): - jupyter_ydoc.dirty = True - assert jupyter_ydoc.dirty - await sleep(1.5) - assert not jupyter_ydoc.dirty + for _ in range(2): + jupyter_ydoc.dirty = True + await sleep(rtc_document_save_delay * 1.5) + assert not jupyter_ydoc.dirty