diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs index d1073db5d3986..c27d3d0c403f8 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -13,6 +14,20 @@ namespace System.Net.NameResolution.Tests { public class GetHostAddressesTest { + [Fact] + public void TestLocalhostAddresses() + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + IPAddress[] addresses = Dns.GetHostAddresses("localhost"); + if (addresses.Length > 1) + { + string localhostResolvesTo = string.Join(',', addresses.Select(a => a.ToString())); + throw new Exception(localhostResolvesTo); + } + } + } + [Fact] public Task Dns_GetHostAddressesAsync_HostString_Ok() => TestGetHostAddressesAsync(() => Dns.GetHostAddressesAsync(TestSettings.LocalHost));