Skip to content

Fix OperationQueue counters #2777

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
Apr 27, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Sources/Foundation/Operation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ open class OperationQueue : NSObject, ProgressReporting {
defer { _unlock() }
var op = __firstOperation
var cnt = 0
if let operation = op?.takeUnretainedValue() {
while let operation = op?.takeUnretainedValue() {
if !(operation is _BarrierOperation) {
cnt += 1
}
Expand All @@ -1100,7 +1100,7 @@ open class OperationQueue : NSObject, ProgressReporting {
defer { _unlock() }
var operations = [Operation]()
var op = __firstOperation
if let operation = op?.takeUnretainedValue() {
while let operation = op?.takeUnretainedValue() {
if includingBarriers || !(operation is _BarrierOperation) {
operations.append(operation)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Foundation/Tests/TestOperationQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestOperationQueue : XCTestCase {
static var allTests: [(String, (TestOperationQueue) -> () throws -> Void)] {
return [
("test_OperationPriorities", test_OperationPriorities),
/* ⚠️ */ ("test_OperationCount", testExpectedToFail(test_OperationCount, "OperationQueue can't count to more than 1")),
("test_OperationCount", test_OperationCount),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to have a test that ensures that the operations returned are also correct. I don't think that we need to hold up this particular patch for that, but would be a good addition to the test suite in a follow up change.

("test_AsyncOperation", test_AsyncOperation),
("test_SyncOperationWithoutAQueue", test_SyncOperationWithoutAQueue),
("test_isExecutingWorks", test_isExecutingWorks),
Expand Down