Skip to content

Commit 3b5554d

Browse files
committed
PR feedback
1 parent 910b9b2 commit 3b5554d

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/Servers/Kestrel/test/Interop.FunctionalTests/Http2/Http2RequestTests.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,70 @@ public async Task GET_NoTLS_Http11RequestToHttp2Endpoint_400Result()
219219
}
220220
}
221221

222+
[Theory(Skip = "https://github.com/dotnet/aspnetcore/issues/41074")]
223+
[InlineData(true)]
224+
[InlineData(false)]
225+
public async Task GET_RequestReturnsLargeData_GracefulShutdownDuringRequest_RequestGracefullyCompletes(bool hasTrailers)
226+
{
227+
// Enable client logging.
228+
// Test failure on CI could be from HttpClient bug.
229+
using var httpEventSource = new HttpEventSourceListener(LoggerFactory);
230+
231+
// Arrange
232+
const int DataLength = 500_000;
233+
var randomBytes = Enumerable.Range(1, DataLength).Select(i => (byte)((i % 10) + 48)).ToArray();
234+
235+
var syncPoint = new SyncPoint();
236+
237+
ILogger logger = null;
238+
var builder = CreateHostBuilder(
239+
async c =>
240+
{
241+
await syncPoint.WaitToContinue();
242+
var memory = c.Response.BodyWriter.GetMemory(randomBytes.Length);
243+
logger.LogInformation($"Server writing {randomBytes.Length} bytes response");
244+
randomBytes.CopyTo(memory);
245+
// It's important for this test that the large write is the last data written to
246+
// the response and it's not awaited by the request delegate.
247+
logger.LogInformation($"Server advancing {randomBytes.Length} bytes response");
248+
c.Response.BodyWriter.Advance(randomBytes.Length);
249+
if (hasTrailers)
250+
{
251+
c.Response.AppendTrailer("test-trailer", "value!");
252+
}
253+
},
254+
protocol: HttpProtocols.Http2,
255+
plaintext: true);
256+
257+
using var host = builder.Build();
258+
logger = host.Services.GetRequiredService<ILoggerFactory>().CreateLogger("Test");
259+
260+
var client = HttpHelpers.CreateClient();
261+
262+
// Act
263+
await host.StartAsync().DefaultTimeout();
264+
265+
var longRunningTask = StartLongRunningRequestAsync(logger, host, client);
266+
267+
logger.LogInformation("Waiting for request on server");
268+
await syncPoint.WaitForSyncPoint().DefaultTimeout();
269+
270+
logger.LogInformation("Stopping server");
271+
var stopTask = host.StopAsync();
272+
273+
syncPoint.Continue();
274+
275+
var (readData, trailers) = await longRunningTask.DefaultTimeout();
276+
await stopTask.DefaultTimeout();
277+
278+
// Assert
279+
Assert.Equal(randomBytes, readData);
280+
if (hasTrailers)
281+
{
282+
Assert.Equal("value!", trailers.GetValues("test-trailer").Single());
283+
}
284+
}
285+
222286
private static async Task<(byte[], HttpResponseHeaders)> StartLongRunningRequestAsync(ILogger logger, IHost host, HttpMessageInvoker client)
223287
{
224288
var request = new HttpRequestMessage(HttpMethod.Get, $"http://127.0.0.1:{host.GetPort()}/");

0 commit comments

Comments
 (0)