Skip to content

Commit 648e8f5

Browse files
committed
added tests for kernel restart
1 parent 1fba96d commit 648e8f5

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

js/tests/supervisord.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ sandboxTest('restart after jupyter kill', async ({ sandbox }) => {
4343
expect(result.text).toEqual('1')
4444
})
4545

46+
sandboxTest('restart after jupyter kernel kill', async ({ sandbox }) => {
47+
// Verify code execution works initially
48+
const code = await sandbox.runCode('x = 42; x')
49+
expect(code.text).toEqual('42')
50+
51+
// Kill all jupyter kernel processes as root
52+
try {
53+
await sandbox.commands.run("kill -9 $(pgrep -f 'ipykernel_launcher')", {
54+
user: 'root',
55+
})
56+
} catch {
57+
// Expected — the kill may terminate the command handle
58+
}
59+
60+
// Code execution still works but the variable is undefined
61+
const code2 = await sandbox.runCode('x')
62+
expect(code2.error!.value).toEqual("name 'x' is not defined")
63+
})
64+
4665
sandboxTest('restart after code-interpreter kill', async ({ sandbox }) => {
4766
// Verify health is up initially
4867
const initialHealth = await waitForHealth(sandbox)

python/tests/async/test_async_supervisord.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ async def test_restart_after_jupyter_kill(async_sandbox: AsyncSandbox):
3939
assert result.text == "1"
4040

4141

42+
async def test_restart_after_jupyter_kernel_kill(async_sandbox: AsyncSandbox):
43+
# Verify code execution works initially
44+
initial = await async_sandbox.run_code("x = 42; x")
45+
assert initial.text == "42"
46+
47+
# Kill all jupyter kernel processes as root
48+
try:
49+
await async_sandbox.commands.run(
50+
"kill -9 $(pgrep -f 'ipykernel_launcher')", user="root"
51+
)
52+
except Exception:
53+
pass
54+
55+
# Code execution still works but the variable is undefined
56+
result = await async_sandbox.run_code("x")
57+
assert result.error is not None
58+
assert result.error.value == "name 'x' is not defined"
59+
60+
4261
async def test_restart_after_code_interpreter_kill(async_sandbox: AsyncSandbox):
4362
# Verify health is up initially
4463
assert await wait_for_health(async_sandbox)

python/tests/sync/test_supervisord.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ def test_restart_after_jupyter_kill(sandbox: Sandbox):
3737
assert result.text == "1"
3838

3939

40+
def test_restart_after_jupyter_kernel_kill(sandbox: Sandbox):
41+
# Verify code execution works initially
42+
initial = sandbox.run_code("x = 42; x")
43+
assert initial.text == "42"
44+
45+
# Kill all jupyter kernel processes as root
46+
try:
47+
sandbox.commands.run(
48+
"kill -9 $(pgrep -f 'ipykernel_launcher')", user="root"
49+
)
50+
except Exception:
51+
pass
52+
53+
# Code execution still works but the variable is undefined
54+
result = sandbox.run_code("x")
55+
assert result.error is not None
56+
assert result.error.value == "name 'x' is not defined"
57+
58+
4059
def test_restart_after_code_interpreter_kill(sandbox: Sandbox):
4160
# Verify health is up initially
4261
assert wait_for_health(sandbox)

0 commit comments

Comments
 (0)