Skip to content

Commit dd60d00

Browse files
committed
added tests
1 parent ced28e2 commit dd60d00

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

js/tests/supervisord.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { expect } from 'vitest'
2+
import { sandboxTest, wait } from './setup'
3+
4+
async function waitForHealth(sandbox: any, maxRetries = 10, intervalMs = 100) {
5+
for (let i = 0; i < maxRetries; i++) {
6+
const result = await sandbox.commands.run(
7+
'curl -s -o /dev/null -w "%{http_code}" http://0.0.0.0:49999/health'
8+
)
9+
if (result.stdout.trim() === '200') {
10+
return true
11+
}
12+
await wait(intervalMs)
13+
}
14+
return false
15+
}
16+
17+
sandboxTest('restart after jupyter kill', async ({ sandbox }) => {
18+
// Verify health is up initially
19+
const initialHealth = await waitForHealth(sandbox)
20+
expect(initialHealth).toBe(true)
21+
22+
// Kill the jupyter process
23+
await sandbox.commands.run('supervisorctl stop jupyter')
24+
25+
// Wait for supervisord to restart it and health to come back
26+
const recovered = await waitForHealth(sandbox, 10, 100)
27+
expect(recovered).toBe(true)
28+
29+
// Verify code execution works after recovery
30+
const result = await sandbox.runCode('x = 1; x')
31+
expect(result.text).toEqual('1')
32+
})
33+
34+
sandboxTest('restart after code-interpreter kill', async ({ sandbox }) => {
35+
// Verify health is up initially
36+
const initialHealth = await waitForHealth(sandbox)
37+
expect(initialHealth).toBe(true)
38+
39+
// Kill the code-interpreter process
40+
await sandbox.commands.run('supervisorctl stop code-interpreter')
41+
42+
// Wait for supervisord to restart it and health to come back
43+
const recovered = await waitForHealth(sandbox, 10, 100)
44+
expect(recovered).toBe(true)
45+
46+
// Verify code execution works after recovery
47+
const result = await sandbox.runCode('x = 1; x')
48+
expect(result.text).toEqual('1')
49+
})
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import asyncio
2+
3+
from e2b_code_interpreter.code_interpreter_async import AsyncSandbox
4+
5+
6+
async def wait_for_health(sandbox: AsyncSandbox, max_retries=10, interval_ms=100):
7+
for _ in range(max_retries):
8+
result = await sandbox.commands.run(
9+
'curl -s -o /dev/null -w "%{http_code}" http://0.0.0.0:49999/health'
10+
)
11+
if result.stdout.strip() == "200":
12+
return True
13+
await asyncio.sleep(interval_ms / 1000)
14+
return False
15+
16+
17+
async def test_restart_after_jupyter_kill(async_sandbox: AsyncSandbox):
18+
# Verify health is up initially
19+
assert await wait_for_health(async_sandbox)
20+
21+
# Kill the jupyter process
22+
await async_sandbox.commands.run("supervisorctl stop jupyter")
23+
24+
# Wait for supervisord to restart it and health to come back
25+
assert await wait_for_health(async_sandbox, 10, 100)
26+
27+
# Verify code execution works after recovery
28+
result = await async_sandbox.run_code("x = 1; x")
29+
assert result.text == "1"
30+
31+
32+
async def test_restart_after_code_interpreter_kill(async_sandbox: AsyncSandbox):
33+
# Verify health is up initially
34+
assert await wait_for_health(async_sandbox)
35+
36+
# Kill the code-interpreter process
37+
await async_sandbox.commands.run("supervisorctl stop code-interpreter")
38+
39+
# Wait for supervisord to restart it and health to come back
40+
assert await wait_for_health(async_sandbox, 10, 100)
41+
42+
# Verify code execution works after recovery
43+
result = await async_sandbox.run_code("x = 1; x")
44+
assert result.text == "1"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import time
2+
3+
from e2b_code_interpreter.code_interpreter_sync import Sandbox
4+
5+
6+
def wait_for_health(sandbox: Sandbox, max_retries=10, interval_ms=100):
7+
for _ in range(max_retries):
8+
result = sandbox.commands.run(
9+
'curl -s -o /dev/null -w "%{http_code}" http://0.0.0.0:49999/health'
10+
)
11+
if result.stdout.strip() == "200":
12+
return True
13+
time.sleep(interval_ms / 1000)
14+
return False
15+
16+
17+
def test_restart_after_jupyter_kill(sandbox: Sandbox):
18+
# Verify health is up initially
19+
assert wait_for_health(sandbox)
20+
21+
# Kill the jupyter process
22+
sandbox.commands.run("supervisorctl stop jupyter")
23+
24+
# Wait for supervisord to restart it and health to come back
25+
assert wait_for_health(sandbox, 10, 100)
26+
27+
# Verify code execution works after recovery
28+
result = sandbox.run_code("x = 1; x")
29+
assert result.text == "1"
30+
31+
32+
def test_restart_after_code_interpreter_kill(sandbox: Sandbox):
33+
# Verify health is up initially
34+
assert wait_for_health(sandbox)
35+
36+
# Kill the code-interpreter process
37+
sandbox.commands.run("supervisorctl stop code-interpreter")
38+
39+
# Wait for supervisord to restart it and health to come back
40+
assert wait_for_health(sandbox, 10, 100)
41+
42+
# Verify code execution works after recovery
43+
result = sandbox.run_code("x = 1; x")
44+
assert result.text == "1"

0 commit comments

Comments
 (0)