|
@@ -110,21 +110,29 @@ |
|
@@ -110,21 +110,29 @@ |
110
|
|
110
|
|
111
|
- (void)test07ThatLoadImageWithSDWebImageRefreshCachedWorks {
|
111
|
- (void)test07ThatLoadImageWithSDWebImageRefreshCachedWorks {
|
112
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Image download twice with SDWebImageRefresh failed"];
|
112
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Image download twice with SDWebImageRefresh failed"];
|
113
|
- NSURL *originalImageURL = [NSURL URLWithString:kTestJpegURL];
|
|
|
114
|
- [[SDImageCache sharedImageCache] clearDiskOnCompletion:nil];
|
|
|
115
|
-
|
113
|
+ NSURL *originalImageURL = [NSURL URLWithString:@"http://via.placeholder.com/10x10.png"];
|
|
|
114
|
+ __block BOOL firstCompletion = NO;
|
116
|
[[SDWebImageManager sharedManager] loadImageWithURL:originalImageURL options:SDWebImageRefreshCached progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
115
|
[[SDWebImageManager sharedManager] loadImageWithURL:originalImageURL options:SDWebImageRefreshCached progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
117
|
expect(image).toNot.beNil();
|
116
|
expect(image).toNot.beNil();
|
118
|
expect(error).to.beNil();
|
117
|
expect(error).to.beNil();
|
119
|
// #1993, load image with SDWebImageRefreshCached twice should not fail if the first time success.
|
118
|
// #1993, load image with SDWebImageRefreshCached twice should not fail if the first time success.
|
120
|
|
119
|
|
121
|
- [[SDWebImageManager sharedManager] loadImageWithURL:originalImageURL options:SDWebImageRefreshCached progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
|
|
122
|
- expect(image).toNot.beNil();
|
|
|
123
|
- expect(error).to.beNil();
|
|
|
124
|
- [expectation fulfill];
|
|
|
125
|
- }];
|
120
|
+ // Because we call completion before remove the operation from queue, so need a dispatch to avoid get the same operation again. Attention this trap.
|
|
|
121
|
+ // One way to solve this is use another `NSURL instance` because we use `NSURL` as key but not `NSString`. However, this is implementation detail and no guarantee in the future.
|
|
|
122
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
123
|
+ NSURL *newImageURL = [NSURL URLWithString:@"http://via.placeholder.com/10x10.png"];
|
|
|
124
|
+ [[SDWebImageManager sharedManager] loadImageWithURL:newImageURL options:SDWebImageRefreshCached progress:nil completed:^(UIImage * _Nullable image2, NSData * _Nullable data2, NSError * _Nullable error2, SDImageCacheType cacheType2, BOOL finished2, NSURL * _Nullable imageURL2) {
|
|
|
125
|
+ expect(image2).toNot.beNil();
|
|
|
126
|
+ expect(error2).to.beNil();
|
|
|
127
|
+ if (!firstCompletion) {
|
|
|
128
|
+ firstCompletion = YES;
|
|
|
129
|
+ [expectation fulfill];
|
|
|
130
|
+ }
|
|
|
131
|
+ }];
|
|
|
132
|
+ });
|
126
|
}];
|
133
|
}];
|
127
|
- [self waitForExpectationsWithCommonTimeout];
|
134
|
+
|
|
|
135
|
+ [self waitForExpectationsWithTimeout:kAsyncTestTimeout * 2 handler:nil];
|
128
|
}
|
136
|
}
|
129
|
|
137
|
|
130
|
@end |
138
|
@end |