Skip to content

Commit

Permalink
Add events to gateway lifecycle test
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-bates committed Apr 15, 2023
1 parent fb6575f commit 56af18e
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

from .utils import expected_http_error

pytest_plugins = ["jupyter_events.pytest_plugin"]


def generate_kernelspec(name):
argv_stanza = ["python", "-m", "ipykernel_launcher", "-f", "{connection_file}"]
Expand Down Expand Up @@ -483,13 +485,28 @@ async def test_gateway_session_lifecycle(init_gateway, jp_root_dir, jp_fetch, cu

@pytest.mark.parametrize("cull_kernel", [False, True])
async def test_gateway_kernel_lifecycle(
init_gateway, jp_serverapp, jp_ws_fetch, jp_fetch, cull_kernel
init_gateway,
jp_configurable_serverapp,
jp_read_emitted_events,
jp_event_handler,
jp_ws_fetch,
jp_fetch,
cull_kernel,
):
# Validate kernel lifecycle functions; create, interrupt, restart and delete.

app = jp_configurable_serverapp()
app.event_logger.register_handler(jp_event_handler)

# create
kernel_id = await create_kernel(jp_fetch, "kspec_bar")

output = jp_read_emitted_events()[0]
assert "action" in output and output["action"] == "start"
assert "msg" in output
assert "kernel_id" in output and kernel_id == output["kernel_id"]
assert "status" in output and output["status"] == "success"

# ensure kernel still considered running
assert await is_kernel_running(jp_fetch, kernel_id) is True

Expand All @@ -502,12 +519,24 @@ async def test_gateway_kernel_lifecycle(
# interrupt
await interrupt_kernel(jp_fetch, kernel_id)

output = jp_read_emitted_events()[0]
assert "action" in output and output["action"] == "interrupt"
assert "msg" in output
assert "kernel_id" in output and kernel_id == output["kernel_id"]
assert "status" in output and output["status"] == "success"

# ensure kernel still considered running
assert await is_kernel_running(jp_fetch, kernel_id) is True

# restart
await restart_kernel(jp_fetch, kernel_id)

output = jp_read_emitted_events()[0]
assert "action" in output and output["action"] == "restart"
assert "msg" in output
assert "kernel_id" in output and kernel_id == output["kernel_id"]
assert "status" in output and output["status"] == "success"

# ensure kernel still considered running
assert await is_kernel_running(jp_fetch, kernel_id) is True

Expand All @@ -526,6 +555,12 @@ async def test_gateway_kernel_lifecycle(
else:
await delete_kernel(jp_fetch, kernel_id)

output = jp_read_emitted_events()[0]
assert "action" in output and output["action"] == "shutdown"
assert "msg" in output
assert "kernel_id" in output and kernel_id == output["kernel_id"]
assert "status" in output and output["status"] == "success"

assert await is_kernel_running(jp_fetch, kernel_id) is False


Expand Down

0 comments on commit 56af18e

Please sign in to comment.