diff options
| author | James O'Doherty <james@theodohertyfamily.com> | 2026-06-03 23:45:45 -0400 |
|---|---|---|
| committer | James O'Doherty <james@theodohertyfamily.com> | 2026-06-03 23:45:45 -0400 |
| commit | 51a0845adba702ac02437405988b24b3b2c9fb45 (patch) | |
| tree | 62174471b2bf2240f5cbe8532c991e33afce9e18 /tests/e2e/lifecycle_test.go | |
| parent | da70b10fbd056f19d892acad542ce96c40c58389 (diff) | |
fix: resolve resource leaks and improve namespace lifecycle management
- Fix DNS resolver leaks by creating temporary resolv.conf files within the profile's runtime directory and ensuring robust cleanup.
- Fix isolation block directory leaks by explicitly removing the block directory during namespace unpinning.
- Improve namespace lifecycle management:
- Register processes before joining an active namespace to prevent race conditions in reference counting.
- Update `IsLastProcess` and corresponding tests to reflect the unregister-then-check cleanup flow.
- Improve test reliability and correctness:
- Convert `TestAppRun_ProfileDirInjection` to use separate binary execution, preventing process replacement and ensuring `t.TempDir()` cleanup.
- Replace hardcoded test configuration paths with `t.TempDir()` in `mount_leak_test.go`.
- Implement `SetEnvOverrides` helper for cleaner environment variable management in E2E tests.
- Improve E2E lifecycle tests with better environment handling and output redirection.
Diffstat (limited to 'tests/e2e/lifecycle_test.go')
| -rw-r--r-- | tests/e2e/lifecycle_test.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/tests/e2e/lifecycle_test.go b/tests/e2e/lifecycle_test.go index 6cff0c8..ffd731f 100644 --- a/tests/e2e/lifecycle_test.go +++ b/tests/e2e/lifecycle_test.go @@ -1,7 +1,6 @@ package e2e import ( - "fmt" "os" "os/exec" "path/filepath" @@ -48,7 +47,9 @@ func waitForLifecycle(t *testing.T, binaryPath, runtimeDir, profile string, expe t.Fatalf("Timed out waiting for lifecycle state: expected active=%v", expectedActive) case <-tick.C: cmd := exec.Command(binaryPath, "test-lifecycle", "--profile", profile) - cmd.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", runtimeDir)) + cmd.Env = SetEnvOverrides(map[string]string{"XDG_RUNTIME_DIR": runtimeDir}) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr err := cmd.Run() isActive := err == nil @@ -79,7 +80,9 @@ func TestNamespaceLifecycleAutomation(t *testing.T) { t.Run("ReferenceCounting", func(t *testing.T) { // Start a process that exits quickly cmd1 := exec.Command(binaryPath, "--profile", "default", "--", "sleep", "1.0") - cmd1.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", tmpRuntimeDir)) + cmd1.Env = SetEnvOverrides(map[string]string{"XDG_RUNTIME_DIR": tmpRuntimeDir}) + cmd1.Stdout = os.Stdout + cmd1.Stderr = os.Stderr if err := cmd1.Start(); err != nil { t.Fatalf("Failed to start cmd1: %v", err) } @@ -87,9 +90,11 @@ func TestNamespaceLifecycleAutomation(t *testing.T) { // Verify PID file exists using polling waitForLifecycle(t, binaryPath, tmpRuntimeDir, "default", true) - // Start a second process using the same profile - cmd2 := exec.Command(binaryPath, "--profile", "default", "--", "sleep", "1.0") - cmd2.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", tmpRuntimeDir)) + // Start a second process using the same profile with a longer sleep + cmd2 := exec.Command(binaryPath, "--profile", "default", "--", "sleep", "5.0") + cmd2.Env = SetEnvOverrides(map[string]string{"XDG_RUNTIME_DIR": tmpRuntimeDir}) + cmd2.Stdout = os.Stdout + cmd2.Stderr = os.Stderr if err := cmd2.Start(); err != nil { t.Fatalf("Failed to start cmd2: %v", err) } @@ -100,7 +105,7 @@ func TestNamespaceLifecycleAutomation(t *testing.T) { t.Fatalf("cmd1 failed: %v", err) } - // Poll for the count to drop back to 1 + // Poll for the count to drop back to 1 (cmd2 should still be running) waitForLifecycle(t, binaryPath, tmpRuntimeDir, "default", true) // Wait for second process to exit naturally |
