Skip to content

Commit

Permalink
Fix Http2 MultiConnection test race conditions (#91156)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan authored Aug 29, 2023
1 parent 4c01386 commit 36cf0e4
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@

using System.IO;
using System.Net.Quic;
using System.Net.Sockets;
using System.Net.Test.Common;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

namespace System.Net.Http.Functional.Tests
{
public abstract partial class HttpClientHandlerTestBase : FileCleanupTestBase
{
protected static async Task<Stream> DefaultConnectCallback(EndPoint endPoint, CancellationToken cancellationToken)
{
Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
try
{
await socket.ConnectAsync(endPoint, cancellationToken);
return new NetworkStream(socket, ownsSocket: true);
}
catch
{
socket.Dispose();
throw;
}
}

protected static bool IsWinHttpHandler => false;

public static bool IsQuicSupported
Expand Down
13 changes: 2 additions & 11 deletions src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,8 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
GetUnderlyingSocketsHttpHandler(Handler).ConnectCallback = async (ctx, cancellationToken) =>
{
connectionStarted.SetResult();
Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
try
{
await socket.ConnectAsync(ctx.DnsEndPoint, cancellationToken);
return new NetworkStream(socket, ownsSocket: true);
}
catch
{
socket.Dispose();
throw;
}

return await DefaultConnectCallback(ctx.DnsEndPoint, cancellationToken);
};

// Enable recording request-duration to test the path with metrics enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
else
{
// Succeed the second connection attempt
Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
await socket.ConnectAsync(context.DnsEndPoint, token);
return new NetworkStream(socket, ownsSocket: true);
return await DefaultConnectCallback(context.DnsEndPoint, token);
}
};

Expand Down
Loading

0 comments on commit 36cf0e4

Please sign in to comment.