fix: make forceKillDelay testable to prevent signal test timeout

将 forceKillDelay 从常量改为变量,在 TestRun_LoggerRemovedOnSignal 中设为 1 秒。
防止测试等待 3 秒超时,而子进程需要 5 秒才能被强制杀死的竞态条件。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
cexll
2025-12-02 17:35:40 +08:00
parent eb84dfa574
commit 368831da4c
2 changed files with 5 additions and 1 deletions

View File

@@ -24,7 +24,6 @@ const (
version = "4.8.2"
defaultWorkdir = "."
defaultTimeout = 7200 // seconds
forceKillDelay = 5 // seconds
codexLogLineLimit = 1000
stdinSpecialChars = "\n\\\"'`$"
stderrCaptureLimit = 4 * 1024
@@ -41,6 +40,7 @@ var (
buildCodexArgsFn = buildCodexArgs
commandContext = exec.CommandContext
jsonMarshal = json.Marshal
forceKillDelay = 5 // seconds - made variable for testability
)
// Config holds CLI configuration

View File

@@ -28,6 +28,7 @@ func resetTestHooks() {
buildCodexArgsFn = buildCodexArgs
commandContext = exec.CommandContext
jsonMarshal = json.Marshal
forceKillDelay = 5
closeLogger()
}
@@ -1286,6 +1287,9 @@ func TestRun_LoggerRemovedOnSignal(t *testing.T) {
defer resetTestHooks()
defer signal.Reset(syscall.SIGINT, syscall.SIGTERM)
// Set shorter force kill delay for faster test
forceKillDelay = 1
tempDir := t.TempDir()
t.Setenv("TMPDIR", tempDir)
logPath := filepath.Join(tempDir, fmt.Sprintf("codex-wrapper-%d.log", os.Getpid()))