From 795583320f74d06e2df8a3a8021646536125be63 Mon Sep 17 00:00:00 2001 From: Christian Soltenborn Date: Thu, 17 Feb 2022 08:48:39 +0100 Subject: [PATCH 1/4] waiting for process to be killed, add debug output --- GoogleTestAdapter/Common/ProcessUtils.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/GoogleTestAdapter/Common/ProcessUtils.cs b/GoogleTestAdapter/Common/ProcessUtils.cs index 28a1995aa..c15be4c8d 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,11 @@ 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(); + logger.DebugInfo($"Successfully killed process {process} with startTime={startTime.ToShortTimeString()}"); } catch (Exception e) { @@ -24,6 +34,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"); } } } From 1d7d6983fe4f1948ccd4aa4f984790fc7a3396bc Mon Sep 17 00:00:00 2001 From: Christian Soltenborn Date: Thu, 17 Feb 2022 09:37:30 +0100 Subject: [PATCH 2/4] fixed cancellation test --- GoogleTestAdapter/Core.Tests/TestCases/TestCaseFactoryTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 96837d21e12ce9a84921746f631b47bfc1e95a1e Mon Sep 17 00:00:00 2001 From: Christian Soltenborn Date: Thu, 17 Feb 2022 10:02:01 +0100 Subject: [PATCH 3/4] trying to fix IndexOutOfRangeException --- .../Tests.Common/Helpers/TestProcessLauncher.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 From e05339266dbedb48abd109dbddbbba50ed800a2d Mon Sep 17 00:00:00 2001 From: Christian Soltenborn Date: Thu, 17 Feb 2022 12:48:27 +0100 Subject: [PATCH 4/4] trying to make even more sure that process has been killed :-) --- GoogleTestAdapter/Common/ProcessUtils.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/GoogleTestAdapter/Common/ProcessUtils.cs b/GoogleTestAdapter/Common/ProcessUtils.cs index c15be4c8d..b050f2365 100644 --- a/GoogleTestAdapter/Common/ProcessUtils.cs +++ b/GoogleTestAdapter/Common/ProcessUtils.cs @@ -24,7 +24,14 @@ private static void DoKillProcess(int processId, ILogger logger) process.Kill(); logger.DebugInfo($"Invoked Kill() on process {process} with startTime={startTime.ToShortTimeString()}, waiting for it to exit..."); process.WaitForExit(); - logger.DebugInfo($"Successfully killed process {process} with startTime={startTime.ToShortTimeString()}"); + 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) {