Update unit test

The `test15CancelQueryShouldCallbackOnceInSync` should use a better way to check
This commit is contained in:
DreamPiggy 2024-01-10 14:35:29 +08:00
parent c60958ca1c
commit a6cce6677b
1 changed files with 6 additions and 12 deletions

View File

@ -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{