Fix ReaderThrowsResetExceptionOnInvalidBody (#1420)
This commit is contained in:
parent
d28468ca8f
commit
d463b5e613
|
|
@ -62,18 +62,15 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
|||
|
||||
public async Task Send(params string[] lines)
|
||||
{
|
||||
var text = string.Join("\r\n", lines);
|
||||
var writer = new StreamWriter(_stream, Encoding.GetEncoding("iso-8859-1"));
|
||||
for (var index = 0; index < text.Length; index++)
|
||||
var bytes = Encoding.ASCII.GetBytes(string.Join("\r\n", lines));
|
||||
|
||||
for (var index = 0; index < bytes.Length; index++)
|
||||
{
|
||||
var ch = text[index];
|
||||
writer.Write(ch);
|
||||
await writer.FlushAsync().ConfigureAwait(false);
|
||||
await _stream.WriteAsync(bytes, index, 1).ConfigureAwait(false);
|
||||
await _stream.FlushAsync().ConfigureAwait(false);
|
||||
// Re-add delay to help find socket input consumption bugs more consistently
|
||||
//await Task.Delay(TimeSpan.FromMilliseconds(5));
|
||||
}
|
||||
await writer.FlushAsync().ConfigureAwait(false);
|
||||
await _stream.FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<int> ReadCharAsync()
|
||||
|
|
|
|||
|
|
@ -206,6 +206,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
[ConditionalFact]
|
||||
public async Task ReaderThrowsResetExceptionOnInvalidBody()
|
||||
{
|
||||
var requestStartedCompletionSource = CreateTaskCompletionSource();
|
||||
var requestCompletedCompletionSource = CreateTaskCompletionSource();
|
||||
|
||||
Exception exception = null;
|
||||
|
|
@ -213,6 +214,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
var data = new byte[1024];
|
||||
using (var testServer = await TestServer.Create(async ctx =>
|
||||
{
|
||||
requestStartedCompletionSource.SetResult(true);
|
||||
try
|
||||
{
|
||||
await ctx.Request.Body.ReadAsync(data);
|
||||
|
|
@ -233,10 +235,19 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
"Host: localhost",
|
||||
"Connection: close",
|
||||
"",
|
||||
"ZZZ",
|
||||
"");
|
||||
await requestCompletedCompletionSource.Task.DefaultTimeout();
|
||||
|
||||
await requestStartedCompletionSource.Task;
|
||||
await connection.Send(
|
||||
"ZZZZZZZZZZZZZ");
|
||||
|
||||
await connection.Receive(
|
||||
"HTTP/1.1 400 Bad Request",
|
||||
""
|
||||
);
|
||||
|
||||
}
|
||||
await requestCompletedCompletionSource.Task.DefaultTimeout();
|
||||
}
|
||||
|
||||
Assert.IsType<ConnectionResetException>(exception);
|
||||
|
|
|
|||
Loading…
Reference in New Issue