Fix Sending100ContinueDoesNotStartResponse #2507

This commit is contained in:
Chris Ross (ASP.NET) 2018-03-26 12:50:36 -07:00
parent 74d19cd4e4
commit b85ab0a7d2
1 changed files with 23 additions and 6 deletions

View File

@ -1635,8 +1635,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
} }
[Fact] [Fact]
public async Task Sending100ContinueDoesNotStartResponse() public async Task RequestDrainingFor100ContinueDoesNotBlockResponse()
{ {
var foundMessage = false;
using (var server = new TestServer(httpContext => using (var server = new TestServer(httpContext =>
{ {
return httpContext.Request.Body.ReadAsync(new byte[1], 0, 1); return httpContext.Request.Body.ReadAsync(new byte[1], 0, 1);
@ -1675,15 +1676,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
await connection.Send( await connection.Send(
"gg"); "gg");
// If 100 Continue sets HttpProtocol.HasResponseStarted to true, // Wait for the server to drain the request body and log an error.
// a success response will be produced before the server sees the // Time out after 10 seconds
// bad chunk header above, making this test fail. for (int i = 0; i < 10 && !foundMessage; i++)
{
while (TestApplicationErrorLogger.Messages.TryDequeue(out var message))
{
if (message.EventId.Id == 17 && message.LogLevel == LogLevel.Information && message.Exception is BadHttpRequestException
&& ((BadHttpRequestException)message.Exception).StatusCode == StatusCodes.Status400BadRequest)
{
foundMessage = true;
break;
}
}
if (!foundMessage)
{
await Task.Delay(TimeSpan.FromSeconds(1));
}
}
await connection.ReceiveEnd(); await connection.ReceiveEnd();
} }
} }
Assert.Contains(TestApplicationErrorLogger.Messages, w => w.EventId.Id == 17 && w.LogLevel == LogLevel.Information && w.Exception is BadHttpRequestException Assert.True(foundMessage, "Expected log not found");
&& ((BadHttpRequestException)w.Exception).StatusCode == StatusCodes.Status400BadRequest);
} }
[Fact] [Fact]