Skip to content

Commit c6eeca7

Browse files
committed
updated tests
1 parent 325cebc commit c6eeca7

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

js/src/sandbox.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ export class Sandbox extends BaseSandbox {
398398
'Content-Type': 'application/json',
399399
...this.connectionConfig.headers,
400400
},
401+
keepalive: true,
402+
signal: this.connectionConfig.getSignal(
403+
this.connectionConfig.requestTimeoutMs
404+
),
401405
})
402406

403407
const error = await extractError(res)

js/tests/contexts.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,17 @@ sandboxTest('list contexts', async ({ sandbox }) => {
4747
sandboxTest('restart context', async ({ sandbox }) => {
4848
const context = await sandbox.createCodeContext()
4949

50+
// set a variable in the context
51+
await sandbox.runCode('x = 1', { context: context })
52+
53+
// restart the context
5054
await sandbox.restartCodeContext(context.id)
55+
56+
// check that the variable no longer exists
57+
const execution = await sandbox.runCode('x', { context: context })
58+
59+
// check for an NameError with message "name 'x' is not defined"
60+
expect(execution.error).toBeDefined()
61+
expect(execution.error?.name).toBe('NameError')
62+
expect(execution.error?.value).toBe("name 'x' is not defined")
5163
})

python/tests/async/test_async_contexts.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ async def test_remove_context(async_sandbox: AsyncSandbox):
3131

3232
await async_sandbox.remove_code_context(context.id)
3333

34+
contexts = await async_sandbox.list_code_contexts()
35+
assert context.id not in [ctx.id for ctx in contexts]
36+
3437

3538
async def test_list_contexts(async_sandbox: AsyncSandbox):
3639
contexts = await async_sandbox.list_code_contexts()
@@ -44,4 +47,16 @@ async def test_list_contexts(async_sandbox: AsyncSandbox):
4447
async def test_restart_context(async_sandbox: AsyncSandbox):
4548
context = await async_sandbox.create_code_context()
4649

50+
# set a variable in the context
51+
await async_sandbox.run_code("x = 1", context=context)
52+
53+
# restart the context
4754
await async_sandbox.restart_code_context(context.id)
55+
56+
# check that the variable no longer exists
57+
execution = await async_sandbox.run_code("x", context=context)
58+
59+
# check for a NameError with message "name 'x' is not defined"
60+
assert execution.error is not None
61+
assert execution.error.name == "NameError"
62+
assert execution.error.value == "name 'x' is not defined"

python/tests/sync/test_contexts.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def test_remove_context(sandbox: Sandbox):
3131

3232
sandbox.remove_code_context(context.id)
3333

34+
contexts = sandbox.list_code_contexts()
35+
assert context.id not in [ctx.id for ctx in contexts]
36+
3437

3538
def test_list_contexts(sandbox: Sandbox):
3639
contexts = sandbox.list_code_contexts()
@@ -44,4 +47,16 @@ def test_list_contexts(sandbox: Sandbox):
4447
def test_restart_context(sandbox: Sandbox):
4548
context = sandbox.create_code_context()
4649

50+
# set a variable in the context
51+
sandbox.run_code("x = 1", context=context)
52+
53+
# restart the context
4754
sandbox.restart_code_context(context.id)
55+
56+
# check that the variable no longer exists
57+
execution = sandbox.run_code("x", context=context)
58+
59+
# check for a NameError with message "name 'x' is not defined"
60+
assert execution.error is not None
61+
assert execution.error.name == "NameError"
62+
assert execution.error.value == "name 'x' is not defined"

0 commit comments

Comments
 (0)