@@ -23,6 +23,7 @@ @interface PINDiskCache()
23
23
24
24
@property (assign , nonatomic ) BOOL diskStateKnown;
25
25
@property (strong , nonatomic ) NSDictionary *metadata;
26
+ @property (readonly ) PINOperationQueue *operationQueue;
26
27
27
28
+ (dispatch_queue_t )sharedTrashQueue ;
28
29
+ (NSURL *)sharedTrashURL ;
@@ -272,7 +273,6 @@ - (void)testObjectGetWithInvalidKey
272
273
- (void )testObjectRemove
273
274
{
274
275
NSString *key = @" key" ;
275
- dispatch_semaphore_t semaphore = dispatch_semaphore_create (0 );
276
276
277
277
self.cache [key] = [self image ];
278
278
@@ -285,13 +285,12 @@ - (void)testObjectRemove
285
285
self.cache .diskCache .didRemoveObjectBlock = ^(PINDiskCache * _Nonnull cache, NSString * _Nonnull key, id <NSCoding > _Nullable object) {
286
286
didRemoveObjectBlockCalled = YES ;
287
287
};
288
-
289
- [self .cache removeObjectForKeyAsync: key completion: ^(id <PINCaching> cache, NSString *key, id object) {
290
- dispatch_semaphore_signal (semaphore);
291
- }];
292
-
293
- dispatch_semaphore_wait (semaphore, [self timeout ]);
294
288
289
+ // Clear out operation queue to ensure blocks are set.
290
+ [self .cache.diskCache.operationQueue waitUntilAllOperationsAreFinished ];
291
+
292
+ [self .cache removeObjectForKey: key];
293
+
295
294
id object = self.cache [key];
296
295
297
296
XCTAssertNil (object, @" object was not removed" );
@@ -303,7 +302,6 @@ - (void)testObjectRemoveAll
303
302
{
304
303
NSString *key1 = @" key1" ;
305
304
NSString *key2 = @" key2" ;
306
- dispatch_semaphore_t semaphore = dispatch_semaphore_create (0 );
307
305
308
306
self.cache [key1] = key1;
309
307
self.cache [key2] = key2;
@@ -317,12 +315,10 @@ - (void)testObjectRemoveAll
317
315
self.cache .diskCache .didRemoveAllObjectsBlock = ^(id <PINCaching> _Nonnull cache) {
318
316
didRemoveAllObjectsBlockCalled = YES ;
319
317
};
320
-
321
- [self .cache removeAllObjectsAsync: ^(id <PINCaching> cache) {
322
- dispatch_semaphore_signal (semaphore);
323
- }];
324
318
325
- dispatch_semaphore_wait (semaphore, [self timeout ]);
319
+ [self .cache.diskCache.operationQueue waitUntilAllOperationsAreFinished ];
320
+
321
+ [self .cache removeAllObjects ];
326
322
327
323
id object1 = self.cache [key1];
328
324
id object2 = self.cache [key2];
0 commit comments