-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathsupervisord.test.ts
More file actions
90 lines (77 loc) · 2.82 KB
/
supervisord.test.ts
File metadata and controls
90 lines (77 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { expect } from 'vitest'
import { sandboxTest, wait } from './setup'
async function waitForHealth(sandbox: any, maxRetries = 10, intervalMs = 100) {
for (let i = 0; i < maxRetries; i++) {
try {
const result = await sandbox.commands.run(
'curl -s -o /dev/null -w "%{http_code}" http://0.0.0.0:49999/health'
)
if (result.stdout.trim() === '200') {
return true
}
} catch {
// Connection refused or other error, retry
}
await wait(intervalMs)
}
return false
}
sandboxTest('restart after jupyter kill', async ({ sandbox }) => {
// Verify health is up initially
const initialHealth = await waitForHealth(sandbox)
expect(initialHealth).toBe(true)
// Kill the jupyter process as root
// The command handle may get killed too (since killing jupyter cascades to code-interpreter),
// so we catch the error.
try {
await sandbox.commands.run("kill -9 $(pgrep -f 'jupyter server')", {
user: 'root',
})
} catch {
// Expected — the kill cascade may terminate the command handle
}
// Wait for supervisord to restart both services (jupyter startup + code-interpreter startup)
const recovered = await waitForHealth(sandbox, 60, 500)
expect(recovered).toBe(true)
// Verify code execution works after recovery
const result = await sandbox.runCode('x = 1; x')
expect(result.text).toEqual('1')
})
sandboxTest('restart after jupyter kernel kill', async ({ sandbox }) => {
// Verify code execution works initially
const code = await sandbox.runCode('x = 42; x')
expect(code.text).toEqual('42')
// Kill all jupyter kernel processes as root
try {
await sandbox.commands.run("kill -9 $(pgrep -f 'ipykernel_launcher')", {
user: 'root',
})
} catch {
// Expected — the kill may terminate the command handle
}
// First call after kill returns context restarted error
const code2 = await sandbox.runCode('x')
expect(code2.error!.value).toEqual('Context was restarted')
// Subsequent call works normally
const code3 = await sandbox.runCode('y = 1; y')
expect(code3.text).toEqual('1')
})
sandboxTest('restart after code-interpreter kill', async ({ sandbox }) => {
// Verify health is up initially
const initialHealth = await waitForHealth(sandbox)
expect(initialHealth).toBe(true)
// Kill the code-interpreter process as root
try {
await sandbox.commands.run('kill -9 $(cat /var/run/code-interpreter.pid)', {
user: 'root',
})
} catch {
// Expected — killing code-interpreter may terminate the command handle
}
// Wait for supervisord to restart it and health to come back
const recovered = await waitForHealth(sandbox, 60, 500)
expect(recovered).toBe(true)
// Verify code execution works after recovery
const result = await sandbox.runCode('x = 1; x')
expect(result.text).toEqual('1')
})