Cleanup process (#3300)

This commit is contained in:
BrennanConroy 2018-11-14 10:48:12 -08:00 committed by GitHub
parent b476df9acd
commit 3896fc7242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 24 deletions

View File

@ -149,6 +149,8 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
{ {
var (process, lines) = RunProcess(fileName, arguments, prefix, logger); var (process, lines) = RunProcess(fileName, arguments, prefix, logger);
using (process)
{
if (!process.WaitForExit((int)timeout.TotalMilliseconds)) if (!process.WaitForExit((int)timeout.TotalMilliseconds))
{ {
process.Close(); process.Close();
@ -162,6 +164,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
return process.ExitCode; return process.ExitCode;
} }
}
private static (Process, ConcurrentQueue<string>) RunProcess(string fileName, string arguments, string prefix, ILogger logger) private static (Process, ConcurrentQueue<string>) RunProcess(string fileName, string arguments, string prefix, ILogger logger)
{ {
@ -179,9 +182,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
EnableRaisingEvents = true EnableRaisingEvents = true
}; };
var exitCode = 0;
var lines = new ConcurrentQueue<string>(); var lines = new ConcurrentQueue<string>();
process.Exited += (_, __) => exitCode = process.ExitCode;
process.OutputDataReceived += (_, a) => process.OutputDataReceived += (_, a) =>
{ {
LogIfNotNull(logger.LogInformation, $"'{prefix}' stdout: {{0}}", a.Data); LogIfNotNull(logger.LogInformation, $"'{prefix}' stdout: {{0}}", a.Data);

View File

@ -149,6 +149,8 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
{ {
var (process, lines) = RunProcess(fileName, arguments, prefix, logger); var (process, lines) = RunProcess(fileName, arguments, prefix, logger);
using (process)
{
if (!process.WaitForExit((int)timeout.TotalMilliseconds)) if (!process.WaitForExit((int)timeout.TotalMilliseconds))
{ {
process.Close(); process.Close();
@ -162,6 +164,7 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
return process.ExitCode; return process.ExitCode;
} }
}
private static (Process, ConcurrentQueue<string>) RunProcess(string fileName, string arguments, string prefix, ILogger logger) private static (Process, ConcurrentQueue<string>) RunProcess(string fileName, string arguments, string prefix, ILogger logger)
{ {
@ -179,9 +182,7 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
EnableRaisingEvents = true EnableRaisingEvents = true
}; };
var exitCode = 0;
var lines = new ConcurrentQueue<string>(); var lines = new ConcurrentQueue<string>();
process.Exited += (_, __) => exitCode = process.ExitCode;
process.OutputDataReceived += (_, a) => process.OutputDataReceived += (_, a) =>
{ {
LogIfNotNull(logger.LogInformation, $"'{prefix}' stdout: {{0}}", a.Data); LogIfNotNull(logger.LogInformation, $"'{prefix}' stdout: {{0}}", a.Data);