From fd94afc5f07a2707d7ecc1cf51152ec1c4913160 Mon Sep 17 00:00:00 2001 From: 0div Date: Mon, 16 Dec 2024 12:08:26 -0800 Subject: [PATCH] remove base_01 template name and add http server test --- .../js-sdk/tests/sandbox/snapshot.test.ts | 24 ++++++++++++++++--- packages/js-sdk/tests/setup.ts | 2 +- packages/python-sdk/tests/conftest.py | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/snapshot.test.ts b/packages/js-sdk/tests/sandbox/snapshot.test.ts index 6dfc57be7..8c11c288b 100644 --- a/packages/js-sdk/tests/sandbox/snapshot.test.ts +++ b/packages/js-sdk/tests/sandbox/snapshot.test.ts @@ -72,10 +72,10 @@ sandboxTest.skipIf(isDebug)('pause and resume a sandbox with file', async ({ san assert.equal(readContent2, content) }) -sandboxTest.skipIf(isDebug)('pause and resume a sandbox long running process', async ({ sandbox }) => { +sandboxTest.skipIf(isDebug)('pause and resume a sandbox with long running process', async ({ sandbox }) => { const filename = 'test_long_running.txt' - sandbox.commands.run(`sleep 2 && echo "done" > /home/user/${filename}`) + sandbox.commands.run(`sleep 2 && echo "done" > /home/user/${filename}`, { background: true }) // the file should not exist before 2 seconds have elapsed const exists = await sandbox.files.exists(filename) @@ -95,4 +95,22 @@ sandboxTest.skipIf(isDebug)('pause and resume a sandbox long running process', a const readContent2 = await sandbox.files.read(filename) assert.equal(readContent2.trim(), 'done') }) - \ No newline at end of file + +sandboxTest.skipIf(isDebug)('pause and resume a sandbox with http server', async ({ sandbox }) => { + await sandbox.commands.run('python3 -m http.server 8000', { background: true }) + + let url = await sandbox.getHost(8000) + console.log(url) + const response1 = await fetch(`https://${url}`) + assert.equal(response1.status, 200) + + await sandbox.pause() + assert.isFalse(await sandbox.isRunning()) + + await Sandbox.resume(sandbox.sandboxId) + assert.isTrue(await sandbox.isRunning()) + + url = await sandbox.getHost(8000) + const response2 = await fetch(`https://${url}`) + assert.equal(response2.status, 200) +}) diff --git a/packages/js-sdk/tests/setup.ts b/packages/js-sdk/tests/setup.ts index d3ff8f067..b3f540706 100644 --- a/packages/js-sdk/tests/setup.ts +++ b/packages/js-sdk/tests/setup.ts @@ -1,7 +1,7 @@ import { Sandbox } from '../src' import { test as base } from 'vitest' -export const template = 'base_01' +export const template = 'base' interface SandboxFixture { sandbox: Sandbox diff --git a/packages/python-sdk/tests/conftest.py b/packages/python-sdk/tests/conftest.py index 2fa1d6a6a..d06e1dfa6 100644 --- a/packages/python-sdk/tests/conftest.py +++ b/packages/python-sdk/tests/conftest.py @@ -8,7 +8,7 @@ @pytest.fixture() def template(): - return "base_01" + return "base" @pytest.fixture()