Skip to content

Commit

Permalink
Add rtc_document_save_delay fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Mar 21, 2024
1 parent f57a797 commit c8fa7fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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}
}


Expand Down
15 changes: 11 additions & 4 deletions tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

0 comments on commit c8fa7fd

Please sign in to comment.