Skip to content

Commit

Permalink
improve resiliency of process tests (#35584)
Browse files Browse the repository at this point in the history
* impove resiliency of process tests

* feedback from review

* dispose process

Co-authored-by: Tomas Weinfurt <furt@Shining.local>
  • Loading branch information
wfurt and Tomas Weinfurt authored Apr 30, 2020
1 parent 6ed9f1b commit 543037d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/libraries/System.Diagnostics.Process/tests/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,5 +38,15 @@ public static async Task RetryWithBackoff(Action action, int delayInMilliseconds
}
}
}

public static void DumpAllProcesses()
{
Process[] all = Process.GetProcesses();
foreach (Process p in all)
{
Console.WriteLine("{0,8} {1}", p.Id, p.ProcessName);
p.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ public async Task Kill_ExitedNonChildProcess_DoesNotThrow(bool killTree)
{
// 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.
Expand All @@ -833,6 +833,15 @@ public async Task Kill_ExitedNonChildProcess_DoesNotThrow(bool killTree)
// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,7 @@ public void Kill_ExitedChildProcess_DoesNotThrow(bool killTree)
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);
}
Expand Down

0 comments on commit 543037d

Please sign in to comment.