Skip to content

Commit fc7b503

Browse files
authored
fixes local Docker testing setup (#238)
* preserve E2B_LOCAL var in sudo * disable reconnect and systemd tests on debug * fmt
1 parent 6d703a4 commit fc7b503

File tree

7 files changed

+64
-44
lines changed

7 files changed

+64
-44
lines changed

js/tests/reconnect.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { expect } from 'vitest'
22

33
import { Sandbox } from '../src'
4-
import { sandboxTest } from './setup'
4+
import { isDebug, sandboxTest } from './setup'
55

6-
sandboxTest('reconnect', async ({ sandbox }) => {
6+
sandboxTest.skipIf(isDebug)('reconnect', async ({ sandbox }) => {
77
sandbox = await Sandbox.connect(sandbox.sandboxId)
88

99
const result = await sandbox.runCode('x =1; x')

js/tests/systemd.test.ts

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'vitest'
2-
import { sandboxTest, wait } from './setup'
2+
import { isDebug, sandboxTest, wait } from './setup'
33

44
async function waitForHealth(sandbox: any, maxRetries = 10, intervalMs = 100) {
55
for (let i = 0; i < maxRetries; i++) {
@@ -18,50 +18,56 @@ async function waitForHealth(sandbox: any, maxRetries = 10, intervalMs = 100) {
1818
return false
1919
}
2020

21-
sandboxTest('restart after jupyter kill', async ({ sandbox }) => {
22-
// Verify health is up initially
23-
const initialHealth = await waitForHealth(sandbox)
24-
expect(initialHealth).toBe(true)
21+
sandboxTest.skipIf(isDebug)(
22+
'restart after jupyter kill',
23+
async ({ sandbox }) => {
24+
// Verify health is up initially
25+
const initialHealth = await waitForHealth(sandbox)
26+
expect(initialHealth).toBe(true)
2527

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

37-
// Wait for systemd to restart both services
38-
const recovered = await waitForHealth(sandbox, 60, 500)
39-
expect(recovered).toBe(true)
39+
// Wait for systemd to restart both services
40+
const recovered = await waitForHealth(sandbox, 60, 500)
41+
expect(recovered).toBe(true)
4042

41-
// Verify code execution works after recovery
42-
const result = await sandbox.runCode('x = 1; x')
43-
expect(result.text).toEqual('1')
44-
})
43+
// Verify code execution works after recovery
44+
const result = await sandbox.runCode('x = 1; x')
45+
expect(result.text).toEqual('1')
46+
}
47+
)
4548

46-
sandboxTest('restart after code-interpreter kill', async ({ sandbox }) => {
47-
// Verify health is up initially
48-
const initialHealth = await waitForHealth(sandbox)
49-
expect(initialHealth).toBe(true)
49+
sandboxTest.skipIf(isDebug)(
50+
'restart after code-interpreter kill',
51+
async ({ sandbox }) => {
52+
// Verify health is up initially
53+
const initialHealth = await waitForHealth(sandbox)
54+
expect(initialHealth).toBe(true)
5055

51-
// Kill the code-interpreter process as root
52-
try {
53-
await sandbox.commands.run("kill -9 $(pgrep -f 'uvicorn main:app')", {
54-
user: 'root',
55-
})
56-
} catch {
57-
// Expected — killing code-interpreter may terminate the command handle
58-
}
56+
// Kill the code-interpreter process as root
57+
try {
58+
await sandbox.commands.run("kill -9 $(pgrep -f 'uvicorn main:app')", {
59+
user: 'root',
60+
})
61+
} catch {
62+
// Expected — killing code-interpreter may terminate the command handle
63+
}
5964

60-
// Wait for systemd to restart it and health to come back
61-
const recovered = await waitForHealth(sandbox, 60, 500)
62-
expect(recovered).toBe(true)
65+
// Wait for systemd to restart it and health to come back
66+
const recovered = await waitForHealth(sandbox, 60, 500)
67+
expect(recovered).toBe(true)
6368

64-
// Verify code execution works after recovery
65-
const result = await sandbox.runCode('x = 1; x')
66-
expect(result.text).toEqual('1')
67-
})
69+
// Verify code execution works after recovery
70+
const result = await sandbox.runCode('x = 1; x')
71+
expect(result.text).toEqual('1')
72+
}
73+
)

python/tests/async/test_async_reconnect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import pytest
2+
13
from e2b_code_interpreter.code_interpreter_async import AsyncSandbox
24

35

6+
@pytest.mark.skip_debug
47
async def test_reconnect(async_sandbox: AsyncSandbox):
58
sandbox_id = async_sandbox.sandbox_id
69

python/tests/async/test_async_systemd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
22

3+
import pytest
4+
35
from e2b_code_interpreter.code_interpreter_async import AsyncSandbox
46

57

@@ -17,6 +19,7 @@ async def wait_for_health(sandbox: AsyncSandbox, max_retries=10, interval_ms=100
1719
return False
1820

1921

22+
@pytest.mark.skip_debug
2023
async def test_restart_after_jupyter_kill(async_sandbox: AsyncSandbox):
2124
# Verify health is up initially
2225
assert await wait_for_health(async_sandbox)
@@ -39,6 +42,7 @@ async def test_restart_after_jupyter_kill(async_sandbox: AsyncSandbox):
3942
assert result.text == "1"
4043

4144

45+
@pytest.mark.skip_debug
4246
async def test_restart_after_code_interpreter_kill(async_sandbox: AsyncSandbox):
4347
# Verify health is up initially
4448
assert await wait_for_health(async_sandbox)

python/tests/sync/test_reconnect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import pytest
2+
13
from e2b_code_interpreter.code_interpreter_sync import Sandbox
24

35

6+
@pytest.mark.skip_debug
47
def test_reconnect(sandbox: Sandbox):
58
sandbox_id = sandbox.sandbox_id
69

python/tests/sync/test_systemd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import time
22

3+
import pytest
4+
35
from e2b_code_interpreter.code_interpreter_sync import Sandbox
46

57

@@ -17,6 +19,7 @@ def wait_for_health(sandbox: Sandbox, max_retries=10, interval_ms=100):
1719
return False
1820

1921

22+
@pytest.mark.skip_debug
2023
def test_restart_after_jupyter_kill(sandbox: Sandbox):
2124
# Verify health is up initially
2225
assert wait_for_health(sandbox)
@@ -37,6 +40,7 @@ def test_restart_after_jupyter_kill(sandbox: Sandbox):
3740
assert result.text == "1"
3841

3942

43+
@pytest.mark.skip_debug
4044
def test_restart_after_code_interpreter_kill(sandbox: Sandbox):
4145
# Verify health is up initially
4246
assert wait_for_health(sandbox)

template/template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def make_template(
144144
template = template.set_user("user").set_workdir("/home/user")
145145

146146
if is_docker:
147-
start_cmd = "sudo /root/.jupyter/start-up.sh"
147+
start_cmd = "sudo --preserve-env=E2B_LOCAL /root/.jupyter/start-up.sh"
148148
else:
149149
start_cmd = "sudo systemctl start jupyter"
150150

0 commit comments

Comments
 (0)