Skip to content

[5.9] Forward unit test concurrency fix from main #4790

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
Sep 12, 2023
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
8 changes: 3 additions & 5 deletions Tests/Foundation/Tests/TestFileHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -481,16 +481,15 @@ class TestFileHandle : XCTestCase {

func test_readToEndOfFileAndNotify() {
let handle = createFileHandle()
var readSomeData = false

let readSomeData = XCTestExpectation(description: "At least some data must've been read")
let done = expectation(forNotification: FileHandle.readCompletionNotification, object: handle, notificationCenter: .default) { (notification) -> Bool in
guard let data = notification.userInfo?[NSFileHandleNotificationDataItem] as? Data else {
XCTFail("Couldn't find the data in the user info: \(notification)")
return true
}

if !data.isEmpty {
readSomeData = true
readSomeData.fulfill()
handle.readInBackgroundAndNotify()
return false
} else {
Expand All @@ -500,8 +499,7 @@ class TestFileHandle : XCTestCase {

handle.readInBackgroundAndNotify()

wait(for: [done], timeout: 10)
XCTAssertTrue(readSomeData, "At least some data must've been read")
wait(for: [readSomeData, done], timeout: 10)
}

func test_readToEndOfFileAndNotify_readError() {
Expand Down