Cleanup process (#3300)
This commit is contained in:
parent
b476df9acd
commit
3896fc7242
|
|
@ -149,18 +149,21 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
|
||||||
{
|
{
|
||||||
var (process, lines) = RunProcess(fileName, arguments, prefix, logger);
|
var (process, lines) = RunProcess(fileName, arguments, prefix, logger);
|
||||||
|
|
||||||
if (!process.WaitForExit((int)timeout.TotalMilliseconds))
|
using (process)
|
||||||
{
|
{
|
||||||
process.Close();
|
if (!process.WaitForExit((int)timeout.TotalMilliseconds))
|
||||||
logger.LogError("Closing process '{processName}' because it is running longer than the configured timeout.", fileName);
|
{
|
||||||
|
process.Close();
|
||||||
|
logger.LogError("Closing process '{processName}' because it is running longer than the configured timeout.", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Need to WaitForExit without a timeout to guarantee the output stream has written everything
|
||||||
|
process.WaitForExit();
|
||||||
|
|
||||||
|
output = string.Join(Environment.NewLine, lines);
|
||||||
|
|
||||||
|
return process.ExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to WaitForExit without a timeout to guarantee the output stream has written everything
|
|
||||||
process.WaitForExit();
|
|
||||||
|
|
||||||
output = string.Join(Environment.NewLine, lines);
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -149,18 +149,21 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
|
||||||
{
|
{
|
||||||
var (process, lines) = RunProcess(fileName, arguments, prefix, logger);
|
var (process, lines) = RunProcess(fileName, arguments, prefix, logger);
|
||||||
|
|
||||||
if (!process.WaitForExit((int)timeout.TotalMilliseconds))
|
using (process)
|
||||||
{
|
{
|
||||||
process.Close();
|
if (!process.WaitForExit((int)timeout.TotalMilliseconds))
|
||||||
logger.LogError("Closing process '{processName}' because it is running longer than the configured timeout.", fileName);
|
{
|
||||||
|
process.Close();
|
||||||
|
logger.LogError("Closing process '{processName}' because it is running longer than the configured timeout.", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Need to WaitForExit without a timeout to guarantee the output stream has written everything
|
||||||
|
process.WaitForExit();
|
||||||
|
|
||||||
|
output = string.Join(Environment.NewLine, lines);
|
||||||
|
|
||||||
|
return process.ExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to WaitForExit without a timeout to guarantee the output stream has written everything
|
|
||||||
process.WaitForExit();
|
|
||||||
|
|
||||||
output = string.Join(Environment.NewLine, lines);
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue