Skip to content

Commit

Permalink
Disable IPV6 cases of QuicConnectionTests.TestConnect when IPv6 loopb…
Browse files Browse the repository at this point in the history
…ack is disabled (#98999)

* Disable IPV6 cases of QuicConnectionTests.TestConnect on non-ipv6 systems

* Move check for IPv6 loopback availability to Configuration.Sockets
  • Loading branch information
rzikm authored Feb 29, 2024
1 parent 70eae70 commit 806d11e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
19 changes: 18 additions & 1 deletion src/libraries/Common/tests/System/Net/Configuration.Sockets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static IEnumerable<object[]> LocalAddresses()
{
yield return new[] { IPAddress.Loopback };
}
if (Socket.OSSupportsIPv6)
if (Socket.OSSupportsIPv6 && IsIPv6LoopbackAvailable)
{
yield return new[] { IPAddress.IPv6Loopback };
}
Expand All @@ -46,6 +46,23 @@ private static IPAddress GetIPv6LinkLocalAddress() =>
.Select(a => a.Address)
.Where(a => a.IsIPv6LinkLocal)
.FirstOrDefault();

private static readonly Lazy<bool> _isIPv6LoopbackAvailable = new Lazy<bool>(GetIsIPv6LoopbackAvailable);
public static bool IsIPv6LoopbackAvailable => _isIPv6LoopbackAvailable.Value;

private static bool GetIsIPv6LoopbackAvailable()
{
try
{
using Socket s = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
s.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 0));
return true;
}
catch (SocketException)
{
return false;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -23,7 +24,7 @@ public sealed class QuicConnectionTests : QuicTestBase

public QuicConnectionTests(ITestOutputHelper output) : base(output) { }

[Theory]
[ConditionalTheory]
[MemberData(nameof(LocalAddresses))]
public async Task TestConnect(IPAddress address)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace System.Net.Quic.Tests
{
using Configuration = System.Net.Test.Common.Configuration;

public abstract class QuicTestBase : IDisposable
{
public const long DefaultStreamErrorCodeClient = 123456;
Expand All @@ -31,8 +33,7 @@ public abstract class QuicTestBase : IDisposable
public static bool IsSupported => QuicListener.IsSupported && QuicConnection.IsSupported;
public static bool IsNotArm32CoreClrStressTest => !(CoreClrConfigurationDetection.IsStressTest && PlatformDetection.IsArmProcess);

private static readonly Lazy<bool> _isIPv6Available = new Lazy<bool>(GetIsIPv6Available);
public static bool IsIPv6Available => _isIPv6Available.Value;
public static bool IsIPv6Available => Configuration.Sockets.IsIPv6LoopbackAvailable;

public static SslApplicationProtocol ApplicationProtocol { get; } = new SslApplicationProtocol("quictest");

Expand Down Expand Up @@ -375,19 +376,5 @@ internal static async Task<int> WriteForever(QuicStream stream, int size = 1)
ArrayPool<byte>.Shared.Return(buffer);
}
}

internal static bool GetIsIPv6Available()
{
try
{
using Socket s = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
s.Bind(new IPEndPoint(IPAddress.IPv6Loopback, 0));
return true;
}
catch (SocketException)
{
return false;
}
}
}
}

0 comments on commit 806d11e

Please sign in to comment.