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

dispose of IProcess #3141

Merged
merged 2 commits into from
Jun 25, 2024
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 @@ -369,7 +369,7 @@ private async Task TakeDumpAsync()

diagnosticsClient.WriteDump(dumpType, finalDumpFileName, true);
NotifyCrashDumpServiceIfEnabled();
IProcess process = _processHandler.GetProcessById(_testHostProcessInformation.PID);
using IProcess process = _processHandler.GetProcessById(_testHostProcessInformation.PID);
process.Kill();
await process.WaitForExitAsync();

Expand All @@ -384,7 +384,7 @@ private async Task TakeDumpAsync()

MiniDumpWriteDump.CollectDumpUsingMiniDumpWriteDump(_testHostProcessInformation.PID, finalDumpFileName, miniDumpTypeOption);
NotifyCrashDumpServiceIfEnabled();
IProcess process = _processHandler.GetProcessById(_testHostProcessInformation.PID);
using IProcess process = _processHandler.GetProcessById(_testHostProcessInformation.PID);
process.Kill();
process.WaitForExit();
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ private static async Task LogInformationAsync(
await logger.LogInformationAsync("Logging mode: " + (syncWrite ? "synchronous" : "asynchronous"));
await logger.LogInformationAsync($"Logging level: {loggerLevel}");
await logger.LogInformationAsync($"CreateBuilderAsync entry time: {createBuilderEntryTime}");
await logger.LogInformationAsync($"PID: {processHandler.GetCurrentProcess().Id}");
using IProcess currentProcess = processHandler.GetCurrentProcess();
await logger.LogInformationAsync($"PID: {currentProcess.Id}");

#if NETCOREAPP
string runtimeInformation = $"{RuntimeInformation.RuntimeIdentifier} - {RuntimeInformation.FrameworkDescription}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,9 @@ private async Task SendCommandLineOptionsToDotnetTestPipeAsync(NamedPipeClient n
await logger.LogDebugAsync($"Connected to named pipe '{pipeName}'");

// Send the PID
using IProcess currentProcess = processHandler.GetCurrentProcess();
await client.RequestReplyAsync<TestHostProcessPIDRequest, VoidResponse>(
new TestHostProcessPIDRequest(processHandler.GetCurrentProcess().Id),
new TestHostProcessPIDRequest(currentProcess.Id),
testApplicationCancellationTokenSource.CancellationToken);
return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ protected override async Task<int> InternalRunAsync()
var consoleRunStarted = Stopwatch.StartNew();
IEnvironment environment = ServiceProvider.GetEnvironment();
IProcessHandler process = ServiceProvider.GetProcessHandler();
int currentPID = process.GetCurrentProcess().Id;
using IProcess currentProcess = process.GetCurrentProcess();
int currentPID = currentProcess.Id;
ITestApplicationModuleInfo testApplicationModuleInfo = ServiceProvider.GetTestApplicationModuleInfo();
ExecutableInfo executableInfo = testApplicationModuleInfo.GetCurrentExecutableInfo();
ITelemetryCollector telemetry = ServiceProvider.GetTelemetryCollector();
Expand All @@ -79,7 +80,7 @@ protected override async Task<int> InternalRunAsync()
IConfiguration configuration = ServiceProvider.GetConfiguration();
try
{
string processIdString = process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture);
string processIdString = currentProcess.Id.ToString(CultureInfo.InvariantCulture);
List<string> partialCommandLine =
[
.. executableInfo.Arguments,
Expand Down Expand Up @@ -111,7 +112,7 @@ protected override async Task<int> InternalRunAsync()
EnvironmentVariables =
{
{ $"{EnvironmentVariableConstants.TESTINGPLATFORM_TESTHOSTCONTROLLER_CORRELATIONID}_{currentPID}", processCorrelationId },
{ $"{EnvironmentVariableConstants.TESTINGPLATFORM_TESTHOSTCONTROLLER_PARENTPID}_{currentPID}", process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture) ?? "null pid" },
{ $"{EnvironmentVariableConstants.TESTINGPLATFORM_TESTHOSTCONTROLLER_PARENTPID}_{currentPID}", currentProcess?.Id.ToString(CultureInfo.InvariantCulture) ?? "null pid" },
{ $"{EnvironmentVariableConstants.TESTINGPLATFORM_TESTHOSTCONTROLLER_SKIPEXTENSION}_{currentPID}", "1" },
{ $"{EnvironmentVariableConstants.TESTINGPLATFORM_TESTHOSTCONTROLLER_PIPENAME}_{currentPID}", testHostControllerIpc.PipeName.Name },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ public string GetCommandLineArguments()
return processPath;
}
#else
=> process.GetCurrentProcess().MainModule.FileName;
{
using IProcess currentProcess = process.GetCurrentProcess();
return currentProcess.MainModule.FileName;
}
#endif

public ExecutableInfo GetCurrentExecutableInfo()
Expand Down
Loading