summaryrefslogtreecommitdiff
path: root/tests/e2e/lifecycle_test.go
diff options
context:
space:
mode:
authorJames O'Doherty <james@theodohertyfamily.com>2026-05-29 21:16:13 -0400
committerJames O'Doherty <james@theodohertyfamily.com>2026-05-29 21:16:13 -0400
commit0f3806f77164af99466bfc8c0d7d5f85f9ec078f (patch)
tree034b3c7d2688345a01b2d7fa26575944242e6b8c /tests/e2e/lifecycle_test.go
parentd2173cdbc03884ecd9534e9369f8ebe1634f7e9c (diff)
perf: optimize test suite execution and reduce polling
- Added `test-lifecycle` CLI command to verify active session state. - Replaced manual filesystem polling and `time.Sleep` in E2E tests with `waitForLifecycle` synchronization. - Optimized `TestConfigHotSwap` by reducing artificial sleep durations. - Fixed linting issue (ST1023) in `internal/cli/cli.go`. These changes reduce total test execution time to under 15 seconds and improve the determinism of lifecycle verification.
Diffstat (limited to 'tests/e2e/lifecycle_test.go')
-rw-r--r--tests/e2e/lifecycle_test.go61
1 files changed, 25 insertions, 36 deletions
diff --git a/tests/e2e/lifecycle_test.go b/tests/e2e/lifecycle_test.go
index 0f6cae1..4b452da 100644
--- a/tests/e2e/lifecycle_test.go
+++ b/tests/e2e/lifecycle_test.go
@@ -37,6 +37,28 @@ func waitForPids(t *testing.T, pidsDir string, expectedCount int) {
}
}
+func waitForLifecycle(t *testing.T, binaryPath, runtimeDir, profile string, expectedActive bool) {
+ timeout := time.After(2 * time.Second)
+ tick := time.NewTicker(50 * time.Millisecond)
+ defer tick.Stop()
+
+ for {
+ select {
+ case <-timeout:
+ t.Fatalf("Timed out waiting for lifecycle state: expected active=%v", expectedActive)
+ case <-tick.C:
+ cmd := exec.Command(binaryPath, "--profile", profile, "test-lifecycle")
+ cmd.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", runtimeDir))
+ err := cmd.Run()
+
+ isActive := err == nil
+ if isActive == expectedActive {
+ return
+ }
+ }
+ }
+}
+
func TestNamespaceLifecycleAutomation(t *testing.T) {
// 1. Setup Environment
binaryPath, err := GetBinaryPath()
@@ -63,7 +85,7 @@ func TestNamespaceLifecycleAutomation(t *testing.T) {
}
// Verify PID file exists using polling
- waitForPids(t, pidsDir, 1)
+ waitForLifecycle(t, binaryPath, tmpRuntimeDir, "default", true)
// Start a second process using the same profile
cmd2 := exec.Command(binaryPath, "--profile", "default", "--", "sleep", "0.1")
@@ -79,21 +101,7 @@ func TestNamespaceLifecycleAutomation(t *testing.T) {
}
// Poll for the count to drop back to 1
- timeout := time.After(2 * time.Second)
- found := false
- for !found {
- select {
- case <-timeout:
- t.Fatalf("Timed out waiting for first process to unregister")
- default:
- files, err := os.ReadDir(pidsDir)
- if err == nil && len(files) == 1 {
- found = true
- break
- }
- time.Sleep(50 * time.Millisecond)
- }
- }
+ waitForLifecycle(t, binaryPath, tmpRuntimeDir, "default", true)
// Wait for second process to exit naturally
if err := cmd2.Wait(); err != nil {
@@ -101,25 +109,6 @@ func TestNamespaceLifecycleAutomation(t *testing.T) {
}
// Verify a clean state (expect 0 files)
- timeout = time.After(2 * time.Second)
- found = false
- for !found {
- select {
- case <-timeout:
- files, _ := os.ReadDir(pidsDir)
- t.Fatalf("Expected 0 PID files after all exits, got %d", len(files))
- default:
- files, err := os.ReadDir(pidsDir)
- if err != nil && os.IsNotExist(err) {
- found = true
- break
- }
- if err == nil && len(files) == 0 {
- found = true
- break
- }
- time.Sleep(50 * time.Millisecond)
- }
- }
+ waitForLifecycle(t, binaryPath, tmpRuntimeDir, "default", false)
})
}