Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add retry block to host and stdin tests
Jakub Novak238887b03dff
diff --git a/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts b/packages/js-sdk/tests/sandbox/commands/sendStdin.test.tsindex 550c04a15..56bcd025a 100644--- a/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts+++ b/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts@@ -7,6 +7,14 @@ sandboxTest('send stdin to process', async ({ sandbox }) => {await sandbox.commands.sendStdin(cmd.pid, text)++ for (let i = 0; i < 5; i++) {+ if (cmd.stdout === text) {+ break+ }+ await new Promise((r) => setTimeout(r, 500))+ }+await cmd.kill()assert.equal(cmd.stdout, text)@@ -29,6 +37,13 @@ sandboxTest('send special characters to stdin', async ({ sandbox }) => {await sandbox.commands.sendStdin(cmd.pid, text)+ for (let i = 0; i < 5; i++) {+ if (cmd.stdout === text) {+ break+ }+ await new Promise((r) => setTimeout(r, 500))+ }+await cmd.kill()assert.equal(cmd.stdout, text)@@ -40,7 +55,15 @@ sandboxTest('send multiline string to stdin', async ({ sandbox }) => {await sandbox.commands.sendStdin(cmd.pid, text)+ for (let i = 0; i < 5; i++) {+ if (cmd.stdout === text) {+ break+ }+ await new Promise((r) => setTimeout(r, 500))+ }+await cmd.kill()+assert.equal(cmd.stdout, text)})diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.tsindex f499f7d3e..b0a176362 100644--- a/packages/js-sdk/tests/sandbox/host.test.ts+++ b/packages/js-sdk/tests/sandbox/host.test.ts@@ -10,8 +10,16 @@ sandboxTest('ping server in sandbox', async ({ sandbox }) => {const host = sandbox.getHost(8000)- const res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)+ let res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)+ for (let i = 0; i < 10; i++) {+ if (res.status === 200) {+ break+ }++ res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)+ await wait(500)+ }assert.equal(res.status, 200)} finally {try {@@ -20,4 +28,4 @@ sandboxTest('ping server in sandbox', async ({ sandbox }) => {console.error(e)}}-})+}, { timeout: 60000 })diff --git a/packages/python-sdk/tests/async/sandbox_async/test_host.py b/packages/python-sdk/tests/async/sandbox_async/test_host.pyindex a8bd3c74c..6637029af 100644--- a/packages/python-sdk/tests/async/sandbox_async/test_host.py+++ b/packages/python-sdk/tests/async/sandbox_async/test_host.py@@ -1,7 +1,6 @@-import httpx-import pytest+import asyncio-from time import sleep+import httpxfrom e2b import AsyncSandbox@@ -13,12 +12,16 @@ async def test_ping_server(async_sandbox: AsyncSandbox, debug):)try:- sleep(1)host = async_sandbox.get_host(8000)+ status_code = Noneasync with httpx.AsyncClient() as client:- res = await client.get(f"{'http' if debug else 'https'}://{host}")- assert res.status_code == 200-+ for _ in range(5):+ res = await client.get(f"{'http' if debug else 'https'}://{host}")+ status_code = res.status_code+ if res.status_code == 200:+ break+ await asyncio.sleep(0.5)+ assert status_code == 200finally:await cmd.kill()diff --git a/packages/python-sdk/tests/sync/sandbox_sync/test_host.py b/packages/python-sdk/tests/sync/sandbox_sync/test_host.pyindex 18de6d5c1..461b98b62 100644--- a/packages/python-sdk/tests/sync/sandbox_sync/test_host.py+++ b/packages/python-sdk/tests/sync/sandbox_sync/test_host.py@@ -7,10 +7,15 @@ def test_ping_server(sandbox, debug):cmd = sandbox.commands.run("python -m http.server 8001", background=True)try:- sleep(1)host = sandbox.get_host(8001)- res = httpx.get(f"{'http' if debug else 'https'}://{host}")- assert res.status_code == 200+ status_code = None+ for _ in range(5):+ res = httpx.get(f"{'http' if debug else 'https'}://{host}")+ status_code = res.status_code+ if res.status_code == 200:+ break+ sleep(0.5)+ assert status_code == 200finally:cmd.kill()