Tweak diagnostics for Dns_GetHostEntry_HostString_Ok failures in CI (dotnet/corefx...
authorStephen Toub <stoub@microsoft.com>
Mon, 24 Jun 2019 21:21:07 +0000 (17:21 -0400)
committerGitHub <noreply@github.com>
Mon, 24 Jun 2019 21:21:07 +0000 (17:21 -0400)
Gather more details when Dns.GetHostEntry("") fails in CI with "Name or service not known".

Commit migrated from https://github.com/dotnet/corefx/commit/ba5c2769a01a8480824ce1b3a3cf40408325ff94

src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs

index dd2a48d..2bc1b65 100644 (file)
@@ -35,23 +35,36 @@ namespace System.Net.NameResolution.Tests
             {
                 // Additional data for debugging sporadic CI failures #24355
                 string actualHostName = Dns.GetHostName();
-                bool getHostEntrySuccess = false;
                 string etcHosts = "";
+                Exception getHostEntryException = null;
+                Exception etcHostsException = null;
+
                 try
                 {
                     Dns.GetHostEntry(actualHostName);
-                    getHostEntrySuccess = true;
+                }
+                catch (Exception e2)
+                {
+                    getHostEntryException = e2;
+                }
+
+                try
+                {
                     if (Environment.OSVersion.Platform != PlatformID.Win32NT)
                     {
                         etcHosts = File.ReadAllText("/etc/hosts");
                     }
                 }
-                catch { }
+                catch (Exception e2)
+                {
+                    etcHostsException = e2;
+                }
 
                 throw new Exception(
                     $"Failed for empty hostname.{Environment.NewLine}" +
                     $"Dns.GetHostName() == {actualHostName}{Environment.NewLine}" +
-                    $"{nameof(getHostEntrySuccess)}=={getHostEntrySuccess}{Environment.NewLine}" +
+                    $"{nameof(getHostEntryException)}=={getHostEntryException}{Environment.NewLine}" +
+                    $"{nameof(etcHostsException)}=={etcHostsException}{Environment.NewLine}" +
                     $"/etc/host =={Environment.NewLine}{etcHosts}",
                     ex);
             }