@@ -412,6 +412,32 @@ public async Task MismatchedETag(CancellationToken ct)
412412 Assert . That ( ex . Message , Does . Contain ( "ETag does not match SHA1 hash of downloaded file" ) . And . Contains ( "beef" ) ) ;
413413 }
414414
415+ [ Test ( Description = "Timeout waiting for existing download" ) ]
416+ [ CancelAfter ( 30_000 ) ]
417+ public async Task CancelledWaitingForOther ( CancellationToken ct )
418+ {
419+ var testCts = CancellationTokenSource . CreateLinkedTokenSource ( ct ) ;
420+ using var httpServer = new TestHttpServer ( async _ =>
421+ {
422+ await Task . Delay ( TimeSpan . FromSeconds ( 5 ) , testCts . Token ) ;
423+ } ) ;
424+ var url0 = new Uri ( httpServer . BaseUrl + "/test0" ) ;
425+ var url1 = new Uri ( httpServer . BaseUrl + "/test1" ) ;
426+ var destPath = Path . Combine ( _tempDir , "test" ) ;
427+ var manager = new Downloader ( NullLogger < Downloader > . Instance ) ;
428+
429+ // first outer task succeeds, getting download started
430+ var dlTask0 = await manager . StartDownloadAsync ( new HttpRequestMessage ( HttpMethod . Get , url0 ) , destPath ,
431+ NullDownloadValidator . Instance , testCts . Token ) ;
432+
433+ // The second request fails if the timeout is short
434+ var smallerCt = new CancellationTokenSource ( TimeSpan . FromSeconds ( 1 ) ) . Token ;
435+ Assert . ThrowsAsync < TaskCanceledException > ( async ( ) => await manager . StartDownloadAsync (
436+ new HttpRequestMessage ( HttpMethod . Get , url1 ) , destPath ,
437+ NullDownloadValidator . Instance , smallerCt ) ) ;
438+ await testCts . CancelAsync ( ) ;
439+ }
440+
415441 [ Test ( Description = "Timeout on response body" ) ]
416442 [ CancelAfter ( 30_000 ) ]
417443 public async Task CancelledInner ( CancellationToken ct )
0 commit comments