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

SystemProcessHandler start cant return null #3002

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
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ internal interface IProcessHandler

IProcess GetCurrentProcess();

IProcess? Start(ProcessStartInfo startInfo);
IProcess Start(ProcessStartInfo startInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

using Microsoft.Testing.Platform.Resources;

namespace Microsoft.Testing.Platform.Helpers;

Expand All @@ -13,11 +16,13 @@ internal sealed class SystemProcessHandler : IProcessHandler

public IProcess GetProcessById(int pid) => new SystemProcess(Process.GetProcessById(pid));

public IProcess? Start(ProcessStartInfo startInfo)
public IProcess Start(ProcessStartInfo startInfo)
{
var process = Process.Start(startInfo);
ApplicationStateGuard.Ensure(process is not null);
Process process = Process.Start(startInfo)
?? throw new InvalidOperationException(string.Format(
CultureInfo.InvariantCulture,
PlatformResources.CannotStartProcessErrorMessage, startInfo.FileName));
process.EnableRaisingEvents = true;
return process is null ? null : (IProcess)new SystemProcess(process);
return new SystemProcess(process);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ protected override async Task<int> InternalRunAsync()
processStartInfo.EnvironmentVariables.Add($"{EnvironmentVariableConstants.TESTINGPLATFORM_TESTHOSTCONTROLLER_TESTHOSTPROCESSSTARTTIME}_{currentPID}", testHostProcessStartupTime);
await _logger.LogDebugAsync($"{EnvironmentVariableConstants.TESTINGPLATFORM_TESTHOSTCONTROLLER_TESTHOSTPROCESSSTARTTIME}_{currentPID} '{testHostProcessStartupTime}'");
await _logger.LogDebugAsync($"Starting test host process");
IProcess testHostProcess = process.Start(processStartInfo)
?? throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, PlatformResources.CannotStartProcessErrorMessage, processStartInfo.FileName));
IProcess testHostProcess = process.Start(processStartInfo);

testHostProcess.Exited += (sender, e) =>
{
Expand Down