Skip to content
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

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

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
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
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 @@ -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)
{
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;
}
}
}
}
Loading