From f8f747216154441d7c9054b16154a15e4bc46de6 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sat, 29 Feb 2020 09:31:55 +1300 Subject: [PATCH] Fix flaky stream pool test (#19425) --- .../Http2/Http2ConnectionTests.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs index 857c9a3e96..b0007a6a0d 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs @@ -108,12 +108,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task StreamPool_MultipleStreamsInSequence_PooledStreamReused() { - await InitializeConnectionAsync(_echoApplication); + TaskCompletionSource appDelegateTcs = null; + + await InitializeConnectionAsync(async context => + { + await appDelegateTcs.Task; + }); Assert.Equal(0, _connection.StreamPool.Count); + appDelegateTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await StartStreamAsync(1, _browserRequestHeaders, endStream: true); + appDelegateTcs.TrySetResult(null); + await ExpectAsync(Http2FrameType.HEADERS, withLength: 55, withFlags: (byte)(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM), @@ -129,16 +137,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests // Stream has been returned to the pool Assert.Equal(1, _connection.StreamPool.Count); + appDelegateTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await StartStreamAsync(3, _browserRequestHeaders, endStream: true); + // New stream has been taken from the pool + Assert.Equal(0, _connection.StreamPool.Count); + + appDelegateTcs.TrySetResult(null); + await ExpectAsync(Http2FrameType.HEADERS, withLength: 55, withFlags: (byte)(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM), withStreamId: 3); - // New stream has been taken from the pool - Assert.Equal(0, _connection.StreamPool.Count); - // Ping will trigger the stream to be returned to the pool so we can assert it await SendPingAsync(Http2PingFrameFlags.NONE); await ExpectAsync(Http2FrameType.PING,