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/mount_leak_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/mount_leak_test.go')
| -rw-r--r-- | tests/e2e/mount_leak_test.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/tests/e2e/mount_leak_test.go b/tests/e2e/mount_leak_test.go index bdc9d75..428675f 100644 --- a/tests/e2e/mount_leak_test.go +++ b/tests/e2e/mount_leak_test.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "strings" "testing" ) @@ -21,11 +22,11 @@ func TestDNSMountLeak(t *testing.T) { dnsServer := "8.8.8.8" // Pre-create a dummy config for the profile - configDir := "/tmp/wg-wrap-test-configs" - if err := os.MkdirAll(configDir, 0755); err != nil { - t.Fatalf("failed to create config dir: %v", err) + configDir := t.TempDir() + if err := os.MkdirAll(filepath.Join(configDir, "profiles"), 0755); err != nil { + t.Fatalf("failed to create profiles dir: %v", err) } - configPath := fmt.Sprintf("%s/%s.conf", configDir, profile) + configPath := filepath.Join(configDir, "profiles", profile+".conf") if err := os.WriteFile(configPath, []byte("[Interface]\nAddress = 10.0.0.1/24\nPrivateKey = aAAA\n"), 0644); err != nil { t.Fatalf("failed to write config file: %v", err) } |
