Skip to content

Enable Http2_MultipleConnectionsEnabled_IdleConnectionTimeoutExpired_ConnectionRemovedAndNewCreated #55019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2185,17 +2185,19 @@ public async Task Http2_MultipleConnectionsEnabled_OpenAndCloseMultipleConnectio
}
}

[ConditionalFact(nameof(SupportsAlpn))]
[OuterLoop("Incurs long delay")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/43877")]
public async Task Http2_MultipleConnectionsEnabled_IdleConnectionTimeoutExpired_ConnectionRemovedAndNewCreated()
[ConditionalTheory(nameof(SupportsAlpn))]
[MemberData(nameof(LongRunning))]
//[OuterLoop("Incurs long delay")]
public async Task Http2_MultipleConnectionsEnabled_IdleConnectionTimeoutExpired_ConnectionRemovedAndNewCreated(int a)
{
Assert.True(a > -1);
const int MaxConcurrentStreams = 2;
using Http2LoopbackServer server = Http2LoopbackServer.CreateServer();
using SocketsHttpHandler handler = CreateHandler();
handler.PooledConnectionIdleTimeout = TimeSpan.FromSeconds(20);
using (HttpClient client = CreateHttpClient(handler))
{
client.Timeout = TimeSpan.FromSeconds(40);
server.AllowMultipleConnections = true;
List<Task<HttpResponseMessage>> sendTasks = new List<Task<HttpResponseMessage>>();
Http2LoopbackConnection connection0 = await PrepareConnection(server, client, MaxConcurrentStreams).ConfigureAwait(false);
Expand All @@ -2204,7 +2206,7 @@ public async Task Http2_MultipleConnectionsEnabled_IdleConnectionTimeoutExpired_
Assert.Equal(MaxConcurrentStreams, acceptedStreamIds.Count);

List<Task<HttpResponseMessage>> connection1SendTasks = new List<Task<HttpResponseMessage>>();
Http2LoopbackConnection connection1 = await PrepareConnection(server, client, MaxConcurrentStreams, readTimeout: 30).ConfigureAwait(false);
Http2LoopbackConnection connection1 = await PrepareConnection(server, client, MaxConcurrentStreams, readTimeout: 40).ConfigureAwait(false);
AcquireAllStreamSlots(server, client, connection1SendTasks, MaxConcurrentStreams);
int handledRequests1 = (await HandleAllPendingRequests(connection1, MaxConcurrentStreams).ConfigureAwait(false)).Count;

Expand All @@ -2217,20 +2219,11 @@ public async Task Http2_MultipleConnectionsEnabled_IdleConnectionTimeoutExpired_

// Wait until the idle connection timeout expires.
await connection1.WaitForClientDisconnectAsync(false).WaitAsync(TestHelper.PassingTestTimeout).ConfigureAwait(false);
// Client connection might be still alive, so send an extra request which will either land on the shutting down connection or on a new one.
try
{
await client.GetAsync(server.Address).WaitAsync(handler.PooledConnectionIdleTimeout).ConfigureAwait(false);
}
catch (Exception)
{
// Suppress all exceptions.
}

Assert.True(connection1.IsInvalid);
Assert.False(connection0.IsInvalid);

Http2LoopbackConnection connection2 = await PrepareConnection(server, client, MaxConcurrentStreams, readTimeout: 15, expectedWarmUpTasks:2).ConfigureAwait(false);
Http2LoopbackConnection connection2 = await PrepareConnection(server, client, MaxConcurrentStreams, readTimeout: 2).ConfigureAwait(false);

AcquireAllStreamSlots(server, client, sendTasks, MaxConcurrentStreams);

Expand All @@ -2247,6 +2240,14 @@ public async Task Http2_MultipleConnectionsEnabled_IdleConnectionTimeoutExpired_
}
}

public static IEnumerable<object[]> LongRunning()
{
for(var i = 0; i < 50; i++)
{
yield return new object[] { i };
}
}

private async Task VerifySendTasks(IReadOnlyList<Task<HttpResponseMessage>> sendTasks)
{
foreach (Task<HttpResponseMessage> sendTask in sendTasks)
Expand Down Expand Up @@ -2310,6 +2311,10 @@ private static async Task<Http2LoopbackConnection> GetConnection(Http2LoopbackSe
await connection.SendDefaultResponseAsync(streamId).ConfigureAwait(false);
lastStreamId = streamId;
}
catch (IOException)
{
return (i, lastStreamId);
}
catch (OperationCanceledException)
{
return (i, lastStreamId);
Expand Down