Skip to content

Commit 4ce05af

Browse files
author
ladeak
committed
MultipleWrites_HeaderFrame_ReservedFrame modified: in case the server completed earlier (because it wasn't reading the input data), then it closed the connection. The second flush might have run into a completed stream, causing a test error.
#52
1 parent 302a3ba commit 4ce05af

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

tests/CHttpServer.Tests/Http3/Http3StreamTests.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Net.Quic;
1+
using System.Diagnostics;
2+
using System.Net.Quic;
23
using CHttpServer.Http3;
34
using Microsoft.AspNetCore.Http.Features;
45

@@ -112,37 +113,38 @@ public async Task SingleWrite_HeaderFrame_ReservedFrame()
112113
public async Task MultipleWrites_HeaderFrame_ReservedFrame()
113114
{
114115
byte[] data = [.. Http3FrameFixture.GetHeadersFrame(), .. Http3FrameFixture.GetReservedFrame(10)];
115-
var quicConnection = await QuicConnectionFixture.SetupConnectionAsync(Port, TestContext.Current.CancellationToken);
116+
await using var quicConnection = await QuicConnectionFixture.SetupConnectionAsync(Port, TestContext.Current.CancellationToken);
116117
for (int i = 1; i < data.Length; i++)
117118
{
118119
var serverStreamTask = Task.Run(async () => await quicConnection.ServerConnection.AcceptInboundStreamAsync());
119120
var sut = new Http3Stream([]);
120121

121-
var clientStream = await quicConnection.ClientConnection.OpenOutboundStreamAsync(QuicStreamType.Bidirectional, TestContext.Current.CancellationToken);
122+
await using var clientStream = await quicConnection.ClientConnection.OpenOutboundStreamAsync(QuicStreamType.Bidirectional, TestContext.Current.CancellationToken);
122123
await clientStream.WriteAsync(data.AsMemory(0, i), TestContext.Current.CancellationToken);
123124
await clientStream.FlushAsync(TestContext.Current.CancellationToken);
124125

125-
TaskCompletionSource tcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
126+
TaskCompletionSource secondFlushCompleted = new(TaskCreationOptions.RunContinuationsAsynchronously);
126127
sut.Initialize(null, await serverStreamTask);
127-
var testApp = new TestBase.TestApplication(ctx =>
128+
var testApp = new TestBase.TestApplication(async ctx =>
128129
{
129130
Assert.Equal("/", ctx.Request.Path);
130131
Assert.Equal("https", ctx.Request.Scheme);
131132
Assert.Equal("localhost", ctx.Request.Host.ToString());
132133
Assert.Equal(HttpMethod.Get.ToString(), ctx.Request.Method);
133-
tcs.SetResult();
134-
return Task.CompletedTask;
134+
135+
// This callback shall not complete before the 2nd flush, otherwise the
136+
// server might close the stream before the flush succeeds.
137+
await secondFlushCompleted.Task;
135138
});
136139
var processing = sut.ProcessStreamAsync(testApp, TestContext.Current.CancellationToken);
137140

138141
await clientStream.WriteAsync(data.AsMemory(i), TestContext.Current.CancellationToken);
139142
await clientStream.FlushAsync(TestContext.Current.CancellationToken);
143+
secondFlushCompleted.SetResult();
140144

141-
await tcs.Task.WaitAsync(DefaultTimeout, TestContext.Current.CancellationToken);
142-
clientStream.Close();
143145
await processing;
146+
clientStream.Close();
144147
}
145-
await quicConnection.DisposeAsync();
146148
}
147149

148150
[Fact]

0 commit comments

Comments
 (0)