Skip to content

Commit

Permalink
edits based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
0div committed Jan 17, 2025
1 parent ad3d8fb commit a9c283e
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions packages/js-sdk/tests/sandbox/host.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assert } from 'vitest'

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

sandboxTest.skipIf(isDebug)(
'ping server in running sandbox',
Expand All @@ -28,34 +27,35 @@ sandboxTest.skipIf(isDebug)(
}
)

sandboxTest.skipIf(isDebug)('ping server in non-running sandbox', async () => {
const sbx = await Sandbox.create(template, { timeoutMs: 120_000 })

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

try {
await wait(20_000)
try {
await wait(20_000)

const host = sbx.getHost(8000)
const host = sandbox.getHost(8000)

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

assert.equal(res.status, 200)
assert.equal(res.status, 200)

await sbx.kill()
await sandbox.kill()

const res2 = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)
assert.equal(res2.status, 502)
const res2 = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)
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)
const text = await res2.text()
assert.equal(text, 'Sandbox does not exist.')
} finally {
try {
await cmd.kill()
} catch (e) {
console.error(e)
}
}
}
})
)

0 comments on commit a9c283e

Please sign in to comment.