From f4c4bbde6a84d0f5fa485d17e3ac720a9975fef8 Mon Sep 17 00:00:00 2001 From: 0div Date: Mon, 23 Dec 2024 17:38:04 +0100 Subject: [PATCH 1/8] created boilerplate for integration tests within js-sdk --- packages/js-sdk/package.json | 3 +- .../js-sdk/tests/integration/stress.test.ts | 73 +++++++++++++++++++ .../tests/integration/template/README.md | 5 ++ .../tests/integration/template/e2b.Dockerfile | 8 ++ .../tests/integration/template/e2b.toml | 18 +++++ packages/js-sdk/tests/setup.ts | 3 +- packages/js-sdk/vitest.workspace.mts | 35 +++++---- 7 files changed, 127 insertions(+), 18 deletions(-) create mode 100644 packages/js-sdk/tests/integration/stress.test.ts create mode 100644 packages/js-sdk/tests/integration/template/README.md create mode 100644 packages/js-sdk/tests/integration/template/e2b.Dockerfile create mode 100644 packages/js-sdk/tests/integration/template/e2b.toml diff --git a/packages/js-sdk/package.json b/packages/js-sdk/package.json index d57b08e15..ad2fdc50e 100644 --- a/packages/js-sdk/package.json +++ b/packages/js-sdk/package.json @@ -35,7 +35,8 @@ "update-deps": "ncu -u && pnpm i", "postPublish": "./scripts/post-publish.sh || true", "test:bun": "bun test tests/runtimes/bun --env-file=.env", - "test:deno": "deno test tests/runtimes/deno/ --allow-net --allow-read --allow-env --unstable-sloppy-imports --trace-leaks" + "test:deno": "deno test tests/runtimes/deno/ --allow-net --allow-read --allow-env --unstable-sloppy-imports --trace-leaks", + "test:integration": "E2B_INTEGRATION_TEST=1 vitest run tests/integration/**" }, "devDependencies": { "@testing-library/react": "^16.0.1", diff --git a/packages/js-sdk/tests/integration/stress.test.ts b/packages/js-sdk/tests/integration/stress.test.ts new file mode 100644 index 000000000..b82830372 --- /dev/null +++ b/packages/js-sdk/tests/integration/stress.test.ts @@ -0,0 +1,73 @@ +import { test } from 'vitest' + +import Sandbox from '../../src/index.js' +import { wait, isIntegrationTest } from '../setup.js' + +const heavyArray = new ArrayBuffer(256 * 1024 * 1024) // 256 MiB = 256 * 1024 * 1024 bytes +const view = new Uint8Array(heavyArray) +for (let i = 0; i < view.length; i++) { + view[i] = Math.floor(Math.random() * 256) +} + +const integrationTestTemplate = 'jonas_base' + +test.skipIf(!isIntegrationTest)( + 'stress test heavy file writes and reads', + async () => { + const promises: Array> = [] + for (let i = 0; i < 500; i++) { + promises.push( + Sandbox.create(integrationTestTemplate, { timeoutMs: 60 }) + .then((sbx) => { + console.log(sbx.sandboxId) + return sbx.files + .write('heavy-file', heavyArray) + .then(() => sbx.files.read('heavy-file')) + }) + .catch(console.error) + ) + } + await wait(10_000) + await Promise.all(promises) + } +) + +test.skipIf(!isIntegrationTest)('stress network ingress', async ({}) => { + const promises: Array> = [] + + for (let i = 0; i < 10; i++) { + promises.push( + Sandbox.create(integrationTestTemplate, { timeoutMs: 60 }).then((sbx) => { + console.log('created sandbox', sbx.sandboxId) + sbx.files + .write('heavy-file', heavyArray) + .then(() => { + sbx.commands.run('python -m http.server 8000', { background: true }) + }) + .then(() => { + new Promise((resolve, reject) => { + try { + resolve(sbx.getHost(8000)) + } catch (e) { + console.error('error getting sbx host', e) + reject(e) + } + }).then((host) => { + const url = `https://${host}` + console.log('fetching url', url) + fetch(url) + }) + + try { + sbx.kill() + } catch (e) { + console.error('error killing sbx', e) + } + }) + }) + ) + } + + await wait(10_000) + await Promise.all(promises) +}) diff --git a/packages/js-sdk/tests/integration/template/README.md b/packages/js-sdk/tests/integration/template/README.md new file mode 100644 index 000000000..2d4155dc3 --- /dev/null +++ b/packages/js-sdk/tests/integration/template/README.md @@ -0,0 +1,5 @@ +# Integration test template + +# Build the template + +`$ e2b template build"` diff --git a/packages/js-sdk/tests/integration/template/e2b.Dockerfile b/packages/js-sdk/tests/integration/template/e2b.Dockerfile new file mode 100644 index 000000000..65ceb7d65 --- /dev/null +++ b/packages/js-sdk/tests/integration/template/e2b.Dockerfile @@ -0,0 +1,8 @@ +FROM e2bdev/code-interpreter:latest + +# Clone the Next.js app repository +RUN git clone https://github.com/ezesundayeze/basic-nextjs-app + +# Install dependencies +RUN cd basic-nextjs-app && npm install + diff --git a/packages/js-sdk/tests/integration/template/e2b.toml b/packages/js-sdk/tests/integration/template/e2b.toml new file mode 100644 index 000000000..4f6dff736 --- /dev/null +++ b/packages/js-sdk/tests/integration/template/e2b.toml @@ -0,0 +1,18 @@ +# This is a config for E2B sandbox template. +# You can use template ID (2e2z80zhv34yumbrybvn) or template name (integration-test-v1) to create a sandbox: + +# Python SDK +# from e2b import Sandbox, AsyncSandbox +# sandbox = Sandbox("integration-test-v1") # Sync sandbox +# sandbox = await AsyncSandbox.create("integration-test-v1") # Async sandbox + +# JS SDK +# import { Sandbox } from 'e2b' +# const sandbox = await Sandbox.create('integration-test-v1') + +team_id = "b9c07023-d095-4bdc-9634-e25d5530ba47" +memory_mb = 1_024 +start_cmd = "npm run dev" +dockerfile = "e2b.Dockerfile" +template_name = "integration-test-v1" +template_id = "2e2z80zhv34yumbrybvn" diff --git a/packages/js-sdk/tests/setup.ts b/packages/js-sdk/tests/setup.ts index 7cdbd5e0c..30889c60f 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' +export const template = 'jonas_base' interface SandboxFixture { sandbox: Sandbox @@ -30,6 +30,7 @@ export const sandboxTest = base.extend({ }) export const isDebug = process.env.E2B_DEBUG !== undefined +export const isIntegrationTest = process.env.E2B_INTEGRATION_TEST !== undefined export async function wait(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)) diff --git a/packages/js-sdk/vitest.workspace.mts b/packages/js-sdk/vitest.workspace.mts index 8ce2118f6..38006cd44 100644 --- a/packages/js-sdk/vitest.workspace.mts +++ b/packages/js-sdk/vitest.workspace.mts @@ -5,20 +5,11 @@ const env = config() export default defineWorkspace([ { test: { - include: [ - 'tests/**/*.test.ts', - ], - exclude: [ - 'tests/runtimes/**', - ], - poolOptions: { - threads: { - minThreads: 1, - maxThreads: 4, - }, - }, + include: ['tests/**/*.test.ts'], + exclude: ['tests/runtimes/**', 'tests/integration/**'], + isolate: false, // for projects that don't rely on side effects, disabling isolation will improve the speed of the tests globals: false, - testTimeout: 30000, + testTimeout: 30_000, environment: 'node', bail: 1, server: {}, @@ -26,7 +17,7 @@ export default defineWorkspace([ interopDefault: true, }, env: { - ...process.env as Record, + ...(process.env as Record), ...env.parsed, }, }, @@ -43,8 +34,8 @@ export default defineWorkspace([ providerOptions: {}, }, env: { - ...process.env as Record, - ...env.parsed, + ...(process.env as Record), + ...env.parsed, }, }, }, @@ -55,4 +46,16 @@ export default defineWorkspace([ environment: 'edge-runtime', }, }, + { + test: { + include: ['tests/integration/**/*.test.ts'], + globals: false, + testTimeout: 60_000, + environment: 'node', + env: { + ...(process.env as Record), + ...env.parsed, + }, + }, + }, ]) From 411631385d742cedbb7e3d9ef6fdb188e3baf82f Mon Sep 17 00:00:00 2001 From: 0div Date: Mon, 23 Dec 2024 17:42:39 +0100 Subject: [PATCH 2/8] rm integration test template work --- .../js-sdk/tests/integration/stress.test.ts | 73 ------------------- .../tests/integration/template/README.md | 5 -- .../tests/integration/template/e2b.Dockerfile | 8 -- .../tests/integration/template/e2b.toml | 18 ----- 4 files changed, 104 deletions(-) delete mode 100644 packages/js-sdk/tests/integration/stress.test.ts delete mode 100644 packages/js-sdk/tests/integration/template/README.md delete mode 100644 packages/js-sdk/tests/integration/template/e2b.Dockerfile delete mode 100644 packages/js-sdk/tests/integration/template/e2b.toml diff --git a/packages/js-sdk/tests/integration/stress.test.ts b/packages/js-sdk/tests/integration/stress.test.ts deleted file mode 100644 index b82830372..000000000 --- a/packages/js-sdk/tests/integration/stress.test.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { test } from 'vitest' - -import Sandbox from '../../src/index.js' -import { wait, isIntegrationTest } from '../setup.js' - -const heavyArray = new ArrayBuffer(256 * 1024 * 1024) // 256 MiB = 256 * 1024 * 1024 bytes -const view = new Uint8Array(heavyArray) -for (let i = 0; i < view.length; i++) { - view[i] = Math.floor(Math.random() * 256) -} - -const integrationTestTemplate = 'jonas_base' - -test.skipIf(!isIntegrationTest)( - 'stress test heavy file writes and reads', - async () => { - const promises: Array> = [] - for (let i = 0; i < 500; i++) { - promises.push( - Sandbox.create(integrationTestTemplate, { timeoutMs: 60 }) - .then((sbx) => { - console.log(sbx.sandboxId) - return sbx.files - .write('heavy-file', heavyArray) - .then(() => sbx.files.read('heavy-file')) - }) - .catch(console.error) - ) - } - await wait(10_000) - await Promise.all(promises) - } -) - -test.skipIf(!isIntegrationTest)('stress network ingress', async ({}) => { - const promises: Array> = [] - - for (let i = 0; i < 10; i++) { - promises.push( - Sandbox.create(integrationTestTemplate, { timeoutMs: 60 }).then((sbx) => { - console.log('created sandbox', sbx.sandboxId) - sbx.files - .write('heavy-file', heavyArray) - .then(() => { - sbx.commands.run('python -m http.server 8000', { background: true }) - }) - .then(() => { - new Promise((resolve, reject) => { - try { - resolve(sbx.getHost(8000)) - } catch (e) { - console.error('error getting sbx host', e) - reject(e) - } - }).then((host) => { - const url = `https://${host}` - console.log('fetching url', url) - fetch(url) - }) - - try { - sbx.kill() - } catch (e) { - console.error('error killing sbx', e) - } - }) - }) - ) - } - - await wait(10_000) - await Promise.all(promises) -}) diff --git a/packages/js-sdk/tests/integration/template/README.md b/packages/js-sdk/tests/integration/template/README.md deleted file mode 100644 index 2d4155dc3..000000000 --- a/packages/js-sdk/tests/integration/template/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Integration test template - -# Build the template - -`$ e2b template build"` diff --git a/packages/js-sdk/tests/integration/template/e2b.Dockerfile b/packages/js-sdk/tests/integration/template/e2b.Dockerfile deleted file mode 100644 index 65ceb7d65..000000000 --- a/packages/js-sdk/tests/integration/template/e2b.Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM e2bdev/code-interpreter:latest - -# Clone the Next.js app repository -RUN git clone https://github.com/ezesundayeze/basic-nextjs-app - -# Install dependencies -RUN cd basic-nextjs-app && npm install - diff --git a/packages/js-sdk/tests/integration/template/e2b.toml b/packages/js-sdk/tests/integration/template/e2b.toml deleted file mode 100644 index 4f6dff736..000000000 --- a/packages/js-sdk/tests/integration/template/e2b.toml +++ /dev/null @@ -1,18 +0,0 @@ -# This is a config for E2B sandbox template. -# You can use template ID (2e2z80zhv34yumbrybvn) or template name (integration-test-v1) to create a sandbox: - -# Python SDK -# from e2b import Sandbox, AsyncSandbox -# sandbox = Sandbox("integration-test-v1") # Sync sandbox -# sandbox = await AsyncSandbox.create("integration-test-v1") # Async sandbox - -# JS SDK -# import { Sandbox } from 'e2b' -# const sandbox = await Sandbox.create('integration-test-v1') - -team_id = "b9c07023-d095-4bdc-9634-e25d5530ba47" -memory_mb = 1_024 -start_cmd = "npm run dev" -dockerfile = "e2b.Dockerfile" -template_name = "integration-test-v1" -template_id = "2e2z80zhv34yumbrybvn" From d90fc02ed1586b5ffba4bcc7113442b37cf952e8 Mon Sep 17 00:00:00 2001 From: 0div Date: Mon, 23 Dec 2024 17:43:24 +0100 Subject: [PATCH 3/8] add stress tests --- .../js-sdk/tests/integration/stress.test.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 packages/js-sdk/tests/integration/stress.test.ts diff --git a/packages/js-sdk/tests/integration/stress.test.ts b/packages/js-sdk/tests/integration/stress.test.ts new file mode 100644 index 000000000..b82830372 --- /dev/null +++ b/packages/js-sdk/tests/integration/stress.test.ts @@ -0,0 +1,73 @@ +import { test } from 'vitest' + +import Sandbox from '../../src/index.js' +import { wait, isIntegrationTest } from '../setup.js' + +const heavyArray = new ArrayBuffer(256 * 1024 * 1024) // 256 MiB = 256 * 1024 * 1024 bytes +const view = new Uint8Array(heavyArray) +for (let i = 0; i < view.length; i++) { + view[i] = Math.floor(Math.random() * 256) +} + +const integrationTestTemplate = 'jonas_base' + +test.skipIf(!isIntegrationTest)( + 'stress test heavy file writes and reads', + async () => { + const promises: Array> = [] + for (let i = 0; i < 500; i++) { + promises.push( + Sandbox.create(integrationTestTemplate, { timeoutMs: 60 }) + .then((sbx) => { + console.log(sbx.sandboxId) + return sbx.files + .write('heavy-file', heavyArray) + .then(() => sbx.files.read('heavy-file')) + }) + .catch(console.error) + ) + } + await wait(10_000) + await Promise.all(promises) + } +) + +test.skipIf(!isIntegrationTest)('stress network ingress', async ({}) => { + const promises: Array> = [] + + for (let i = 0; i < 10; i++) { + promises.push( + Sandbox.create(integrationTestTemplate, { timeoutMs: 60 }).then((sbx) => { + console.log('created sandbox', sbx.sandboxId) + sbx.files + .write('heavy-file', heavyArray) + .then(() => { + sbx.commands.run('python -m http.server 8000', { background: true }) + }) + .then(() => { + new Promise((resolve, reject) => { + try { + resolve(sbx.getHost(8000)) + } catch (e) { + console.error('error getting sbx host', e) + reject(e) + } + }).then((host) => { + const url = `https://${host}` + console.log('fetching url', url) + fetch(url) + }) + + try { + sbx.kill() + } catch (e) { + console.error('error killing sbx', e) + } + }) + }) + ) + } + + await wait(10_000) + await Promise.all(promises) +}) From 7dc89ac7368309e1db40dce1726307eca8458c9e Mon Sep 17 00:00:00 2001 From: 0div Date: Mon, 23 Dec 2024 17:56:19 +0100 Subject: [PATCH 4/8] boilerplate for integration test template build --- .../tests/integration/template/e2b.Dockerfile | 8 ++++++++ .../js-sdk/tests/integration/template/e2b.toml | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 packages/js-sdk/tests/integration/template/e2b.Dockerfile create mode 100644 packages/js-sdk/tests/integration/template/e2b.toml diff --git a/packages/js-sdk/tests/integration/template/e2b.Dockerfile b/packages/js-sdk/tests/integration/template/e2b.Dockerfile new file mode 100644 index 000000000..65ceb7d65 --- /dev/null +++ b/packages/js-sdk/tests/integration/template/e2b.Dockerfile @@ -0,0 +1,8 @@ +FROM e2bdev/code-interpreter:latest + +# Clone the Next.js app repository +RUN git clone https://github.com/ezesundayeze/basic-nextjs-app + +# Install dependencies +RUN cd basic-nextjs-app && npm install + diff --git a/packages/js-sdk/tests/integration/template/e2b.toml b/packages/js-sdk/tests/integration/template/e2b.toml new file mode 100644 index 000000000..4f6dff736 --- /dev/null +++ b/packages/js-sdk/tests/integration/template/e2b.toml @@ -0,0 +1,18 @@ +# This is a config for E2B sandbox template. +# You can use template ID (2e2z80zhv34yumbrybvn) or template name (integration-test-v1) to create a sandbox: + +# Python SDK +# from e2b import Sandbox, AsyncSandbox +# sandbox = Sandbox("integration-test-v1") # Sync sandbox +# sandbox = await AsyncSandbox.create("integration-test-v1") # Async sandbox + +# JS SDK +# import { Sandbox } from 'e2b' +# const sandbox = await Sandbox.create('integration-test-v1') + +team_id = "b9c07023-d095-4bdc-9634-e25d5530ba47" +memory_mb = 1_024 +start_cmd = "npm run dev" +dockerfile = "e2b.Dockerfile" +template_name = "integration-test-v1" +template_id = "2e2z80zhv34yumbrybvn" From 3245acd4d9829763e739c9ee7c6a34c1fcdfce2f Mon Sep 17 00:00:00 2001 From: 0div Date: Thu, 26 Dec 2024 11:27:24 +0100 Subject: [PATCH 5/8] fix template build command to include npm start command and add nextjs stress test to integration suite --- .../js-sdk/tests/integration/stress.test.ts | 41 +++++++++++++++++-- .../tests/integration/template/README.md | 5 +++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 packages/js-sdk/tests/integration/template/README.md diff --git a/packages/js-sdk/tests/integration/stress.test.ts b/packages/js-sdk/tests/integration/stress.test.ts index b82830372..c880dcbb2 100644 --- a/packages/js-sdk/tests/integration/stress.test.ts +++ b/packages/js-sdk/tests/integration/stress.test.ts @@ -9,13 +9,14 @@ for (let i = 0; i < view.length; i++) { view[i] = Math.floor(Math.random() * 256) } -const integrationTestTemplate = 'jonas_base' +const integrationTestTemplate = 'integration-test-v1' +const sanboxCount = 10 test.skipIf(!isIntegrationTest)( 'stress test heavy file writes and reads', async () => { const promises: Array> = [] - for (let i = 0; i < 500; i++) { + for (let i = 0; i < sanboxCount; i++) { promises.push( Sandbox.create(integrationTestTemplate, { timeoutMs: 60 }) .then((sbx) => { @@ -35,7 +36,7 @@ test.skipIf(!isIntegrationTest)( test.skipIf(!isIntegrationTest)('stress network ingress', async ({}) => { const promises: Array> = [] - for (let i = 0; i < 10; i++) { + for (let i = 0; i < sanboxCount; i++) { promises.push( Sandbox.create(integrationTestTemplate, { timeoutMs: 60 }).then((sbx) => { console.log('created sandbox', sbx.sandboxId) @@ -71,3 +72,37 @@ test.skipIf(!isIntegrationTest)('stress network ingress', async ({}) => { await wait(10_000) await Promise.all(promises) }) + +test.skipIf(!isIntegrationTest)('stress requests to nextjs app', async ({}) => { + const promises: Array> = [] + + for (let i = 0; i < sanboxCount; i++) { + promises.push( + Sandbox.create(integrationTestTemplate, { timeoutMs: 60_000 }) + .then((sbx) => { + console.log('created sandbox', sbx.sandboxId) + return new Promise((resolve, reject) => { + try { + resolve(sbx.getHost(3000)) + } catch (e) { + console.error('error getting sbx host', e) + reject(e) + } + }).then(async (host) => { + const url = `https://${host}` + console.log('fetching url', url) + await fetch(url).then(async (res) => { + console.log('response', res.status) + await res.text().then((text) => { + console.log('response body', text) + }) + }) + }) + }) + .catch(console.error) + ) + } + + await wait(10_000) + await Promise.all(promises) +}) diff --git a/packages/js-sdk/tests/integration/template/README.md b/packages/js-sdk/tests/integration/template/README.md new file mode 100644 index 000000000..7da9296a3 --- /dev/null +++ b/packages/js-sdk/tests/integration/template/README.md @@ -0,0 +1,5 @@ +# Integration test template + +# Build the template + +`$ e2b template build -c "cd /basic-nextjs-app/ && sudo npm run dev"` From e84bf8d0b4f431a3e03dd1da95bd87dd7edb2649 Mon Sep 17 00:00:00 2001 From: 0div Date: Thu, 26 Dec 2024 12:06:13 +0100 Subject: [PATCH 6/8] improve nextjs stress test --- .../js-sdk/tests/integration/stress.test.ts | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/packages/js-sdk/tests/integration/stress.test.ts b/packages/js-sdk/tests/integration/stress.test.ts index c880dcbb2..7f2e3bd78 100644 --- a/packages/js-sdk/tests/integration/stress.test.ts +++ b/packages/js-sdk/tests/integration/stress.test.ts @@ -74,12 +74,12 @@ test.skipIf(!isIntegrationTest)('stress network ingress', async ({}) => { }) test.skipIf(!isIntegrationTest)('stress requests to nextjs app', async ({}) => { - const promises: Array> = [] + const hostPromises: Array> = [] for (let i = 0; i < sanboxCount; i++) { - promises.push( - Sandbox.create(integrationTestTemplate, { timeoutMs: 60_000 }) - .then((sbx) => { + hostPromises.push( + Sandbox.create(integrationTestTemplate, { timeoutMs: 60_000 }).then( + (sbx) => { console.log('created sandbox', sbx.sandboxId) return new Promise((resolve, reject) => { try { @@ -88,21 +88,30 @@ test.skipIf(!isIntegrationTest)('stress requests to nextjs app', async ({}) => { console.error('error getting sbx host', e) reject(e) } - }).then(async (host) => { - const url = `https://${host}` - console.log('fetching url', url) - await fetch(url).then(async (res) => { - console.log('response', res.status) - await res.text().then((text) => { - console.log('response body', text) - }) - }) }) - }) - .catch(console.error) + } + ) ) } await wait(10_000) - await Promise.all(promises) + const hosts = await Promise.all(hostPromises) + + const fetchPromises: Array> = [] + + for (let i = 0; i < 100; i++) { + for (const host of hosts) { + fetchPromises.push( + new Promise((resolve) => { + fetch('https://' + host) + .then((res) => { + console.log(`response for ${host}: ${res.status}`) + }) + .then(resolve) + }) + ) + } + } + + await Promise.all(fetchPromises) }) From c7ae7161fd7b86b4da77c2027ec2df9d989bd00b Mon Sep 17 00:00:00 2001 From: 0div <98087403+0div@users.noreply.github.com> Date: Fri, 17 Jan 2025 04:45:17 +0100 Subject: [PATCH 7/8] Update packages/js-sdk/tests/setup.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Novák --- packages/js-sdk/tests/setup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js-sdk/tests/setup.ts b/packages/js-sdk/tests/setup.ts index 30889c60f..5e5955f7f 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 = 'jonas_base' +export const template = 'base' interface SandboxFixture { sandbox: Sandbox From a76ce3f6f23e4b660704d02ff50c76136634445c Mon Sep 17 00:00:00 2001 From: 0div Date: Thu, 16 Jan 2025 20:16:42 -0800 Subject: [PATCH 8/8] used create-next-app in template; remove old draft test --- .../js-sdk/tests/integration/stress.test.ts | 42 +------------------ .../tests/integration/template/e2b.Dockerfile | 4 +- 2 files changed, 3 insertions(+), 43 deletions(-) diff --git a/packages/js-sdk/tests/integration/stress.test.ts b/packages/js-sdk/tests/integration/stress.test.ts index 7f2e3bd78..69da1472d 100644 --- a/packages/js-sdk/tests/integration/stress.test.ts +++ b/packages/js-sdk/tests/integration/stress.test.ts @@ -1,7 +1,7 @@ import { test } from 'vitest' import Sandbox from '../../src/index.js' -import { wait, isIntegrationTest } from '../setup.js' +import { isIntegrationTest, wait } from '../setup.js' const heavyArray = new ArrayBuffer(256 * 1024 * 1024) // 256 MiB = 256 * 1024 * 1024 bytes const view = new Uint8Array(heavyArray) @@ -33,46 +33,6 @@ test.skipIf(!isIntegrationTest)( } ) -test.skipIf(!isIntegrationTest)('stress network ingress', async ({}) => { - const promises: Array> = [] - - for (let i = 0; i < sanboxCount; i++) { - promises.push( - Sandbox.create(integrationTestTemplate, { timeoutMs: 60 }).then((sbx) => { - console.log('created sandbox', sbx.sandboxId) - sbx.files - .write('heavy-file', heavyArray) - .then(() => { - sbx.commands.run('python -m http.server 8000', { background: true }) - }) - .then(() => { - new Promise((resolve, reject) => { - try { - resolve(sbx.getHost(8000)) - } catch (e) { - console.error('error getting sbx host', e) - reject(e) - } - }).then((host) => { - const url = `https://${host}` - console.log('fetching url', url) - fetch(url) - }) - - try { - sbx.kill() - } catch (e) { - console.error('error killing sbx', e) - } - }) - }) - ) - } - - await wait(10_000) - await Promise.all(promises) -}) - test.skipIf(!isIntegrationTest)('stress requests to nextjs app', async ({}) => { const hostPromises: Array> = [] diff --git a/packages/js-sdk/tests/integration/template/e2b.Dockerfile b/packages/js-sdk/tests/integration/template/e2b.Dockerfile index 65ceb7d65..2284ca7d3 100644 --- a/packages/js-sdk/tests/integration/template/e2b.Dockerfile +++ b/packages/js-sdk/tests/integration/template/e2b.Dockerfile @@ -1,7 +1,7 @@ FROM e2bdev/code-interpreter:latest -# Clone the Next.js app repository -RUN git clone https://github.com/ezesundayeze/basic-nextjs-app +# Create a basic Next.js app +RUN npx -y create-next-app@latest test --yes --ts --use-npm # Install dependencies RUN cd basic-nextjs-app && npm install