Skip to content

TestFoundation: make TestPipe pass on Windows #2237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2019
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
14 changes: 11 additions & 3 deletions TestFoundation/TestPipe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
class TestPipe: XCTestCase {

static var allTests: [(String, (TestPipe) -> () throws -> Void)] {
return [
("test_MaxPipes", test_MaxPipes),
var tests: [(String, (TestPipe) -> () throws -> Void)] = [
("test_Pipe", test_Pipe),
]

#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
tests.append(contentsOf: [
("test_MaxPipes", test_MaxPipes),
])
#endif
return tests
}

#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
func test_MaxPipes() {
// Try and create enough pipes to exhaust the process's limits. 1024 is a reasonable
// hard limit for the test. This is reached when testing on Linux (at around 488 pipes)
Expand All @@ -27,14 +34,15 @@ class TestPipe: XCTestCase {
pipes.reserveCapacity(maxPipes)
for _ in 1...maxPipes {
let pipe = Pipe()
if pipe.fileHandleForReading.fileDescriptor == -1 {
if !pipe.fileHandleForReading._isPlatformHandleValid {
XCTAssertEqual(pipe.fileHandleForReading.fileDescriptor, pipe.fileHandleForWriting.fileDescriptor)
break
}
pipes.append(pipe)
}
pipes = []
}
#endif

func test_Pipe() throws {
let aPipe = Pipe()
Expand Down