Skip to content

Commit 3876cec

Browse files
authored
[browser] improve HTTP abort test (#118274)
1 parent 9732798 commit 3876cec

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,18 @@ public async Task BrowserHttpHandler_StreamingResponseAbort(HttpMethod method, s
319319
using HttpClient client = CreateHttpClientForRemoteServer(Configuration.Http.RemoteHttp11Server);
320320
if (abort == "abortDuringBody")
321321
{
322-
using var res = await client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead);
322+
HttpResponseMessage res;
323+
try
324+
{
325+
res = await client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead);
326+
}
327+
catch (HttpRequestException)
328+
{
329+
// sometimes the server aborts earlier than the browser is able to return from the non-blocking send/fetch
330+
return;
331+
}
323332
await Assert.ThrowsAsync<HttpRequestException>(() => res.Content.ReadAsByteArrayAsync());
333+
res.Dispose();
324334
}
325335
else
326336
{

src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/EchoHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static async Task InvokeAsync(HttpContext context)
8585
if (qs.Contains("abortDuringBody"))
8686
{
8787
await context.Response.Body.FlushAsync();
88-
await Task.Delay(10);
88+
await Task.Delay(100);
8989
context.Abort();
9090
return;
9191
}

0 commit comments

Comments
 (0)