From e5b2b680e07ec6142bfd0f2ca39592f1acf85b2f Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 7 Sep 2018 18:18:02 -0700 Subject: [PATCH] Fix flaky test by ignoring indeterminant response --- test/Kestrel.FunctionalTests/ChunkedRequestTests.cs | 2 +- test/shared/TestConnection.cs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs b/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs index 10b68fdf45..ecbb6f23b2 100644 --- a/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs +++ b/test/Kestrel.FunctionalTests/ChunkedRequestTests.cs @@ -678,7 +678,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests connection.Socket.Shutdown(SocketShutdown.Send); - await connection.ReceiveEnd(); + await connection.ReceiveEnd(ignoreResponse: true); var badReqEx = await exTcs.Task.TimeoutAfter(TestConstants.DefaultTimeout); Assert.Equal(RequestRejectionReason.UnexpectedEndOfRequestContent, badReqEx.Reason); diff --git a/test/shared/TestConnection.cs b/test/shared/TestConnection.cs index 2d760a5bc8..6469dd2d19 100644 --- a/test/shared/TestConnection.cs +++ b/test/shared/TestConnection.cs @@ -149,14 +149,20 @@ namespace Microsoft.AspNetCore.Testing Assert.Equal(expected, new string(actual, 0, offset)); } - public async Task ReceiveEnd(params string[] lines) + public Task ReceiveEnd(params string[] lines) + => ReceiveEnd(false, lines); + + public async Task ReceiveEnd(bool ignoreResponse, params string[] lines) { await Receive(lines).ConfigureAwait(false); _socket.Shutdown(SocketShutdown.Send); var ch = new char[128]; var count = await _reader.ReadAsync(ch, 0, 128).TimeoutAfter(Timeout).ConfigureAwait(false); - var text = new string(ch, 0, count); - Assert.Equal("", text); + if (!ignoreResponse) + { + var text = new string(ch, 0, count); + Assert.Equal("", text); + } } public async Task ReceiveForcedEnd(params string[] lines)