From 019ba081d38b5410aa0c7808275c0fd78d8f32fc Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 14 Dec 2018 16:26:54 -0800 Subject: [PATCH] Fix flakiness in RequestsCanBeAbortedMidRead (#4881) Addresses aspnet/AspNetCore-Internal#1521 --- src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs b/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs index b528e80b3a95..aad4f50deb13 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs @@ -1206,7 +1206,12 @@ await connection.Send("POST / HTTP/1.1", } } - await Assert.ThrowsAsync(async () => await readTcs.Task); + var thrownEx = await Assert.ThrowsAnyAsync(async () => await readTcs.Task); + + // https://github.com/aspnet/AspNetCore-Internal/issues/1521 + // In more recent versions of Kestrel, we expect this to always be a TaskCanceledException, + // but without the changes in https://github.com/aspnet/KestrelHttpServer/pull/2844, this is flaky. + Assert.True(thrownEx is TaskCanceledException || thrownEx is IOException, $"{thrownEx} is neither a TaskCanceledException nor IOException."); // The cancellation token for only the last request should be triggered. var abortedRequestId = await registrationTcs.Task;