Skip to content

Commit 8141eb3

Browse files
committed
Fix AsyncOperation test by adding locking around flags.
1 parent 84ee193 commit 8141eb3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

TestFoundation/TestOperationQueue.swift

+14-6
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,35 @@ class AsyncOperation: Operation {
175175

176176
override internal(set) var isExecuting: Bool {
177177
get {
178-
return _executing
178+
lock.lock()
179+
let wasExecuting = _executing
180+
lock.unlock()
181+
return wasExecuting
179182
}
180183
set {
181-
if _executing != newValue {
184+
if isExecuting != newValue {
182185
willChangeValue(forKey: "isExecuting")
186+
lock.lock()
183187
_executing = newValue
188+
lock.unlock()
184189
didChangeValue(forKey: "isExecuting")
185190
}
186191
}
187192
}
188193

189194
override internal(set) var isFinished: Bool {
190195
get {
191-
return _finished
196+
lock.lock()
197+
let wasFinished = _finished
198+
lock.unlock()
199+
return wasFinished
192200
}
193201
set {
194-
if _finished != newValue {
202+
if isFinished != newValue {
195203
willChangeValue(forKey: "isFinished")
204+
lock.lock()
196205
_finished = newValue
206+
lock.unlock()
197207
didChangeValue(forKey: "isFinished")
198208
}
199209
}
@@ -213,10 +223,8 @@ class AsyncOperation: Operation {
213223

214224
queue.async {
215225
sleep(1)
216-
self.lock.lock()
217226
self.isExecuting = false
218227
self.isFinished = true
219-
self.lock.unlock()
220228
}
221229
}
222230

0 commit comments

Comments
 (0)