Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of traitlets to configure YStore class #322

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions projects/jupyter-server-ydoc/jupyter_server_ydoc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import asyncio
from functools import partial
from typing import Literal

from jupyter_server.extension.application import ExtensionApp
Expand Down Expand Up @@ -96,13 +97,12 @@ def initialize_handlers(self):
page_config.setdefault("serverSideExecution", self.server_side_execution)

# Set configurable parameters to YStore class
for k, v in self.config.get(self.ystore_class.__name__, {}).items():
setattr(self.ystore_class, k, v)
ystore_class = partial(self.ystore_class, config=self.config)

self.ywebsocket_server = JupyterWebsocketServer(
rooms_ready=False,
auto_clean_rooms=False,
ystore_class=self.ystore_class,
ystore_class=ystore_class,
# Log exceptions, because we don't want the websocket server
# to _ever_ crash permanently in a live jupyter_server.
exception_handler=exception_logger,
Expand All @@ -125,7 +125,7 @@ def initialize_handlers(self):
"document_cleanup_delay": self.document_cleanup_delay,
"document_save_delay": self.document_save_delay,
"file_loaders": self.file_loaders,
"ystore_class": self.ystore_class,
"ystore_class": ystore_class,
"ywebsocket_server": self.ywebsocket_server,
},
),
Expand Down
13 changes: 7 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,9 @@ async def _inner(format: str, type: str, path: str) -> None:
return _inner


@pytest.fixture
def rtc_create_SQLite_store(jp_serverapp):
for k, v in jp_serverapp.config.get("SQLiteYStore").items():
setattr(SQLiteYStore, k, v)

def rtc_create_SQLite_store_factory(jp_serverapp):
async def _inner(type: str, path: str, content: str) -> DocumentRoom:
db = SQLiteYStore(path=f"{type}:{path}")
db = SQLiteYStore(path=f"{type}:{path}", config=jp_serverapp.config)
task = create_task(db.start())
await db.started.wait()

Expand All @@ -192,6 +188,11 @@ async def _inner(type: str, path: str, content: str) -> DocumentRoom:
return _inner


@pytest.fixture
def rtc_create_SQLite_store(jp_serverapp):
return rtc_create_SQLite_store_factory(jp_serverapp)


@pytest.fixture
def rtc_create_mock_document_room():
def _inner(
Expand Down
15 changes: 15 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pytest
from jupyter_server_ydoc.stores import SQLiteYStore, TempFileYStore

from .conftest import rtc_create_SQLite_store_factory


def test_default_settings(jp_serverapp):
settings = jp_serverapp.web_app.settings["jupyter_server_ydoc_config"]
Expand Down Expand Up @@ -62,6 +64,19 @@ def test_settings_should_change_ystore_class(jp_configurable_serverapp):
assert settings["ystore_class"] == TempFileYStore


async def test_document_ttl_from_settings(rtc_create_mock_document_room, jp_configurable_serverapp):
argv = ["--SQLiteYStore.document_ttl=3600"]

app = jp_configurable_serverapp(argv=argv)

id = "test-id"
content = "test_ttl"
rtc_create_SQLite_store = rtc_create_SQLite_store_factory(app)
store = await rtc_create_SQLite_store("file", id, content)

assert store.document_ttl == 3600


@pytest.mark.parametrize("copy", [True, False])
async def test_get_document_file(rtc_create_file, jp_serverapp, copy):
path, content = await rtc_create_file("test.txt", "test", store=True)
Expand Down
Loading