From 30870b34c0d0c2183f8c123ea4b1613078a0b6d7 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Fri, 19 Oct 2018 12:36:08 -0700 Subject: [PATCH] Fix abort race in response body tests #451 --- .../Listener/ResponseBodyTests.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseBodyTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseBodyTests.cs index 4632c8e..044c6cf 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseBodyTests.cs @@ -221,12 +221,13 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener var cts = new CancellationTokenSource(); // First write sends headers await context.Response.Body.WriteAsync(new byte[10], 0, 10, cts.Token); + var response = await responseTask; cts.Cancel(); var writeTask = context.Response.Body.WriteAsync(new byte[10], 0, 10, cts.Token); Assert.True(writeTask.IsCanceled); context.Dispose(); - await Assert.ThrowsAsync(() => responseTask); + await Assert.ThrowsAsync(() => response.Content.LoadIntoBufferAsync()); } } @@ -242,12 +243,13 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener var cts = new CancellationTokenSource(); // First write sends headers await context.Response.Body.WriteAsync(new byte[10], 0, 10, cts.Token); + var response = await responseTask; cts.Cancel(); var writeTask = context.Response.Body.WriteAsync(new byte[10], 0, 10, cts.Token); Assert.True(writeTask.IsCanceled); context.Dispose(); - await Assert.ThrowsAsync(() => responseTask); + await Assert.ThrowsAsync(() => response.Content.LoadIntoBufferAsync()); } } @@ -492,9 +494,9 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener private async Task SendRequestAsync(string uri, CancellationToken cancellationToken = new CancellationToken()) { - using (HttpClient client = new HttpClient()) + using (HttpClient client = new HttpClient() { Timeout = Utilities.DefaultTimeout }) { - return await client.GetAsync(uri, cancellationToken); + return await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, cancellationToken); } } }