Skip to content

Commit 51b0d17

Browse files
committed
update /contexts method
1 parent 7306a5a commit 51b0d17

File tree

4 files changed

+9
-30
lines changed

4 files changed

+9
-30
lines changed

js/tests/contexts.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import { sandboxTest } from './setup'
55
sandboxTest('create context with no options', async ({ sandbox }) => {
66
const context = await sandbox.createCodeContext()
77

8-
// wait 1 second for the context to be created
9-
await new Promise((resolve) => setTimeout(resolve, 1000))
10-
118
const contexts = await sandbox.listCodeContexts()
129
const lastContext = contexts[contexts.length - 1]
1310

@@ -22,9 +19,6 @@ sandboxTest('create context with options', async ({ sandbox }) => {
2219
cwd: '/root',
2320
})
2421

25-
// wait 1 second for the context to be created
26-
await new Promise((resolve) => setTimeout(resolve, 1000))
27-
2822
const contexts = await sandbox.listCodeContexts()
2923
const lastContext = contexts[contexts.length - 1]
3024

python/tests/async/test_async_contexts.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
from e2b_code_interpreter.code_interpreter_async import AsyncSandbox
2-
import asyncio
32

43

54
async def test_create_context_with_no_options(async_sandbox: AsyncSandbox):
65
context = await async_sandbox.create_code_context()
76

8-
# wait 1 second for the context to be created
9-
await asyncio.sleep(1)
10-
117
contexts = await async_sandbox.list_code_contexts()
128
last_context = contexts[-1]
139

@@ -22,9 +18,6 @@ async def test_create_context_with_options(async_sandbox: AsyncSandbox):
2218
cwd="/root",
2319
)
2420

25-
# wait 1 second for the context to be created
26-
await asyncio.sleep(1)
27-
2821
contexts = await async_sandbox.list_code_contexts()
2922
last_context = contexts[-1]
3023

python/tests/sync/test_contexts.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
from e2b_code_interpreter.code_interpreter_sync import Sandbox
2-
import time
32

43

54
def test_create_context_with_no_options(sandbox: Sandbox):
65
context = sandbox.create_code_context()
76

8-
# wait 1 second for the context to be created
9-
time.sleep(1)
10-
117
contexts = sandbox.list_code_contexts()
128
last_context = contexts[-1]
139

@@ -22,9 +18,6 @@ def test_create_context_with_options(sandbox: Sandbox):
2218
cwd="/root",
2319
)
2420

25-
# wait 1 second for the context to be created
26-
time.sleep(1)
27-
2821
contexts = sandbox.list_code_contexts()
2922
last_context = contexts[-1]
3023

template/server/main.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
import httpx
44

5-
from typing import Dict, Union, Literal, Set
5+
from typing import Dict, Union, Literal, List
66

77
from contextlib import asynccontextmanager
88
from fastapi import FastAPI, Request
@@ -133,19 +133,18 @@ async def post_contexts(request: CreateContext) -> Context:
133133

134134

135135
@app.get("/contexts")
136-
async def get_contexts() -> Set[Context]:
136+
async def get_contexts() -> List[Context]:
137137
logger.info("Listing contexts")
138138

139-
context_ids = websockets.keys()
140-
141-
return set(
139+
return [
142140
Context(
143-
id=websockets[context_id].context_id,
144-
language=websockets[context_id].language,
145-
cwd=websockets[context_id].cwd,
141+
id=ws.context_id,
142+
language=ws.language,
143+
cwd=ws.cwd,
146144
)
147-
for context_id in context_ids
148-
)
145+
for key, ws in websockets.items()
146+
if key != "default"
147+
]
149148

150149

151150
@app.post("/contexts/{context_id}/restart")

0 commit comments

Comments
 (0)