Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

System.Diagnostics.Process has a different behavior on non-Windows platforms #248

Merged
merged 3 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion BuildForPublication.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
setlocal EnableDelayedExpansion
set errorlevel=
set BuildConfiguration=Release
set VersionSuffix=beta-build0012
set VersionSuffix=beta-build0013

REM Check that git is on path.
where.exe /Q git.exe || (
Expand Down
12 changes: 8 additions & 4 deletions src/xunit.performance.api/ProcessExitInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ public sealed class ProcessExitInfo
/// <summary>
/// Initializes a new instance of a ProcessExitInfo class with the run process.
/// </summary>
/// <param name="process"></param>
public ProcessExitInfo(Process process)
/// <param name="process">The terminated process.</param>
/// <param name="startTime">The time that the associated process was started.</param>
/// <param name="exitTime">The time that the associated process exited.</param>
internal ProcessExitInfo(Process process, DateTime startTime, DateTime exitTime)
{
if (process == null)
throw new ArgumentNullException(nameof(process));
if (!process.HasExited)
throw new InvalidOperationException($"{process.ProcessName} has not exited.");
if (exitTime < startTime)
throw new InvalidOperationException($"Process.ExitTime: {exitTime}, is less than the Process.StartTime: {startTime}.");

ProcessId = process.Id;
ExitCode = process.ExitCode;
StartTime = process.StartTime;
ExitTime = process.ExitTime;
StartTime = startTime;
ExitTime = exitTime;
}

/// <summary>
Expand Down
8 changes: 5 additions & 3 deletions src/xunit.performance.api/ScenarioExecutionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Xunit.Performance.Api.Profilers.Etw;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Microsoft.Xunit.Performance.Api
{
Expand All @@ -16,10 +16,12 @@ public sealed class ScenarioExecutionResult
/// Initializes a new instance of the ScenarioExecutionResult class.
/// </summary>
/// <param name="process">Scenario benchmark process that was run.</param>
/// <param name="startTime">The time that the associated process was started.</param>
/// <param name="exitTime">The time that the associated process exited.</param>
/// <param name="configuration">Configuration for the scenario that was run.</param>
public ScenarioExecutionResult(System.Diagnostics.Process process, ScenarioTestConfiguration configuration)
internal ScenarioExecutionResult(System.Diagnostics.Process process, DateTime startTime, DateTime exitTime, ScenarioTestConfiguration configuration)
{
ProcessExitInfo = new ProcessExitInfo(process);
ProcessExitInfo = new ProcessExitInfo(process, startTime, exitTime);
Configuration = configuration;
}

Expand Down
12 changes: 9 additions & 3 deletions src/xunit.performance.api/XunitPerformanceHarness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ public static string Usage()

private static ScenarioExecutionResult Run(ScenarioTestConfiguration configuration, ScenarioTest scenarioTest)
{
if (!scenarioTest.Process.Start())
var hasStarted = scenarioTest.Process.Start();
var startTime = DateTime.UtcNow;
if (!hasStarted)
throw new Exception($"Failed to start {scenarioTest.Process.ProcessName}");

if (scenarioTest.Process.StartInfo.RedirectStandardError)
Expand All @@ -303,7 +305,11 @@ private static ScenarioExecutionResult Run(ScenarioTestConfiguration configurati
if (scenarioTest.Process.StartInfo.RedirectStandardOutput)
scenarioTest.Process.BeginOutputReadLine();

if (scenarioTest.Process.WaitForExit((int)(configuration.TimeoutPerIteration.TotalMilliseconds)) == false)
var hasExited = scenarioTest.Process.WaitForExit(
(int)(configuration.TimeoutPerIteration.TotalMilliseconds));
var exitTime = DateTime.UtcNow;

if (!hasExited)
{
// TODO: scenarioOutput.Process.Kill[All|Tree]();
scenarioTest.Process.Kill();
Expand All @@ -314,7 +320,7 @@ private static ScenarioExecutionResult Run(ScenarioTestConfiguration configurati
if (!configuration.SuccessExitCodes.Contains(scenarioTest.Process.ExitCode))
throw new Exception($"'{scenarioTest.Process.StartInfo.FileName}' exited with an invalid exit code: {scenarioTest.Process.ExitCode}");

return new ScenarioExecutionResult(scenarioTest.Process, configuration);
return new ScenarioExecutionResult(scenarioTest.Process, startTime, exitTime, configuration);
}

private void ProcessResults(XUnitPerformanceSessionData xUnitSessionData, XUnitPerformanceMetricData xUnitPerformanceMetricData)
Expand Down