-
Notifications
You must be signed in to change notification settings - Fork 489
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
Boilerplate for integration tests (within js-sdk) #519
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f4c4bbd
created boilerplate for integration tests within js-sdk
0div 4116313
rm integration test template work
0div d90fc02
add stress tests
0div 7dc89ac
boilerplate for integration test template build
0div 39dfd38
Merge branch 'create-integration-test-template-e2b-1361' into create-…
0div 3245acd
fix template build command to include npm start command and add nextj…
0div e84bf8d
improve nextjs stress test
0div c7ae716
Update packages/js-sdk/tests/setup.ts
0div a76ce3f
used create-next-app in template; remove old draft test
0div 5c4207b
Merge branch 'main' of https://github.com/e2b-dev/E2B into create-str…
0div File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { test } from 'vitest' | ||
|
||
import Sandbox from '../../src/index.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) | ||
for (let i = 0; i < view.length; i++) { | ||
view[i] = Math.floor(Math.random() * 256) | ||
} | ||
|
||
const integrationTestTemplate = 'integration-test-v1' | ||
const sanboxCount = 10 | ||
|
||
test.skipIf(!isIntegrationTest)( | ||
'stress test heavy file writes and reads', | ||
async () => { | ||
const promises: Array<Promise<string | void>> = [] | ||
for (let i = 0; i < sanboxCount; 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 requests to nextjs app', async ({}) => { | ||
const hostPromises: Array<Promise<string | void>> = [] | ||
|
||
for (let i = 0; i < sanboxCount; i++) { | ||
hostPromises.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) | ||
} | ||
}) | ||
} | ||
) | ||
) | ||
} | ||
|
||
await wait(10_000) | ||
const hosts = await Promise.all(hostPromises) | ||
|
||
const fetchPromises: Array<Promise<string | void>> = [] | ||
|
||
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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Integration test template | ||
|
||
# Build the template | ||
|
||
`$ e2b template build -c "cd /basic-nextjs-app/ && sudo npm run dev"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM e2bdev/code-interpreter:latest | ||
|
||
# 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do it only based on directory structure? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, I initially tried that, but the way vitest workspace works makes it impossible to exclude the integration tests when when running
pnpm test
, bc that just picks up everything — maybe i'm missing something tho!