improve resiliency of process tests (#35584)
authorTomas Weinfurt <tweinfurt@yahoo.com>
Thu, 30 Apr 2020 19:16:33 +0000 (12:16 -0700)
committerGitHub <noreply@github.com>
Thu, 30 Apr 2020 19:16:33 +0000 (12:16 -0700)
* impove resiliency of process tests

* feedback from review

* dispose process

Co-authored-by: Tomas Weinfurt <furt@Shining.local>
src/libraries/System.Diagnostics.Process/tests/Helpers.cs
src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs
src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs

index f762e00..0e12a1e 100644 (file)
@@ -12,6 +12,8 @@ namespace System.Diagnostics.Tests
 {
     internal static class Helpers
     {
+        public const int PassingTestTimeoutMilliseconds = 60_000;
+
         public static async Task RetryWithBackoff(Action action, int delayInMilliseconds = 10, int times = 10)
         {
             // Guards against delay growing to an exceptionally large value. No special technical significance to
@@ -36,5 +38,15 @@ namespace System.Diagnostics.Tests
                 }
             }
         }
+
+        public static void DumpAllProcesses()
+        {
+            Process[] all = Process.GetProcesses();
+            foreach (Process p in all)
+            {
+                Console.WriteLine("{0,8} {1}", p.Id, p.ProcessName);
+                p.Dispose();
+            }
+        }
     }
 }
index 4e38d97..1944afa 100644 (file)
@@ -817,7 +817,7 @@ namespace System.Diagnostics.Tests
         {
             // In this test, we kill a process in a way the Process instance
             // is not aware the process has terminated when we invoke Process.Kill.
-
+            DateTime start = DateTime.UtcNow;
             using (Process nonChildProcess = CreateNonChildProcess())
             {
                 // Kill the process.
@@ -833,6 +833,15 @@ namespace System.Diagnostics.Tests
                         // process still exists, wait some time.
                         await Task.Delay(100);
                     }
+
+                    DateTime now = DateTime.UtcNow;
+                    if (start.Ticks + (Helpers.PassingTestTimeoutMilliseconds * 10_000) <= now.Ticks)
+                    {
+                        Console.WriteLine("{0} Failed to kill process {1} started at {2}", now, nonChildProcess.Id, start);
+                        Helpers.DumpAllProcesses();
+
+                        Assert.True(false, "test timed out");
+                    }
                 }
 
                 // Call Process.Kill.
index 1b5eb65..167776c 100644 (file)
@@ -2119,7 +2119,7 @@ namespace System.Diagnostics.Tests
             Process process = CreateProcess();
             process.Start();
 
-            process.WaitForExit();
+            Assert.True(process.WaitForExit(Helpers.PassingTestTimeoutMilliseconds), $"Proccess {process.Id} did not finish in {Helpers.PassingTestTimeoutMilliseconds}.");
 
             process.Kill(killTree);
         }