Use KillTree from Common

This commit is contained in:
John Luo 2016-03-16 18:04:17 -07:00
parent ac7741fe81
commit 9ae3327af3
2 changed files with 6 additions and 35 deletions

View File

@ -2,11 +2,10 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.PlatformAbstractions;
@ -104,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Testing
if (hostProcess != null && !hostProcess.HasExited)
{
// Shutdown the host process.
KillProcess(hostProcess.Id);
hostProcess.KillTree();
if (!hostProcess.HasExited)
{
Logger.LogWarning("Unable to terminate the host process with process Id '{processId}", hostProcess.Id);
@ -120,38 +119,6 @@ namespace Microsoft.AspNetCore.Server.Testing
}
}
private void KillProcess(int processId)
{
if (IsWindows)
{
var startInfo = new ProcessStartInfo
{
FileName = "taskkill",
Arguments = $"/T /F /PID {processId}",
};
var killProcess = Process.Start(startInfo);
killProcess.WaitForExit();
}
else
{
var killSubProcessStartInfo = new ProcessStartInfo
{
FileName = "pkill",
Arguments = $"-TERM -P {processId}",
};
var killSubProcess = Process.Start(killSubProcessStartInfo);
killSubProcess.WaitForExit();
var killProcessStartInfo = new ProcessStartInfo
{
FileName = "kill",
Arguments = $"-TERM {processId}",
};
var killProcess = Process.Start(killProcessStartInfo);
killProcess.WaitForExit();
}
}
protected void AddEnvironmentVariablesToProcess(ProcessStartInfo startInfo)
{
var environment =

View File

@ -17,6 +17,10 @@
"Microsoft.AspNetCore.Testing": "1.0.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
"Microsoft.Extensions.ProcessHelper.Sources": {
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.NETCore.Platforms": "1.0.1-*"
},
"frameworks": {