Skip to content

Commit 9bc5207

Browse files
committed
Added test case test31ThatMultipleRequestForSameURLFailedCallback to ensure behavior
1 parent b25864c commit 9bc5207

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Tests/Tests/SDWebImageDownloaderTests.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,35 @@ - (void)test31ThatMultipleRequestForSameURLNeverSkipCallback {
830830
[self waitForExpectations:expectations timeout:kAsyncTestTimeout * 2];
831831
}
832832

833+
834+
- (void)test31ThatMultipleRequestForSameURLFailedCallback {
835+
// See #3493, silly bug
836+
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"]; // Always fail url
837+
NSMutableArray<XCTestExpectation *> *expectations = [NSMutableArray arrayWithCapacity:100];
838+
__block void (^recursiveBlock)(int);
839+
void (^mainBlock)(int) = ^(int i) {
840+
if (i > 200) return;
841+
NSString *desc = [NSString stringWithFormat:@"Failed url with index %d should callback error", i];
842+
XCTestExpectation *expectation = [self expectationWithDescription:desc];
843+
[expectations addObject:expectation];
844+
// Delay 0.01s ~ 0.99s for each download request, simulate the real-world call site
845+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(i * 10000000ull)), dispatch_get_main_queue(), ^{
846+
[SDWebImageDownloader.sharedDownloader downloadImageWithURL:url completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
847+
if (error) {
848+
expect(error.code).equal(SDWebImageErrorBadImageData);
849+
[expectation fulfill];
850+
}
851+
}];
852+
});
853+
recursiveBlock(i+1);
854+
};
855+
recursiveBlock = mainBlock;
856+
recursiveBlock(0);
857+
858+
[self waitForExpectations:expectations timeout:kAsyncTestTimeout * 2];
859+
}
860+
861+
833862
#pragma mark - SDWebImageLoader
834863
- (void)testCustomImageLoaderWorks {
835864
XCTestExpectation *expectation = [self expectationWithDescription:@"Custom image not works"];

0 commit comments

Comments
 (0)