Skip to content

Commit aec0d6f

Browse files
authored
Merge pull request #2039 from spevans/pr_readability_test
2 parents 0c82d32 + 1ab846b commit aec0d6f

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

TestFoundation/TestProcess.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,7 @@ class _SignalHelperRunner {
517517
let semaphore = DispatchSemaphore(value: 0)
518518

519519
private let outputPipe = Pipe()
520-
private let sQueue = DispatchQueue(label: "io queue")
521-
private let source: DispatchSourceRead
520+
private let sQueue = DispatchQueue(label: "signal queue")
522521

523522
private var gotReady = false
524523
private var bytesIn = Data()
@@ -534,17 +533,16 @@ class _SignalHelperRunner {
534533
process.arguments = ["--signal-test"]
535534
process.standardOutput = outputPipe.fileHandleForWriting
536535

537-
source = DispatchSource.makeReadSource(fileDescriptor: outputPipe.fileHandleForReading.fileDescriptor, queue: sQueue)
538-
let workItem = DispatchWorkItem(block: { [weak self] in
536+
outputPipe.fileHandleForReading.readabilityHandler = { [weak self] fh in
539537
if let strongSelf = self {
540538
let newLine = UInt8(ascii: "\n")
541539

542-
strongSelf.bytesIn.append(strongSelf.outputPipe.fileHandleForReading.availableData)
540+
strongSelf.bytesIn.append(fh.availableData)
543541
if strongSelf.bytesIn.isEmpty {
544542
return
545543
}
546544
// Split the incoming data into lines.
547-
while let index = strongSelf.bytesIn.index(of: newLine) {
545+
while let index = strongSelf.bytesIn.firstIndex(of: newLine) {
548546
if index >= strongSelf.bytesIn.startIndex {
549547
// dont include the newline when converting to string
550548
let line = String(data: strongSelf.bytesIn[strongSelf.bytesIn.startIndex..<index], encoding: String.Encoding.utf8) ?? ""
@@ -567,18 +565,15 @@ class _SignalHelperRunner {
567565
}
568566
}
569567
}
570-
})
571-
source.setEventHandler(handler: workItem)
568+
}
572569
}
573570

574571
deinit {
575-
source.cancel()
576572
process.terminate()
577573
process.waitUntilExit()
578574
}
579575

580576
func start() throws {
581-
source.resume()
582577
try process.run()
583578
}
584579

0 commit comments

Comments
 (0)