|
| 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 | +}) |
0 commit comments