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

More updates to unit tests for pending kernels work #662

Merged
merged 1 commit into from
Jan 14, 2022
Merged
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
41 changes: 24 additions & 17 deletions jupyter_server/tests/services/sessions/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ async def cleanup(self):
time.sleep(0.1)


@pytest.fixture
def session_is_ready(jp_serverapp):
"""Wait for the kernel started by a session to be ready.

This is useful when working with pending kernels.
"""

async def _(session_id):
sm = jp_serverapp.session_manager
mkm = jp_serverapp.kernel_manager
session = await sm.get_session(session_id=session_id)
kernel_id = session["kernel"]["id"]
kernel = mkm.get_kernel(kernel_id)
await kernel.ready

return _


@pytest.fixture
def session_client(jp_root_dir, jp_fetch):
subdir = jp_root_dir.joinpath("foo")
Expand Down Expand Up @@ -156,7 +174,9 @@ def assert_session_equality(actual, expected):
assert_kernel_equality(actual["kernel"], expected["kernel"])


async def test_create(session_client, jp_base_url, jp_cleanup_subprocesses, jp_serverapp):
async def test_create(
session_client, jp_base_url, jp_cleanup_subprocesses, jp_serverapp, session_is_ready
):
# Make sure no sessions exist.
resp = await session_client.list()
sessions = j(resp)
Expand Down Expand Up @@ -197,7 +217,6 @@ async def test_create(session_client, jp_base_url, jp_cleanup_subprocesses, jp_s
assert_session_equality(got, new_session)

# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand All @@ -218,7 +237,6 @@ async def test_create_bad(
await session_client.create("foo/nb1.ipynb")

# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand Down Expand Up @@ -251,7 +269,6 @@ async def test_create_bad_pending(
assert "non_existent_path" in session["kernel"]["reason"]

# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand All @@ -261,7 +278,6 @@ async def test_create_file_session(session_client, jp_cleanup_subprocesses, jp_s
newsession = j(resp)
assert newsession["path"] == "foo/nb1.py"
assert newsession["type"] == "file"
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand All @@ -272,7 +288,6 @@ async def test_create_console_session(session_client, jp_cleanup_subprocesses, j
assert newsession["path"] == "foo/abc123"
assert newsession["type"] == "console"
# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand All @@ -284,7 +299,6 @@ async def test_create_deprecated(session_client, jp_cleanup_subprocesses, jp_ser
assert newsession["type"] == "notebook"
assert newsession["notebook"]["path"] == "foo/nb1.ipynb"
# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand Down Expand Up @@ -316,7 +330,6 @@ async def test_create_with_kernel_id(
got = j(resp)
assert_session_equality(got, new_session)
# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand All @@ -327,14 +340,15 @@ async def test_create_with_bad_kernel_id(session_client, jp_cleanup_subprocesses
# TODO
assert newsession["path"] == "foo/nb1.py"
assert newsession["type"] == "file"
await session_client.cleanup()
await jp_cleanup_subprocesses()


async def test_delete(session_client, jp_cleanup_subprocesses, jp_serverapp):
async def test_delete(session_client, jp_cleanup_subprocesses, jp_serverapp, session_is_ready):
resp = await session_client.create("foo/nb1.ipynb")

newsession = j(resp)
sid = newsession["id"]
await session_is_ready(sid)

resp = await session_client.delete(sid)
assert resp.code == 204
Expand All @@ -347,7 +361,6 @@ async def test_delete(session_client, jp_cleanup_subprocesses, jp_serverapp):
await session_client.get(sid)
assert expected_http_error(e, 404)
# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand All @@ -361,7 +374,6 @@ async def test_modify_path(session_client, jp_cleanup_subprocesses, jp_serverapp
assert changed["id"] == sid
assert changed["path"] == "nb2.ipynb"
# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand All @@ -375,7 +387,6 @@ async def test_modify_path_deprecated(session_client, jp_cleanup_subprocesses, j
assert changed["id"] == sid
assert changed["notebook"]["path"] == "nb2.ipynb"
# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand All @@ -389,7 +400,6 @@ async def test_modify_type(session_client, jp_cleanup_subprocesses, jp_serverapp
assert changed["id"] == sid
assert changed["type"] == "console"
# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand All @@ -414,7 +424,6 @@ async def test_modify_kernel_name(session_client, jp_fetch, jp_cleanup_subproces
assert kernel_list == [after["kernel"]]

# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand Down Expand Up @@ -446,7 +455,6 @@ async def test_modify_kernel_id(session_client, jp_fetch, jp_cleanup_subprocesse
assert kernel_list == [kernel]

# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()


Expand Down Expand Up @@ -509,5 +517,4 @@ async def test_restart_kernel(
assert model["connections"] == 1

# Need to find a better solution to this.
await session_client.cleanup()
await jp_cleanup_subprocesses()