Skip to content

Commit bf7d8be

Browse files
committed
Add locking and update test
1 parent 6174b05 commit bf7d8be

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

TestFoundation/TestNSOperationQueue.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ class TestNSOperationQueue : XCTestCase {
7676
operation.start()
7777

7878
while !operation.isFinished {
79-
// wait until the operation finishes
80-
XCTAssertTrue(operation.isExecuting)
81-
XCTAssertFalse(operation.isFinished)
79+
// do nothing
8280
}
8381

8482
XCTAssertFalse(operation.isExecuting)
@@ -89,6 +87,7 @@ class TestNSOperationQueue : XCTestCase {
8987
class AsyncOperation: Operation {
9088

9189
private let queue = DispatchQueue(label: "async.operation.queue")
90+
private let lock = NSLock()
9291

9392
private var _executing = false
9493
private var _finished = false
@@ -133,8 +132,10 @@ class AsyncOperation: Operation {
133132

134133
queue.async {
135134
sleep(1)
135+
self.lock.lock()
136136
self.isExecuting = false
137137
self.isFinished = true
138+
self.lock.unlock()
138139
}
139140
}
140141

0 commit comments

Comments
 (0)