Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

test(js-sdk): keep sending wake requests in the auto-resume test (#1865)

devin-ai-integration[bot]1cd5cb841726
diff --git a/packages/js-sdk/tests/sandbox/lifecyclePayload.test.ts b/packages/js-sdk/tests/sandbox/lifecyclePayload.test.ts
index bb371e1e7..5f90335f6 100644
--- a/packages/js-sdk/tests/sandbox/lifecyclePayload.test.ts
+++ b/packages/js-sdk/tests/sandbox/lifecyclePayload.test.ts
@@ -18,22 +18,6 @@ async function waitForState(
)
}
-async function triggerAutoResume(url: string): Promise<void> {
- try {
- const response = await fetch(url, {
- signal: AbortSignal.timeout(5_000),
- })
- await response.body?.cancel()
- } catch (error) {
- // The request itself is the wake signal. A gateway timeout while the
- // sandbox resumes is an allowed transitional response; other failures
- // should remain visible.
- if (!(error instanceof Error) || error.name !== 'TimeoutError') {
- throw error
- }
- }
-}
-
function withRequestSource(url: string): string {
const source = process.env.E2B_USER_AGENT_SOURCE
return source ? `${url}?source=${encodeURIComponent(source)}` : url
@@ -162,10 +146,12 @@ sandboxTest.skipIf(isDebug)(
await waitForState(sandbox, 'paused')
+ // Each request is a wake signal; keep sending them until the guest
+ // server answers, since a request that races the pause finalizing or
+ // times out at the gateway while the sandbox resumes may not wake it.
const url = withRequestSource(`https://${sandbox.getHost(8000)}`)
- await triggerAutoResume(url)
+ await waitForHttpStatus(url, 200, { timeoutMs: 60_000 })
await waitForState(sandbox, 'running')
- await waitForHttpStatus(url, 200)
assert.isTrue(await sandbox.isRunning())
} catch (error) {
let state = 'unknown'
diff --git a/packages/js-sdk/tests/sandbox/network.test.ts b/packages/js-sdk/tests/sandbox/network.test.ts
index c61ba7e58..d36b28eef 100644
--- a/packages/js-sdk/tests/sandbox/network.test.ts
+++ b/packages/js-sdk/tests/sandbox/network.test.ts
@@ -150,8 +150,10 @@ describe('allowPublicTraffic=false', () => {
// Test 2: Request with valid traffic access token should succeed
await waitForHttpStatus(sandboxUrl, 200, {
- headers: {
- 'e2b-traffic-access-token': sandbox.trafficAccessToken,
+ init: {
+ headers: {
+ 'e2b-traffic-access-token': sandbox.trafficAccessToken,
+ },
},
})
},
diff --git a/packages/js-sdk/tests/setup.ts b/packages/js-sdk/tests/setup.ts
index e088f3712..dafe05b29 100644
--- a/packages/js-sdk/tests/setup.ts
+++ b/packages/js-sdk/tests/setup.ts
@@ -166,8 +166,7 @@ export async function wait(ms: number) {
export async function waitForHttpStatus(
url: string,
expectedStatus: number,
- init?: RequestInit,
- timeoutMs = 30_000
+ { init, timeoutMs = 30_000 }: { init?: RequestInit; timeoutMs?: number } = {}
): Promise<string> {
const deadline = Date.now() + timeoutMs
let lastStatus: number | undefined