Skip to content

Commit

Permalink
Add retry block to host and stdin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Jan 17, 2025
1 parent 2c4508e commit 238887b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
23 changes: 23 additions & 0 deletions packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
})
12 changes: 10 additions & 2 deletions packages/js-sdk/tests/sandbox/host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -20,4 +28,4 @@ sandboxTest('ping server in sandbox', async ({ sandbox }) => {
console.error(e)
}
}
})
}, { timeout: 60000 })
17 changes: 10 additions & 7 deletions packages/python-sdk/tests/async/sandbox_async/test_host.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import httpx
import pytest
import asyncio

from time import sleep
import httpx

from e2b import AsyncSandbox

Expand All @@ -13,12 +12,16 @@ async def test_ping_server(async_sandbox: AsyncSandbox, debug):
)

try:
sleep(1)
host = async_sandbox.get_host(8000)

status_code = None
async 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 == 200
finally:
await cmd.kill()
11 changes: 8 additions & 3 deletions packages/python-sdk/tests/sync/sandbox_sync/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == 200
finally:
cmd.kill()

0 comments on commit 238887b

Please sign in to comment.