From a6cce6677b8f1ad5c021cdd4f1036b244b967664 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Wed, 10 Jan 2024 14:35:29 +0800 Subject: [PATCH] Update unit test The `test15CancelQueryShouldCallbackOnceInSync` should use a better way to check --- Tests/Tests/SDImageCacheTests.m | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Tests/Tests/SDImageCacheTests.m b/Tests/Tests/SDImageCacheTests.m index 70134ee6..111c7d2a 100644 --- a/Tests/Tests/SDImageCacheTests.m +++ b/Tests/Tests/SDImageCacheTests.m @@ -226,25 +226,19 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png"; } - (void)test15CancelQueryShouldCallbackOnceInSync { - XCTestExpectation *expectation = [self expectationWithDescription:@"Cancel Query Should Callback Once In Sync"]; - expectation.expectedFulfillmentCount = 1; NSString *key = @"test15CancelQueryShouldCallbackOnceInSync"; [SDImageCache.sharedImageCache removeImageFromMemoryForKey:key]; [SDImageCache.sharedImageCache removeImageFromDiskForKey:key]; __block BOOL callced = NO; SDImageCacheToken *token = [SDImageCache.sharedImageCache queryCacheOperationForKey:key done:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) { callced = YES; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0), dispatch_get_main_queue(), ^{ - [expectation fulfill]; // callback once fulfill once - }); }]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0), dispatch_get_main_queue(), ^{ - expect(callced).beFalsy(); - [token cancel]; // sync - expect(callced).beTruthy(); - }); - - [self waitForExpectationsWithCommonTimeout]; + expect(callced).beFalsy(); + [token cancel]; // sync + expect(callced).beTruthy(); + if (callced == NO) { + XCTFail("Callback called not in sync but async"); + } } - (void)test20InitialCacheSize{