Skip to content

Commit 7a3be0b

Browse files
committed
[UtilityTests] Close master fd explicitly
It looks like if deinit wasn't called for pesudoterminal in time the master won't be closed and OS would assign slave fd to new pipe (because it was already closed) and that turns out to be a bad file descriptor somehow... Closing explicitly fixes the issue. - <rdar://problem/28411803> POSIX.popen() sometimes breaks the build - https://bugs.swift.org/browse/SR-2703
1 parent 76714d2 commit 7a3be0b

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

Tests/UtilityTests/ProgressBarTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ final class PseudoTerminal {
4343
return String(cString: buf)
4444
}
4545

46-
func close() {
46+
func closeSlave() {
4747
_ = libc.close(slave)
4848
}
4949

50-
deinit {
50+
func closeMaster() {
5151
_ = libc.close(master)
5252
}
5353
}
@@ -79,9 +79,10 @@ final class ProgressBarTests: XCTestCase {
7979
}
8080
thread.start()
8181
runProgressBar(bar)
82-
pty.close()
82+
pty.closeSlave()
8383
// Make sure to read the complete output before checking it.
8484
thread.join()
85+
pty.closeMaster()
8586
XCTAssertTrue(output.chuzzle()?.hasPrefix("\u{1B}[36m\u{1B}[1mTestHeader\u{1B}[0m") ?? false)
8687
}
8788

Tests/UtilityTests/ShellTests.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,18 @@ import Utility
1616
class ShellTests: XCTestCase {
1717

1818
func testPopen() {
19-
// FIXME: Disabled due to https://bugs.swift.org/browse/SR-2703
20-
#if false
2119
XCTAssertEqual(try! popen(["echo", "foo"]), "foo\n")
22-
#endif
2320
}
2421

2522
func testPopenWithBufferLargerThanThatAllocated() {
26-
// FIXME: Disabled due to https://bugs.swift.org/browse/SR-2703
27-
#if false
2823
let path = AbsolutePath(#file).parentDirectory.parentDirectory.appending(components: "GetTests", "VersionGraphTests.swift")
2924
XCTAssertGreaterThan(try! popen(["cat", path.asString]).characters.count, 4096)
30-
#endif
3125
}
3226

3327
func testPopenWithBinaryOutput() {
34-
// FIXME: Disabled due to https://bugs.swift.org/browse/SR-2703
35-
#if false
3628
if (try? popen(["cat", "/bin/cat"])) != nil {
3729
XCTFail("popen succeeded but should have faileds")
3830
}
39-
#endif
4031
}
4132

4233
static var allTests = [

0 commit comments

Comments
 (0)