diff --git a/GoogleTestAdapter/Common/ProcessUtils.cs b/GoogleTestAdapter/Common/ProcessUtils.cs index 28a1995aa..b050f2365 100644 --- a/GoogleTestAdapter/Common/ProcessUtils.cs +++ b/GoogleTestAdapter/Common/ProcessUtils.cs @@ -1,11 +1,18 @@ using System; using System.Diagnostics; +using System.Threading.Tasks; namespace GoogleTestAdapter.Common { public static class ProcessUtils { public static void KillProcess(int processId, ILogger logger) + { + logger.DebugInfo($"Scheduling to kill process with id {processId}..."); + Task.Run(() => DoKillProcess(processId, logger)); + } + + private static void DoKillProcess(int processId, ILogger logger) { try { @@ -13,8 +20,18 @@ public static void KillProcess(int processId, ILogger logger) DateTime startTime = process.StartTime; try { + logger.DebugInfo($"Trying to kill process {process} with startTime={startTime.ToShortTimeString()}"); process.Kill(); - logger.DebugInfo($"Killed process {process} with startTime={startTime.ToShortTimeString()}"); + logger.DebugInfo($"Invoked Kill() on process {process} with startTime={startTime.ToShortTimeString()}, waiting for it to exit..."); + process.WaitForExit(); + if (process.HasExited) + { + logger.DebugInfo($"Successfully killed process {process} with startTime={startTime.ToShortTimeString()}"); + } + else + { + logger.DebugWarning($"Wasn't able to kill process {process} with startTime={startTime.ToShortTimeString()}..."); + } } catch (Exception e) { @@ -24,6 +41,7 @@ public static void KillProcess(int processId, ILogger logger) catch (Exception) { // process was not running - nothing to do + logger.DebugInfo($"Process with id {processId} should be killed, but apparently was not running"); } } } diff --git a/GoogleTestAdapter/Core.Tests/TestCases/TestCaseFactoryTests.cs b/GoogleTestAdapter/Core.Tests/TestCases/TestCaseFactoryTests.cs index e5a9ff920..2ceb7e1ae 100644 --- a/GoogleTestAdapter/Core.Tests/TestCases/TestCaseFactoryTests.cs +++ b/GoogleTestAdapter/Core.Tests/TestCases/TestCaseFactoryTests.cs @@ -37,7 +37,7 @@ public void CreateTestCases_DiscoveryTimeoutIsExceeded_DiscoveryIsCanceledAndCan reportedTestCases.Should().BeEmpty(); returnedTestCases.Should().BeEmpty(); - stopWatch.Elapsed.Should().BeGreaterOrEqualTo(TimeSpan.FromSeconds(1)); + stopWatch.Elapsed.Should().BeGreaterOrEqualTo(TimeSpan.FromSeconds(0.9)); stopWatch.Elapsed.Should().BeLessThan(TimeSpan.FromSeconds(2)); MockLogger.Verify(o => o.LogError(It.Is(s => s.Contains(TestResources.TenSecondsWaiter))), Times.Once); MockLogger.Verify(o => o.DebugError(It.Is(s => s.Contains(Path.GetFileName(TestResources.TenSecondsWaiter)))), Times.AtLeastOnce); diff --git a/GoogleTestAdapter/Tests.Common/Helpers/TestProcessLauncher.cs b/GoogleTestAdapter/Tests.Common/Helpers/TestProcessLauncher.cs index aa8e61b9f..ea81618ff 100644 --- a/GoogleTestAdapter/Tests.Common/Helpers/TestProcessLauncher.cs +++ b/GoogleTestAdapter/Tests.Common/Helpers/TestProcessLauncher.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Collections.Concurrent; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using GoogleTestAdapter.Common; @@ -19,18 +20,18 @@ public int GetOutputStreams(string workingDirectory, string command, string para { Process process = CreateProcess(workingDirectory, command, param); - var localStandardOut = new List(); - var localStandardErr = new List(); - var localAllOutput = new List(); + var localStandardOut = new ConcurrentQueue(); + var localStandardErr = new ConcurrentQueue(); + var localAllOutput = new ConcurrentQueue(); process.OutputDataReceived += (sender, e) => { - localStandardOut.Add(e.Data); - localAllOutput.Add(e.Data); + localStandardOut.Enqueue(e.Data); + localAllOutput.Enqueue(e.Data); }; process.ErrorDataReceived += (sender, e) => { - localStandardErr.Add(e.Data); - localAllOutput.Add(e.Data); + localStandardErr.Enqueue(e.Data); + localAllOutput.Enqueue(e.Data); }; try