Skip to content

Commit b7febd6

Browse files
authored
Make AsyncProcessTests/IntegrationTests.testCanDealWithRunawayChildProcesses more resilient (#133)
This test so far has been flaky enough to add more retries for assertions.
1 parent 58337d6 commit b7febd6

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Tests/AsyncProcessTests/IntegrationTests.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ final class IntegrationTests: XCTestCase {
10251025
// Foundation.Process on Linux doesn't correctly detect when child process dies (creating zombie processes)
10261026
func testCanDealWithRunawayChildProcesses() async throws {
10271027
self.logger = Logger(label: "x")
1028-
self.logger.logLevel = .trace
1028+
self.logger.logLevel = .info
10291029
let p = ProcessExecutor(
10301030
executable: "/bin/bash",
10311031
[
@@ -1070,10 +1070,19 @@ final class IntegrationTests: XCTestCase {
10701070
try await group.waitForAll()
10711071

10721072
// Let's check that the subprocess (/usr/bin/yes) of our subprocess (/bin/bash) is actually dead
1073-
let killRet = kill(pid, 0)
1074-
let errnoCode = errno
1075-
XCTAssertEqual(-1, killRet)
1076-
XCTAssertEqual(ESRCH, errnoCode)
1073+
// This is a tiny bit racy because the pid isn't immediately invalidated, so let's allow a few failures
1074+
for attempt in 0 ..< .max {
1075+
let killRet = kill(pid, 0)
1076+
let errnoCode = errno
1077+
guard killRet == -1 || attempt > 5 else {
1078+
logger.error("kill didn't fail on attempt \(attempt), trying again...")
1079+
usleep(100_000)
1080+
continue
1081+
}
1082+
XCTAssertEqual(-1, killRet)
1083+
XCTAssertEqual(ESRCH, errnoCode)
1084+
break
1085+
}
10771086
}
10781087
}
10791088
#endif

0 commit comments

Comments
 (0)