From 71f96318d3d385794a55cce224c55750afc8f853 Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Tue, 14 Jun 2022 06:54:36 -0700 Subject: [PATCH] Ensure that test-run element is sent when test is cancelled --- .../Runners/MasterTestRunner.cs | 24 ++++--------------- .../Services/TestEventDispatcher.cs | 2 +- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/TestEngine/testcentric.engine/Runners/MasterTestRunner.cs b/src/TestEngine/testcentric.engine/Runners/MasterTestRunner.cs index d053aa3..e9f2f30 100644 --- a/src/TestEngine/testcentric.engine/Runners/MasterTestRunner.cs +++ b/src/TestEngine/testcentric.engine/Runners/MasterTestRunner.cs @@ -175,29 +175,15 @@ public void StopRun(bool force) _engineRunner.StopRun(force); - if (force) + // When running under .NET Core, the test framework will not be able to kill the + // threads currently running tests. We handle cleanup here in case that happens. + if (force && !_eventDispatcher.WaitForCompletion(WAIT_FOR_CANCEL_TO_COMPLETE)) { - // Frameworks should handle StopRun(true) by cancelling all tests and notifying - // us of the completion of any tests that were running. However, this feature - // may be absent in some frameworks or may be broken and we may not pass on the - // notifications needed by some runners. In fact, such a bug is present in the - // NUnit framework through release 3.12 and motivated the following code. - // - // We try to make up for the potential problem here by notifying the listeners - // of the completion of every pending WorkItem, that is, one that started but - // never sent a completion event. - + // Send completion events for any tests, which were still running _eventDispatcher.IssuePendingNotifications(); // Signal completion of the run - _eventDispatcher.OnTestEvent($""); - - // Since we were not notified of the completion of some items, we can't trust - // that they were actually stopped by the framework. To make sure nothing is - // left running, we unload the tests. By unloading only the lower-level engine - // runner and not the MasterTestRunner itself, we allow the tests to be loaded - // for subsequent runs using the same package. - //_engineRunner.Unload(); + _eventDispatcher.DispatchEvent($""); } } diff --git a/src/TestEngine/testcentric.engine/Services/TestEventDispatcher.cs b/src/TestEngine/testcentric.engine/Services/TestEventDispatcher.cs index e068f08..35a0692 100644 --- a/src/TestEngine/testcentric.engine/Services/TestEventDispatcher.cs +++ b/src/TestEngine/testcentric.engine/Services/TestEventDispatcher.cs @@ -67,7 +67,7 @@ public void OnTestEvent(string report) } } - private void DispatchEvent(string report) + internal void DispatchEvent(string report) { foreach (var listener in Listeners) listener.OnTestEvent(report);