Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions Tests/CodexBarTests/ShellCommandLocatorProcessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down