From 9ae3327af30e4d8595c14104a51b1f8d71c54cee Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 16 Mar 2016 18:04:17 -0700 Subject: [PATCH] Use KillTree from Common --- .../Deployers/ApplicationDeployer.cs | 37 +------------------ .../project.json | 4 ++ 2 files changed, 6 insertions(+), 35 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs index f5e50ca740..0734b6addf 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs @@ -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 = diff --git a/src/Microsoft.AspNetCore.Server.Testing/project.json b/src/Microsoft.AspNetCore.Server.Testing/project.json index 697405f45a..86afd0de96 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/project.json +++ b/src/Microsoft.AspNetCore.Server.Testing/project.json @@ -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": {