Skip to content

Commit 876840c

Browse files
authored
Add ResponseBodyWriterCompleteFlushesChunkTerminator test (#26161)
1 parent eb3a719 commit 876840c

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ await InitializeConnectionAsync(context =>
12341234
withFlags: (byte)(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM),
12351235
withStreamId: 1);
12361236

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

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

@@ -1654,7 +1654,7 @@ await ExpectAsync(Http2FrameType.DATA,
16541654
withFlags: (byte)Http2DataFrameFlags.NONE,
16551655
withStreamId: 1);
16561656

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

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

src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseTests.cs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ await connection.Receive(
878878
It.IsAny<string>(),
879879
It.IsAny<string>(),
880880
It.Is<InvalidOperationException>(ex =>
881-
ex.Message.Equals($"Response Content-Length mismatch: too few bytes written (12 of 13).", StringComparison.Ordinal))));
881+
ex.Message.Equals(CoreStrings.FormatTooFewBytesWritten(12, 13), StringComparison.Ordinal))));
882882
}
883883

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

941941
Assert.NotNull(completeEx);
942942
}
@@ -1025,7 +1025,7 @@ await connection.Receive(
10251025

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

10311031
[Theory]
@@ -3550,7 +3550,7 @@ await connection.Receive(
35503550
}
35513551

35523552
[Fact]
3553-
public async Task ResponseBodyWriterCompleteWithoutExceptionWritesDoesThrow()
3553+
public async Task ResponseBodyWriterCompleteWithoutExceptionNextWriteDoesThrow()
35543554
{
35553555
InvalidOperationException writeEx = null;
35563556

@@ -3580,6 +3580,40 @@ await connection.Receive(
35803580
Assert.NotNull(writeEx);
35813581
}
35823582

3583+
[Fact]
3584+
public async Task ResponseBodyWriterCompleteFlushesChunkTerminator()
3585+
{
3586+
var middlewareCompletionTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
3587+
3588+
await using var server = new TestServer(async httpContext =>
3589+
{
3590+
await httpContext.Response.WriteAsync("hello, world");
3591+
await httpContext.Response.BodyWriter.CompleteAsync();
3592+
await middlewareCompletionTcs.Task;
3593+
}, new TestServiceContext(LoggerFactory));
3594+
3595+
using var connection = server.CreateConnection();
3596+
3597+
await connection.Send(
3598+
"GET / HTTP/1.1",
3599+
"Host:",
3600+
"",
3601+
"");
3602+
3603+
await connection.Receive(
3604+
"HTTP/1.1 200 OK",
3605+
$"Date: {server.Context.DateHeaderValue}",
3606+
"Transfer-Encoding: chunked",
3607+
"",
3608+
"c",
3609+
"hello, world",
3610+
"0",
3611+
"",
3612+
"");
3613+
3614+
middlewareCompletionTcs.SetResult();
3615+
}
3616+
35833617
[Fact]
35843618
public async Task ResponseAdvanceStateIsResetWithMultipleReqeusts()
35853619
{
@@ -3912,7 +3946,6 @@ await connection.Receive(
39123946
}
39133947
}
39143948

3915-
39163949
[Fact]
39173950
public async Task ResponseGetMemoryAndStartAsyncAdvanceThrows()
39183951
{

0 commit comments

Comments
 (0)