Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProcessWatchdog: no longer fail on exit code 259 on Windows #450

Merged
merged 5 commits into from
Dec 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ProcessWatchdogTest: improve diagnostics, migrate to ping instead of …
…timeout

timeout was behaving weirdly in cmd with IO redirection.
ForNeVeR committed Dec 2, 2023
commit d2107f0337c13bd8fac8921506d184994e588308
25 changes: 16 additions & 9 deletions rd-net/Test.Lifetimes/Diagnostics/ProcessWatchdogTest.cs
Original file line number Diff line number Diff line change
@@ -44,7 +44,8 @@ private static Task DoTest(Func<Process> processCreator, bool assertAlive) => Li
if (assertAlive)
{
await Task.Delay(timeForReliableDetection, lt);
Assert.IsFalse(task.IsCompleted);
Assert.IsFalse(process.HasExited, "Process should not be exited.");
Assert.IsFalse(task.IsCompleted, "Watchdog should not be triggered.");
}

if (!process.HasExited) process.Kill();
@@ -62,15 +63,21 @@ private static Task DoTest(Func<Process> processCreator, bool assertAlive) => Li

private Process StartSleepingProcess()
{
if (RuntimeInfo.IsRunningUnderWindows)
{
return Process.Start(new ProcessStartInfo("cmd.exe", "/c timeout 30")
{
WindowStyle = ProcessWindowStyle.Hidden
});
}
var startInfo = RuntimeInfo.IsRunningUnderWindows
? new ProcessStartInfo("cmd.exe", "/c ping 127.0.0.1 -n 30")
: new ProcessStartInfo("sleep", "30");
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;

var logger = Log.GetLog<ProcessWatchdogTest>();
var process = Process.Start(startInfo)!;
process.ErrorDataReceived += (_, args) => logger.Warn($"[{process.Id}] {args.Data}");
process.OutputDataReceived += (_, args) => logger.Info($"[{process.Id}] {args.Data}");
process.Exited += (_, _) => logger.Info($"[{process.Id}] Exited with code: {process.ExitCode}");

return Process.Start("sleep", "30");
return process;
}

private Process GetTerminatedProcess(int exitCode)
Loading