collect system info if IPv6 loopback fails to resolve (dotnet/corefx#35581)
authorTomas Weinfurt <tweinfurt@yahoo.com>
Tue, 26 Feb 2019 23:12:36 +0000 (15:12 -0800)
committerGitHub <noreply@github.com>
Tue, 26 Feb 2019 23:12:36 +0000 (15:12 -0800)
* 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

src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs

index 812b0d8..d0dab1c 100644 (file)
@@ -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);
         }