Skip to content

Commit 443c546

Browse files
committed
added try/catch blocks to avoid throwing on negative err code
1 parent a31d702 commit 443c546

File tree

3 files changed

+47
-21
lines changed

3 files changed

+47
-21
lines changed

js/tests/supervisord.test.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ sandboxTest('restart after jupyter kill', async ({ sandbox }) => {
2424
expect(initialHealth).toBe(true)
2525

2626
// Kill the jupyter process as root
27-
await sandbox.commands.run("kill -9 $(pgrep -f 'jupyter server') || true", {
28-
user: 'root',
29-
})
27+
// The command handle may get killed too (since killing jupyter cascades to code-interpreter),
28+
// so we catch the error.
29+
try {
30+
await sandbox.commands.run("kill -9 $(pgrep -f 'jupyter server')", {
31+
user: 'root',
32+
})
33+
} catch {
34+
// Expected — the kill cascade may terminate the command handle
35+
}
3036

31-
// Wait for supervisord to restart it and health to come back
32-
const recovered = await waitForHealth(sandbox, 20, 100)
37+
// Wait for supervisord to restart both services (jupyter startup + code-interpreter startup)
38+
const recovered = await waitForHealth(sandbox, 60, 500)
3339
expect(recovered).toBe(true)
3440

3541
// Verify code execution works after recovery
@@ -43,12 +49,16 @@ sandboxTest('restart after code-interpreter kill', async ({ sandbox }) => {
4349
expect(initialHealth).toBe(true)
4450

4551
// Kill the code-interpreter process as root
46-
await sandbox.commands.run('kill -9 $(cat /var/run/code-interpreter.pid) || true', {
47-
user: 'root',
48-
})
52+
try {
53+
await sandbox.commands.run('kill -9 $(cat /var/run/code-interpreter.pid)', {
54+
user: 'root',
55+
})
56+
} catch {
57+
// Expected — killing code-interpreter may terminate the command handle
58+
}
4959

5060
// Wait for supervisord to restart it and health to come back
51-
const recovered = await waitForHealth(sandbox, 20, 100)
61+
const recovered = await waitForHealth(sandbox, 60, 500)
5262
expect(recovered).toBe(true)
5363

5464
// Verify code execution works after recovery

python/tests/async/test_async_supervisord.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ async def test_restart_after_jupyter_kill(async_sandbox: AsyncSandbox):
2222
assert await wait_for_health(async_sandbox)
2323

2424
# Kill the jupyter process as root
25-
await async_sandbox.commands.run("kill -9 $(pgrep -f 'jupyter server') || true", user="root")
25+
# The command handle may get killed too (killing jupyter cascades to code-interpreter),
26+
# so we catch the error.
27+
try:
28+
await async_sandbox.commands.run("kill -9 $(pgrep -f 'jupyter server')", user="root")
29+
except Exception:
30+
pass
2631

27-
# Wait for supervisord to restart it and health to come back
28-
assert await wait_for_health(async_sandbox, 20, 100)
32+
# Wait for supervisord to restart both services
33+
assert await wait_for_health(async_sandbox, 60, 500)
2934

3035
# Verify code execution works after recovery
3136
result = await async_sandbox.run_code("x = 1; x")
@@ -37,10 +42,13 @@ async def test_restart_after_code_interpreter_kill(async_sandbox: AsyncSandbox):
3742
assert await wait_for_health(async_sandbox)
3843

3944
# Kill the code-interpreter process as root
40-
await async_sandbox.commands.run("kill -9 $(cat /var/run/code-interpreter.pid) || true", user="root")
45+
try:
46+
await async_sandbox.commands.run("kill -9 $(cat /var/run/code-interpreter.pid)", user="root")
47+
except Exception:
48+
pass
4149

4250
# Wait for supervisord to restart it and health to come back
43-
assert await wait_for_health(async_sandbox, 20, 100)
51+
assert await wait_for_health(async_sandbox, 60, 500)
4452

4553
# Verify code execution works after recovery
4654
result = await async_sandbox.run_code("x = 1; x")

python/tests/sync/test_supervisord.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ def test_restart_after_jupyter_kill(sandbox: Sandbox):
2222
assert wait_for_health(sandbox)
2323

2424
# Kill the jupyter process as root
25-
sandbox.commands.run("kill -9 $(pgrep -f 'jupyter server') || true", user="root")
25+
# The command handle may get killed too (killing jupyter cascades to code-interpreter),
26+
# so we catch the error.
27+
try:
28+
sandbox.commands.run("kill -9 $(pgrep -f 'jupyter server')", user="root")
29+
except Exception:
30+
pass
2631

27-
# Wait for supervisord to restart it and health to come back
28-
assert wait_for_health(sandbox, 20, 100)
32+
# Wait for supervisord to restart both services
33+
assert wait_for_health(sandbox, 60, 500)
2934

3035
# Verify code execution works after recovery
3136
result = sandbox.run_code("x = 1; x")
@@ -37,12 +42,15 @@ def test_restart_after_code_interpreter_kill(sandbox: Sandbox):
3742
assert wait_for_health(sandbox)
3843

3944
# Kill the code-interpreter process as root
40-
sandbox.commands.run(
41-
"kill -9 $(cat /var/run/code-interpreter.pid) || true", user="root"
42-
)
45+
try:
46+
sandbox.commands.run(
47+
"kill -9 $(cat /var/run/code-interpreter.pid)", user="root"
48+
)
49+
except Exception:
50+
pass
4351

4452
# Wait for supervisord to restart it and health to come back
45-
assert wait_for_health(sandbox, 20, 100)
53+
assert wait_for_health(sandbox, 60, 500)
4654

4755
# Verify code execution works after recovery
4856
result = sandbox.run_code("x = 1; x")

0 commit comments

Comments
 (0)