@@ -680,7 +680,7 @@ - (void)test26DownloadURLSessionMetrics {
680
680
expect (metric.fetchStartDate ).notTo .beNil ();
681
681
expect (metric.connectStartDate ).notTo .beNil ();
682
682
expect (metric.connectEndDate ).notTo .beNil ();
683
- expect (metric.networkProtocolName ).equal (@" http/1.1 " );
683
+ expect (metric.networkProtocolName ).equal (@" h2 " );
684
684
expect (metric.resourceFetchType ).equal (NSURLSessionTaskMetricsResourceFetchTypeNetworkLoad );
685
685
expect (metric.isProxyConnection ).beFalsy ();
686
686
expect (metric.isReusedConnection ).beFalsy ();
@@ -799,8 +799,39 @@ - (void)test30ThatDifferentThumbnailLoadShouldCallbackDifferentSize {
799
799
[self waitForExpectationsWithTimeout: kAsyncTestTimeout * 5 handler: nil ];
800
800
}
801
801
802
+ - (void )test31ThatMultipleRequestForSameURLNeverSkipCallback {
803
+ // See #3475
804
+ // When multiple download request for same URL, the SDWebImageDownloader will try to `Re-use` URLSessionTask to avoid duplicate actual network request
805
+ // However, if caller submit too frequently in another queue, we should stop attaching more callback once the URLSessionTask `didCompleteWithError:` is called
806
+ NSURL *url = [NSURL fileURLWithPath: [self testPNGPath ]];
807
+ NSMutableArray <XCTestExpectation *> *expectations = [NSMutableArray arrayWithCapacity: 100 ];
808
+ __block void (^recursiveBlock)(int );
809
+ void (^mainBlock)(int ) = ^(int i) {
810
+ if (i > 200 ) return ;
811
+ NSString *desc = [NSString stringWithFormat: @" Local url with index %d not callback!" , i];
812
+ XCTestExpectation *expectation = [self expectationWithDescription: desc];
813
+ [expectations addObject: expectation];
814
+ // Delay 0.01s ~ 0.99s for each download request, simulate the real-world call site
815
+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(i * 10000000ull )), dispatch_get_main_queue (), ^{
816
+ [SDWebImageDownloader.sharedDownloader downloadImageWithURL: url completed: ^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
817
+ if (image) {
818
+ NSLog (@" Local url callback with index: %d " , i);
819
+ [expectation fulfill ];
820
+ } else {
821
+ XCTFail (@" Something went wrong: %@ " , error.description );
822
+ }
823
+ }];
824
+ });
825
+ recursiveBlock (i+1 );
826
+ };
827
+ recursiveBlock = mainBlock;
828
+ recursiveBlock (0 );
829
+
830
+ [self waitForExpectations: expectations timeout: kAsyncTestTimeout * 2 ];
831
+ }
832
+
802
833
#pragma mark - SDWebImageLoader
803
- - (void )test30CustomImageLoaderWorks {
834
+ - (void )testCustomImageLoaderWorks {
804
835
XCTestExpectation *expectation = [self expectationWithDescription: @" Custom image not works" ];
805
836
SDWebImageTestLoader *loader = [[SDWebImageTestLoader alloc ] init ];
806
837
NSURL *imageURL = [NSURL URLWithString: kTestJPEGURL ];
@@ -820,7 +851,7 @@ - (void)test30CustomImageLoaderWorks {
820
851
[self waitForExpectationsWithCommonTimeout ];
821
852
}
822
853
823
- - (void )test31ThatLoadersManagerWorks {
854
+ - (void )testThatLoadersManagerWorks {
824
855
XCTestExpectation *expectation = [self expectationWithDescription: @" Loaders manager not works" ];
825
856
SDWebImageTestLoader *loader = [[SDWebImageTestLoader alloc ] init ];
826
857
SDImageLoadersManager *manager = [[SDImageLoadersManager alloc ] init ];
0 commit comments