@@ -830,6 +830,35 @@ - (void)test31ThatMultipleRequestForSameURLNeverSkipCallback {
830
830
[self waitForExpectations: expectations timeout: kAsyncTestTimeout * 2 ];
831
831
}
832
832
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
+
833
862
#pragma mark - SDWebImageLoader
834
863
- (void )testCustomImageLoaderWorks {
835
864
XCTestExpectation *expectation = [self expectationWithDescription: @" Custom image not works" ];
0 commit comments