From 10a54402373821c95495a0b7672df30c6044f452 Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Tue, 26 Feb 2019 15:12:36 -0800 Subject: [PATCH] collect system info if IPv6 loopback fails to resolve (dotnet/corefx#35581) * collect system info if IPv6 loopback fails to resolve * add emply line after } to comply with style Commit migrated from https://github.com/dotnet/corefx/commit/77cde697f9ee9941bdc76e02b9481d781790e86a --- .../tests/PalTests/NameResolutionPalTests.cs | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs index 812b0d8..d0dab1c 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs @@ -2,18 +2,32 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.IO; using System.Net.Sockets; using System.Net.Test.Common; using System.Runtime.InteropServices; using Xunit; +using Xunit.Abstractions; namespace System.Net.NameResolution.PalTests { public class NameResolutionPalTests { - static NameResolutionPalTests() + private ITestOutputHelper _output; + + public NameResolutionPalTests(ITestOutputHelper output) { NameResolutionPal.EnsureSocketsAreInitialized(); + _output = output; + } + + private void LogUnixInfo() + { + _output.WriteLine("--- /etc/hosts ---"); + _output.WriteLine(File.ReadAllText("/etc/hosts")); + _output.WriteLine("--- /etc/resolv.conf ---"); + _output.WriteLine(File.ReadAllText("/etc/resolv.conf")); + _output.WriteLine("------"); } [Fact] @@ -75,6 +89,11 @@ namespace System.Net.NameResolution.PalTests SocketError error; int nativeErrorCode; string name = NameResolutionPal.TryGetNameInfo(new IPAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }), out error, out nativeErrorCode); + if (SocketError.Success != error && Environment.OSVersion.Platform == PlatformID.Unix) + { + LogUnixInfo(); + } + Assert.Equal(SocketError.Success, error); Assert.NotNull(name); } @@ -160,11 +179,21 @@ namespace System.Net.NameResolution.PalTests SocketError error; int nativeErrorCode; string name = NameResolutionPal.TryGetNameInfo(new IPAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }), out error, out nativeErrorCode); + if (SocketError.Success != error && Environment.OSVersion.Platform == PlatformID.Unix) + { + LogUnixInfo(); + } + Assert.Equal(SocketError.Success, error); Assert.NotNull(name); IPHostEntry hostEntry; error = NameResolutionPal.TryGetAddrInfo(name, out hostEntry, out nativeErrorCode); + if (SocketError.Success != error && Environment.OSVersion.Platform == PlatformID.Unix) + { + LogUnixInfo(); + } + Assert.Equal(SocketError.Success, error); Assert.NotNull(hostEntry); } -- 2.7.4