diff --git a/Tests/CodexBarTests/ShellCommandLocatorProcessTests.swift b/Tests/CodexBarTests/ShellCommandLocatorProcessTests.swift index 7736323586..f64a964455 100644 --- a/Tests/CodexBarTests/ShellCommandLocatorProcessTests.swift +++ b/Tests/CodexBarTests/ShellCommandLocatorProcessTests.swift @@ -30,6 +30,18 @@ struct ShellCommandLocatorProcessTests { .path let stdoutPIDFile = "\(pidFile).stdout" let stderrPIDFile = "\(pidFile).stderr" + let pidFiles = [stdoutPIDFile, stderrPIDFile] + defer { + for file in pidFiles { + if let pidText = try? String(contentsOfFile: file, encoding: .utf8) + .trimmingCharacters(in: .whitespacesAndNewlines), + let pid = pid_t(pidText) + { + kill(pid, SIGKILL) + } + try? FileManager.default.removeItem(atPath: file) + } + } let script = """ import os import signal @@ -57,25 +69,17 @@ struct ShellCommandLocatorProcessTests { let data = ShellCommandLocator.test_runShellCommand( shell: "/usr/bin/python3", arguments: ["-c", script, pidFile], - timeout: 0.2) + timeout: 2.0) let elapsed = Date().timeIntervalSince(start) - let pids = try [stdoutPIDFile, stderrPIDFile].map { file in + let pids = try pidFiles.map { file in let pidText = try String(contentsOfFile: file, encoding: .utf8) .trimmingCharacters(in: .whitespacesAndNewlines) return try #require(pid_t(pidText)) } - defer { - for pid in pids { - kill(pid, SIGKILL) - } - for file in [stdoutPIDFile, stderrPIDFile] { - try? FileManager.default.removeItem(atPath: file) - } - } #expect(data == nil) - #expect(elapsed < 3.0, "Timed-out PATH probes should remain bounded") + #expect(elapsed < 4.0, "Timed-out PATH probes should remain bounded") for pid in pids { #expect(kill(pid, 0) != 0) }