Skip to content

Commit 2e35c0a

Browse files
authored
fix flaky test that can hang in CI (#205)
motivation: stable CI background: * testSignal can hang *sometimes* when the child processes it creates do not recieve the expeted signal. * this has been observed when waitForFile timed-out and the test existed before issuing the signal. * this behavior is unexpected and points to potential issue with xctest, but this fix attempts to workaround the underlying issue by making sure the sub-rocesses are forced-killed by the test itself changes: * regsiter the sub-processes in a process-set and force temrinate them at the end of the test rdar://74356445
1 parent 38b42c1 commit 2e35c0a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Tests/TSCBasicTests/ProcessTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class ProcessTests: XCTestCase {
116116

117117
#if !os(Windows) // Signals are not supported in Windows
118118
func testSignals() throws {
119+
let processes = ProcessSet()
119120
let group = DispatchGroup()
120121

121122
DispatchQueue.global().async(group: group) {
@@ -125,6 +126,7 @@ class ProcessTests: XCTestCase {
125126
let file = tmpdir.appending(component: "pidfile")
126127
let waitFile = tmpdir.appending(component: "waitFile")
127128
let process = Process(args: self.script("print-pid"), file.pathString, waitFile.pathString)
129+
try processes.add(process)
128130
try process.launch()
129131
guard waitForFile(waitFile) else {
130132
return XCTFail("Couldn't launch the process")
@@ -152,6 +154,7 @@ class ProcessTests: XCTestCase {
152154
let file = tmpdir.appending(component: "pidfile")
153155
let waitFile = tmpdir.appending(component: "waitFile")
154156
let process = Process(args: self.script("subprocess"), file.pathString, waitFile.pathString)
157+
try processes.add(process)
155158
try process.launch()
156159
guard waitForFile(waitFile) else {
157160
return XCTFail("Couldn't launch the process")
@@ -183,6 +186,9 @@ class ProcessTests: XCTestCase {
183186
if case .timedOut = group.wait(timeout: .now() + 10) {
184187
XCTFail("timeout waiting for signals to be processed")
185188
}
189+
190+
// rdar://74356445: make sure the processes are terminated as they *sometimes* cause xctest to hang
191+
processes.terminate()
186192
}
187193
#endif
188194

0 commit comments

Comments
 (0)