Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ResponseBodyWriterCompleteFlushesChunkTerminator test #26161

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ await InitializeConnectionAsync(context =>
withFlags: (byte)(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM),
withStreamId: 1);

Assert.Contains(TestApplicationErrorLogger.Messages, m => m.Exception?.Message.Contains("Response Content-Length mismatch: too few bytes written (0 of 11).") ?? false);
Assert.Contains(TestApplicationErrorLogger.Messages, m => m.Exception?.Message.Contains(CoreStrings.FormatTooFewBytesWritten(0, 11)) ?? false);

await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);

Expand Down Expand Up @@ -1654,7 +1654,7 @@ await ExpectAsync(Http2FrameType.DATA,
withFlags: (byte)Http2DataFrameFlags.NONE,
withStreamId: 1);

await WaitForStreamErrorAsync(1, Http2ErrorCode.INTERNAL_ERROR, "Response Content-Length mismatch: too few bytes written (6 of 11).");
await WaitForStreamErrorAsync(1, Http2ErrorCode.INTERNAL_ERROR, CoreStrings.FormatTooFewBytesWritten(6, 11));

await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);

Expand Down
43 changes: 38 additions & 5 deletions src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ await connection.Receive(
It.IsAny<string>(),
It.IsAny<string>(),
It.Is<InvalidOperationException>(ex =>
ex.Message.Equals($"Response Content-Length mismatch: too few bytes written (12 of 13).", StringComparison.Ordinal))));
ex.Message.Equals(CoreStrings.FormatTooFewBytesWritten(12, 13), StringComparison.Ordinal))));
}

[Fact]
Expand Down Expand Up @@ -936,7 +936,7 @@ await connection.Receive(
It.IsAny<string>(),
It.IsAny<string>(),
It.Is<InvalidOperationException>(ex =>
ex.Message.Equals($"Response Content-Length mismatch: too few bytes written (12 of 13).", StringComparison.Ordinal))));
ex.Message.Equals(CoreStrings.FormatTooFewBytesWritten(12, 13), StringComparison.Ordinal))));

Assert.NotNull(completeEx);
}
Expand Down Expand Up @@ -1025,7 +1025,7 @@ await connection.Receive(

var error = TestApplicationErrorLogger.Messages.Where(message => message.LogLevel == LogLevel.Error);
Assert.Equal(2, error.Count());
Assert.All(error, message => message.Message.Equals("Response Content-Length mismatch: too few bytes written (0 of 5)."));
Assert.All(error, message => message.Message.Equals(CoreStrings.FormatTooFewBytesWritten(0, 5)));
}

[Theory]
Expand Down Expand Up @@ -3550,7 +3550,7 @@ await connection.Receive(
}

[Fact]
public async Task ResponseBodyWriterCompleteWithoutExceptionWritesDoesThrow()
public async Task ResponseBodyWriterCompleteWithoutExceptionNextWriteDoesThrow()
{
InvalidOperationException writeEx = null;

Expand Down Expand Up @@ -3580,6 +3580,40 @@ await connection.Receive(
Assert.NotNull(writeEx);
}

[Fact]
public async Task ResponseBodyWriterCompleteFlushesChunkTerminator()
{
var middlewareCompletionTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

await using var server = new TestServer(async httpContext =>
{
await httpContext.Response.WriteAsync("hello, world");
await httpContext.Response.BodyWriter.CompleteAsync();
await middlewareCompletionTcs.Task;
}, new TestServiceContext(LoggerFactory));

using var connection = server.CreateConnection();

await connection.Send(
"GET / HTTP/1.1",
"Host:",
"",
"");

await connection.Receive(
"HTTP/1.1 200 OK",
$"Date: {server.Context.DateHeaderValue}",
"Transfer-Encoding: chunked",
"",
"c",
"hello, world",
"0",
"",
"");

middlewareCompletionTcs.SetResult();
}

[Fact]
public async Task ResponseAdvanceStateIsResetWithMultipleReqeusts()
{
Expand Down Expand Up @@ -3912,7 +3946,6 @@ await connection.Receive(
}
}


[Fact]
public async Task ResponseGetMemoryAndStartAsyncAdvanceThrows()
{
Expand Down