Skip to content
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

Fix Operation.swift Operation addDependency bug #2488

Merged
merged 2 commits into from
Aug 27, 2019
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
2 changes: 1 addition & 1 deletion Foundation/Operation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ open class Operation : NSObject {
withExtendedLifetime(op) {
var up: Operation?
_lock()
if __dependencies.first(where: { $0 === op }) != nil {
if __dependencies.first(where: { $0 === op }) == nil {
__dependencies.append(op)
up = op
}
Expand Down
15 changes: 15 additions & 0 deletions TestFoundation/TestOperationQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TestOperationQueue : XCTestCase {
("test_CurrentQueueWithCustomUnderlyingQueue", test_CurrentQueueWithCustomUnderlyingQueue),
("test_CurrentQueueWithUnderlyingQueueResetToNil", test_CurrentQueueWithUnderlyingQueueResetToNil),
("test_isSuspended", test_isSuspended),
("test_OperationDependencyCount", test_OperationDependencyCount),
]
}

Expand Down Expand Up @@ -264,6 +265,20 @@ class TestOperationQueue : XCTestCase {

waitForExpectations(timeout: 1)
}

func test_OperationDependencyCount() {
var results = [Int]()
let op1 = BlockOperation {
results.append(1)
}
op1.name = "op1"
let op2 = BlockOperation {
results.append(2)
}
op2.name = "op2"
op1.addDependency(op2)
XCTAssert(op1.dependencies.count == 1)
}
}

class AsyncOperation: Operation {
Expand Down