Skip to content

Commit e7e36fd

Browse files
committed
test(config): remove Windows startup timing assumptions
Cold PowerShell startup under concurrent Windows CI can consume most of the provider timeout, so an unsynchronized PID file may never be written and a fixed four-second bound can fail despite correct process-tree cleanup. Treat an absent PID as a helper that never reached startup, retain strict liveness checks for synchronized children, and bound completion by the child's natural lifetime instead.
1 parent 97ef90d commit e7e36fd

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

‎internal/config/command_test.go‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"errors"
45
"os"
56
"path/filepath"
67
"runtime"
@@ -87,7 +88,7 @@ func TestLoadProviderCommandTimeout(t *testing.T) {
8788
if elapsed > maxElapsed {
8889
t.Fatalf("timeout returned after %s, want roughly 5s", elapsed)
8990
}
90-
assertProcessTerminated(t, pidFile)
91+
assertProcessTerminatedIfStarted(t, pidFile)
9192
}
9293

9394
// TestLoadProviderCommandTerminatesBackgroundChild covers a command that
@@ -97,9 +98,10 @@ func TestLoadProviderCommandTimeout(t *testing.T) {
9798
// leftover child instead of just returning and leaking it.
9899
func TestLoadProviderCommandTerminatesBackgroundChild(t *testing.T) {
99100
pidFile := filepath.Join(t.TempDir(), "bg.pid")
101+
childLifetime := 10 * time.Second
100102
command := writeCommand(t, commandScript{
101103
Stdout: `{"name":"cmd","provider":"openai","apiKey":"sk-command","model":"gpt-command"}`,
102-
BackgroundSleepSeconds: 10,
104+
BackgroundSleepSeconds: int(childLifetime / time.Second),
103105
BackgroundPidFile: pidFile,
104106
})
105107

@@ -112,8 +114,8 @@ func TestLoadProviderCommandTerminatesBackgroundChild(t *testing.T) {
112114
if !strings.Contains(err.Error(), "timed out after 5s") {
113115
t.Fatalf("error = %q, want timeout", err.Error())
114116
}
115-
if elapsed > 4*time.Second {
116-
t.Fatalf("returned after %s, want well under the 5s provider-command timeout since WaitDelay (1s) should trigger termination", elapsed)
117+
if elapsed >= childLifetime {
118+
t.Fatalf("returned after %s, want before the background child finishes naturally after %s", elapsed, childLifetime)
117119
}
118120
assertProcessTerminated(t, pidFile)
119121
}
@@ -126,10 +128,11 @@ func TestLoadProviderCommandTerminatesBackgroundChild(t *testing.T) {
126128
// be terminated on that path.
127129
func TestLoadProviderCommandTerminatesBackgroundChildOnFailure(t *testing.T) {
128130
pidFile := filepath.Join(t.TempDir(), "bg-fail.pid")
131+
childLifetime := 10 * time.Second
129132
command := writeCommand(t, commandScript{
130133
Stderr: "boom",
131134
ExitCode: 7,
132-
BackgroundSleepSeconds: 10,
135+
BackgroundSleepSeconds: int(childLifetime / time.Second),
133136
BackgroundPidFile: pidFile,
134137
})
135138

@@ -142,8 +145,21 @@ func TestLoadProviderCommandTerminatesBackgroundChildOnFailure(t *testing.T) {
142145
if !strings.Contains(err.Error(), "exit status") {
143146
t.Fatalf("error = %q, want exit status failure", err.Error())
144147
}
145-
if elapsed > 4*time.Second {
146-
t.Fatalf("returned after %s, want well under the 5s provider-command timeout since WaitDelay (1s) should trigger termination", elapsed)
148+
if elapsed >= childLifetime {
149+
t.Fatalf("returned after %s, want before the background child finishes naturally after %s", elapsed, childLifetime)
150+
}
151+
assertProcessTerminated(t, pidFile)
152+
}
153+
154+
func assertProcessTerminatedIfStarted(t *testing.T, pidFile string) {
155+
t.Helper()
156+
157+
// The basic timeout fixture is intentionally unsynchronized. On a loaded
158+
// Windows runner, the cold PowerShell child can be terminated before it
159+
// records its PID; the synchronized background-child tests below retain
160+
// the strict PID and liveness checks.
161+
if _, err := os.Stat(pidFile); errors.Is(err, os.ErrNotExist) {
162+
return
147163
}
148164
assertProcessTerminated(t, pidFile)
149165
}

0 commit comments

Comments
 (0)