Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test new error handling indicating when the sandbox is not found #540

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
43 changes: 39 additions & 4 deletions packages/js-sdk/tests/sandbox/host.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { assert } from 'vitest'

import { isDebug, sandboxTest, wait } from '../setup.js'
import Sandbox from '../../src/index.js'
import { isDebug, sandboxTest, template, wait } from '../setup.js'

sandboxTest('ping server in sandbox', async ({ sandbox }) => {
const cmd = await sandbox.commands.run('python -m http.server 8000', { background: true })
sandboxTest('ping server in running sandbox', async ({ sandbox }) => {
const cmd = await sandbox.commands.run('python -m http.server 8000', {
background: true,
})

try {
await wait(1000)
await wait(10_000)

const host = sandbox.getHost(8000)

Expand All @@ -21,3 +24,35 @@ sandboxTest('ping server in sandbox', async ({ sandbox }) => {
}
}
})

sandboxTest('ping server in non-running sandbox', async () => {
const sbx = await Sandbox.create(template, { timeoutMs: 60_000 })
0div marked this conversation as resolved.
Show resolved Hide resolved

const cmd = await sbx.commands.run('python -m http.server 8000', {
background: true,
})

try {
await wait(10_000)

const host = sbx.getHost(8000)

const res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)

assert.equal(res.status, 200)

await sbx.kill()

const res2 = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)
0div marked this conversation as resolved.
Show resolved Hide resolved
assert.equal(res2.status, 502)

const text = await res2.text()
assert.equal(text, 'Sandbox does not exist.')
} finally {
try {
await cmd.kill()
} catch (e) {
console.error(e)
}
}
})
Loading