diff --git a/src/libraries/Common/tests/System/Net/Configuration.Sockets.cs b/src/libraries/Common/tests/System/Net/Configuration.Sockets.cs index f9f9ba1dc17e5d..761998370685d9 100644 --- a/src/libraries/Common/tests/System/Net/Configuration.Sockets.cs +++ b/src/libraries/Common/tests/System/Net/Configuration.Sockets.cs @@ -29,7 +29,7 @@ public static IEnumerable LocalAddresses() { yield return new[] { IPAddress.Loopback }; } - if (Socket.OSSupportsIPv6) + if (Socket.OSSupportsIPv6 && IsIPv6LoopbackAvailable) { yield return new[] { IPAddress.IPv6Loopback }; } @@ -46,6 +46,23 @@ private static IPAddress GetIPv6LinkLocalAddress() => .Select(a => a.Address) .Where(a => a.IsIPv6LinkLocal) .FirstOrDefault(); + + private static readonly Lazy _isIPv6LoopbackAvailable = new Lazy(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; + } + } } } } diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicConnectionTests.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicConnectionTests.cs index f7c70196e6d15e..8f374ff78e7f78 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicConnectionTests.cs +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicConnectionTests.cs @@ -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; @@ -22,7 +23,7 @@ public sealed class QuicConnectionTests : QuicTestBase public QuicConnectionTests(ITestOutputHelper output) : base(output) { } - [Theory] + [ConditionalTheory] [MemberData(nameof(LocalAddresses))] public async Task TestConnect(IPAddress address) { diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs index d85cf0e5ed3d9b..c3e0e4e7372aba 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/QuicTestBase.cs @@ -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; @@ -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 _isIPv6Available = new Lazy(GetIsIPv6Available); - public static bool IsIPv6Available => _isIPv6Available.Value; + public static bool IsIPv6Available => Configuration.Sockets.IsIPv6LoopbackAvailable; public static SslApplicationProtocol ApplicationProtocol { get; } = new SslApplicationProtocol("quictest"); @@ -375,19 +376,5 @@ internal static async Task WriteForever(QuicStream stream, int size = 1) ArrayPool.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; - } - } } }