Skip to content

Commit c93dc02

Browse files
committed
fix(tests): deflake remaining integration flakes
1 parent c01f876 commit c93dc02

3 files changed

Lines changed: 33 additions & 20 deletions

File tree

‎tests/integration/internal/tests/envd/process_test.go‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/stretchr/testify/require"
1111

1212
"github.com/e2b-dev/infra/packages/shared/pkg/grpc/envd/process"
13+
"github.com/e2b-dev/infra/tests/integration/internal/api"
1314
"github.com/e2b-dev/infra/tests/integration/internal/setup"
1415
"github.com/e2b-dev/infra/tests/integration/internal/utils"
1516
)
@@ -20,15 +21,28 @@ func TestCommandKillNextApp(t *testing.T) {
2021
defer cancel()
2122

2223
client := setup.GetAPIClient()
23-
sbx := utils.SetupSandboxWithCleanup(t, client, utils.WithTimeout(300))
24-
25-
envdClient := setup.GetEnvdClient(t, ctx)
2624

27-
// Run `npx create-next-app`
25+
// Pre-bake create-next-app into a template build (fresh-boot VM) instead of
26+
// running the page-fault-heavy npm install in the restored sandbox, where
27+
// host load has caused guest soft lockups and envd stream EOFs.
2828
// Pinned to the latest known-good stable release; `@latest` currently resolves
2929
// to a 16.3.0 pre-release that ships a broken SWC binary and 404s on preview.
30-
err := utils.ExecCommand(t, ctx, sbx, envdClient, "npx", "create-next-app@16.2.8", "nextapp", "--yes")
31-
require.NoError(t, err)
30+
tmpl := utils.BuildTemplate(t, utils.TemplateBuildOptions{
31+
Name: "kill-next-app",
32+
Timeout: 10 * time.Minute,
33+
BuildData: api.TemplateBuildStartV2{
34+
FromTemplate: &setup.SandboxTemplateID,
35+
Steps: &[]api.TemplateStep{{
36+
Type: "RUN",
37+
Args: &[]string{"cd /home/user && npx create-next-app@16.2.8 nextapp --yes", "user"},
38+
}},
39+
},
40+
ReqEditors: []api.RequestEditorFn{setup.WithAPIKey()},
41+
})
42+
43+
sbx := utils.SetupSandboxWithCleanup(t, client, utils.WithTimeout(300), utils.WithTemplateID(tmpl.TemplateID))
44+
45+
envdClient := setup.GetEnvdClient(t, ctx)
3246

3347
// Run `npm run dev` in background
3448
cwd := "~/nextapp"

‎tests/integration/internal/tests/orchestrator/sandbox_object_not_found_test.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ func TestSandboxObjectNotFound(t *testing.T) {
2222

2323
client := setup.GetOrchestratorClient(t, ctx)
2424

25-
for range 10 {
25+
// Under full host load (parallel 100-sandbox tests) the orchestrator can
26+
// report ResourceExhausted for minutes before template validation is
27+
// reached, so keep the retry window generous.
28+
for range 36 {
2629
_, err := client.Create(ctx, &orchestrator.SandboxCreateRequest{
2730
Sandbox: &orchestrator.SandboxConfig{
2831
TemplateId: "nonexistent-template-id",
@@ -67,6 +70,6 @@ func TestSandboxObjectNotFound(t *testing.T) {
6770
return
6871
}
6972

70-
t.Log("failed to create sandbox after 10 retries")
73+
t.Log("failed to create sandbox after 36 retries")
7174
t.FailNow()
7275
}

‎tests/integration/internal/tests/proxies/mask_request_host_test.go‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,21 @@ func TestMaskRequestHostAPIParameter(t *testing.T) {
3030
// Create sandbox with maskRequestHost set
3131
sbx := utils.SetupSandboxWithCleanup(t, c, utils.WithNetwork(sbxNet), utils.WithTimeout(120))
3232

33-
// run sudo apt-get update; sudo apt-get install -y netcat
34-
// run nc -l -p 8080
3533
envdClient := setup.GetEnvdClient(t, ctx)
3634

37-
// Install netcat for the test
38-
err := utils.ExecCommandAsRoot(t, ctx, sbx, envdClient, "apt-get", "update")
39-
require.NoError(t, err)
40-
err = utils.ExecCommandAsRoot(t, ctx, sbx, envdClient, "apt-get", "install", "-y", "netcat-traditional")
41-
require.NoError(t, err)
42-
4335
port := 8080
44-
// Start a netcat listener on port that outputs request headers to a file
36+
// Single-shot listener that dumps the raw request to a file. Uses the
37+
// preinstalled python instead of installing netcat via apt-get, which is
38+
// page-fault-heavy enough to wedge the sandbox under parallel test load.
4539
outputFile := "/tmp/nc_output.txt"
40+
listener := fmt.Sprintf(
41+
`import socket; s=socket.socket(); s.bind(("0.0.0.0",%d)); s.listen(1); c,_=s.accept(); open(%q,"wb").write(c.recv(65536))`,
42+
port, outputFile)
4643
go func() {
47-
_ = utils.ExecCommandAsRoot(t, ctx, sbx, envdClient,
48-
"/bin/bash", "-c", fmt.Sprintf("nc -l -p %d > %s", port, outputFile))
44+
_ = utils.ExecCommandAsRoot(t, ctx, sbx, envdClient, "python3", "-c", listener)
4945
}()
5046

51-
// Wait for nc to be up
47+
// Wait for the listener to be up
5248
time.Sleep(2 * time.Second)
5349

5450
// Prepare the sandbox URL using helpers

0 commit comments

Comments
 (0)