-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathsystemd.test.ts
More file actions
73 lines (64 loc) · 2.17 KB
/
systemd.test.ts
File metadata and controls
73 lines (64 loc) · 2.17 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
import { expect } from 'vitest'
import { isDebug, 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.skipIf(isDebug)(
'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 systemd to restart both services
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.skipIf(isDebug)(
'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 $(pgrep -f 'uvicorn main:app')", {
user: 'root',
})
} catch {
// Expected — killing code-interpreter may terminate the command handle
}
// Wait for systemd 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')
}
)