File tree Expand file tree Collapse file tree 1 file changed +7
-26
lines changed Expand file tree Collapse file tree 1 file changed +7
-26
lines changed Original file line number Diff line number Diff line change @@ -213,41 +213,22 @@ class TestNSNotificationQueue : XCTestCase {
213
213
// MARK: Private
214
214
215
215
private func scheduleTimer( withInterval interval: NSTimeInterval ) {
216
- var isInvoked = false
216
+ let e = expectation ( withDescription : " Timer " )
217
217
let dummyTimer = NSTimer . scheduledTimer ( interval, repeats: false ) { _ in
218
- isInvoked = true
218
+ e . fulfill ( )
219
219
}
220
220
NSRunLoop . currentRunLoop ( ) . addTimer ( dummyTimer, forMode: NSDefaultRunLoopMode)
221
- self . waitForExpectation ( {
222
- return isInvoked
223
- } , withTimeout: 0.1 )
221
+ waitForExpectations ( withTimeout: 0.1 )
224
222
}
225
223
226
- private func executeInBackgroundThread( _ operation: ( ) -> ( ) ) -> Bool {
227
- var isFinished = false
228
- let lock = NSLock ( )
224
+ private func executeInBackgroundThread( _ operation: ( ) -> Void ) {
225
+ let e = expectation ( withDescription: " Background Execution " )
229
226
let bgThread = NSThread ( ) {
230
227
operation ( )
231
- lock. lock ( )
232
- isFinished = true
233
- lock. unlock ( )
228
+ e. fulfill ( )
234
229
}
235
230
bgThread. start ( )
236
231
237
- return self . waitForExpectation ( {
238
- lock. lock ( )
239
- let finished = isFinished
240
- lock. unlock ( )
241
- return finished
242
- } , withTimeout: 0.2 )
232
+ waitForExpectations ( withTimeout: 0.2 )
243
233
}
244
-
245
- private func waitForExpectation( _ expectation: ( ) -> Bool , withTimeout timeout: NSTimeInterval ) -> Bool {
246
- let timeoutDate = NSDate ( timeIntervalSinceNow: timeout)
247
- while !expectation( ) && timeoutDate. timeIntervalSinceNow > 0.0 {
248
- NSRunLoop . currentRunLoop ( ) . runUntilDate ( NSDate ( timeIntervalSinceNow: 0.01 ) )
249
- }
250
- return expectation ( )
251
- }
252
-
253
234
}
You can’t perform that action at this time.
0 commit comments