Skip to content

Commit

Permalink
Merge pull request #52 from TestCentric/issue-39g
Browse files Browse the repository at this point in the history
Ensure that test-run element is sent when test is cancelled
  • Loading branch information
CharliePoole authored Jun 14, 2022
2 parents 90ad357 + 71f9631 commit 0a438b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
24 changes: 5 additions & 19 deletions src/TestEngine/testcentric.engine/Runners/MasterTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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($"<test-run id='{TestPackage.ID}' result='Failed' label='Cancelled' />");

// 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($"<test-run id='{TestPackage.ID}' result='Failed' label='Cancelled' />");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0a438b2

Please sign in to comment.