Fix flaky stream pool test (#19425)
This commit is contained in:
parent
e65408a36c
commit
f8f7472161
|
|
@ -108,12 +108,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task StreamPool_MultipleStreamsInSequence_PooledStreamReused()
|
public async Task StreamPool_MultipleStreamsInSequence_PooledStreamReused()
|
||||||
{
|
{
|
||||||
await InitializeConnectionAsync(_echoApplication);
|
TaskCompletionSource<object> appDelegateTcs = null;
|
||||||
|
|
||||||
|
await InitializeConnectionAsync(async context =>
|
||||||
|
{
|
||||||
|
await appDelegateTcs.Task;
|
||||||
|
});
|
||||||
|
|
||||||
Assert.Equal(0, _connection.StreamPool.Count);
|
Assert.Equal(0, _connection.StreamPool.Count);
|
||||||
|
|
||||||
|
appDelegateTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
await StartStreamAsync(1, _browserRequestHeaders, endStream: true);
|
await StartStreamAsync(1, _browserRequestHeaders, endStream: true);
|
||||||
|
|
||||||
|
appDelegateTcs.TrySetResult(null);
|
||||||
|
|
||||||
await ExpectAsync(Http2FrameType.HEADERS,
|
await ExpectAsync(Http2FrameType.HEADERS,
|
||||||
withLength: 55,
|
withLength: 55,
|
||||||
withFlags: (byte)(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM),
|
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
|
// Stream has been returned to the pool
|
||||||
Assert.Equal(1, _connection.StreamPool.Count);
|
Assert.Equal(1, _connection.StreamPool.Count);
|
||||||
|
|
||||||
|
appDelegateTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
await StartStreamAsync(3, _browserRequestHeaders, endStream: true);
|
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,
|
await ExpectAsync(Http2FrameType.HEADERS,
|
||||||
withLength: 55,
|
withLength: 55,
|
||||||
withFlags: (byte)(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM),
|
withFlags: (byte)(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM),
|
||||||
withStreamId: 3);
|
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
|
// Ping will trigger the stream to be returned to the pool so we can assert it
|
||||||
await SendPingAsync(Http2PingFrameFlags.NONE);
|
await SendPingAsync(Http2PingFrameFlags.NONE);
|
||||||
await ExpectAsync(Http2FrameType.PING,
|
await ExpectAsync(Http2FrameType.PING,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue