@@ -375,17 +375,17 @@ public async Task DownloadExistingDifferentContent(CancellationToken ct)
375
375
376
376
[ Test ( Description = "Unexpected response code from server" ) ]
377
377
[ CancelAfter ( 30_000 ) ]
378
- public void UnexpectedResponseCode ( CancellationToken ct )
378
+ public async Task UnexpectedResponseCode ( CancellationToken ct )
379
379
{
380
380
using var httpServer = new TestHttpServer ( ctx => { ctx . Response . StatusCode = 404 ; } ) ;
381
381
var url = new Uri ( httpServer . BaseUrl + "/test" ) ;
382
382
var destPath = Path . Combine ( _tempDir , "test" ) ;
383
383
384
384
var manager = new Downloader ( NullLogger < Downloader > . Instance ) ;
385
- // The "outer " Task should fail.
386
- var ex = Assert . ThrowsAsync < HttpRequestException > ( async ( ) =>
387
- await manager . StartDownloadAsync ( new HttpRequestMessage ( HttpMethod . Get , url ) , destPath ,
388
- NullDownloadValidator . Instance , ct ) ) ;
385
+ // The "inner " Task should fail.
386
+ var dlTask = await manager . StartDownloadAsync ( new HttpRequestMessage ( HttpMethod . Get , url ) , destPath ,
387
+ NullDownloadValidator . Instance , ct ) ;
388
+ var ex = Assert . ThrowsAsync < HttpRequestException > ( async ( ) => await dlTask . Task ) ;
389
389
Assert . That ( ex . Message , Does . Contain ( "404" ) ) ;
390
390
}
391
391
@@ -412,22 +412,6 @@ public async Task MismatchedETag(CancellationToken ct)
412
412
Assert . That ( ex . Message , Does . Contain ( "ETag does not match SHA1 hash of downloaded file" ) . And . Contains ( "beef" ) ) ;
413
413
}
414
414
415
- [ Test ( Description = "Timeout on response headers" ) ]
416
- [ CancelAfter ( 30_000 ) ]
417
- public void CancelledOuter ( CancellationToken ct )
418
- {
419
- using var httpServer = new TestHttpServer ( async _ => { await Task . Delay ( TimeSpan . FromSeconds ( 5 ) , ct ) ; } ) ;
420
- var url = new Uri ( httpServer . BaseUrl + "/test" ) ;
421
- var destPath = Path . Combine ( _tempDir , "test" ) ;
422
-
423
- var manager = new Downloader ( NullLogger < Downloader > . Instance ) ;
424
- // The "outer" Task should fail.
425
- var smallerCt = new CancellationTokenSource ( TimeSpan . FromSeconds ( 1 ) ) . Token ;
426
- Assert . ThrowsAsync < TaskCanceledException > ( async ( ) => await manager . StartDownloadAsync (
427
- new HttpRequestMessage ( HttpMethod . Get , url ) , destPath ,
428
- NullDownloadValidator . Instance , smallerCt ) ) ;
429
- }
430
-
431
415
[ Test ( Description = "Timeout on response body" ) ]
432
416
[ CancelAfter ( 30_000 ) ]
433
417
public async Task CancelledInner ( CancellationToken ct )
@@ -479,12 +463,10 @@ public async Task ValidationFailureExistingFile(CancellationToken ct)
479
463
await File . WriteAllTextAsync ( destPath , "test" , ct ) ;
480
464
481
465
var manager = new Downloader ( NullLogger < Downloader > . Instance ) ;
466
+ var dlTask = await manager . StartDownloadAsync ( new HttpRequestMessage ( HttpMethod . Get , url ) , destPath ,
467
+ new TestDownloadValidator ( new Exception ( "test exception" ) ) , ct ) ;
482
468
// The "outer" Task should fail because the inner task never starts.
483
- var ex = Assert . ThrowsAsync < Exception > ( async ( ) =>
484
- {
485
- await manager . StartDownloadAsync ( new HttpRequestMessage ( HttpMethod . Get , url ) , destPath ,
486
- new TestDownloadValidator ( new Exception ( "test exception" ) ) , ct ) ;
487
- } ) ;
469
+ var ex = Assert . ThrowsAsync < Exception > ( async ( ) => { await dlTask . Task ; } ) ;
488
470
Assert . That ( ex . Message , Does . Contain ( "Existing file failed validation" ) ) ;
489
471
Assert . That ( ex . InnerException , Is . Not . Null ) ;
490
472
Assert . That ( ex . InnerException ! . Message , Is . EqualTo ( "test exception" ) ) ;
0 commit comments