Repository: nunit/nunit

Issue #2328: Test execution hangs without any progress.
Created: 2017-07-24T18:38:40Z
Recently we started encountering strange issues with our NUnit tests. In the middle of the execution, progress stops. If we attach to the application we see that no test is actually executed - NUnit just waits for the previous test to finish and apparently there is no one to signal that. After some investigation, we believe this is due to the following exception that we keep encountering:
System.Threading.ThreadAbortException occurred
  HResult=-2146233040
  Message=Thread was being aborted.
  Source=nunit.framework
  StackTrace:
       at NUnit.Framework.Internal.TestExecutionContext.get_ExecutionStatus() in C:\Sources\NUnit\src\NUnitFramework\framework\Internal\TestExecutionContext.cs:line 275
  InnerException: 

The stack trace for this exception is as follows:
>	nunit.framework.dll!NUnit.Framework.Internal.TestExecutionContext.ExecutionStatus.get() Line 277	C#
 	nunit.framework.dll!NUnit.Framework.Internal.TestExecutionContext.ExecutionStatus.get() Line 275	C#
 	nunit.framework.dll!NUnit.Framework.Internal.TestExecutionContext.ExecutionStatus.get() Line 275	C#
 	nunit.framework.dll!NUnit.Framework.Internal.TestExecutionContext.ExecutionStatus.get() Line 275	C#
 	nunit.framework.dll!NUnit.Framework.Internal.TestExecutionContext.ExecutionStatus.get() Line 275	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.CheckForCancellation() Line 145	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.RunChildren() Line 274	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformWork() Line 100	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.RunOnCurrentThread() Line 442	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.Execute() Line 226	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.SimpleWorkItemDispatcher.Dispatch(NUnit.Framework.Internal.Execution.WorkItem work) Line 75	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.RunChildren() Line 285	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformWork() Line 100	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.RunOnCurrentThread() Line 442	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.Execute() Line 226	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.SimpleWorkItemDispatcher.Dispatch(NUnit.Framework.Internal.Execution.WorkItem work) Line 75	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.RunChildren() Line 285	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformWork() Line 100	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.RunOnCurrentThread() Line 442	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.Execute() Line 226	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.SimpleWorkItemDispatcher.Dispatch(NUnit.Framework.Internal.Execution.WorkItem work) Line 75	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.RunChildren() Line 285	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformWork() Line 100	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.RunOnCurrentThread() Line 442	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.Execute() Line 226	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.SimpleWorkItemDispatcher.Dispatch(NUnit.Framework.Internal.Execution.WorkItem work) Line 75	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.RunChildren() Line 285	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformWork() Line 100	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.RunOnCurrentThread() Line 442	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.Execute() Line 226	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.SimpleWorkItemDispatcher.Dispatch(NUnit.Framework.Internal.Execution.WorkItem work) Line 75	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.RunChildren() Line 285	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformWork() Line 100	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.RunOnCurrentThread() Line 442	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.WorkItem.Execute() Line 226	C#
 	nunit.framework.dll!NUnit.Framework.Internal.Execution.SimpleWorkItemDispatcher.RunnerThreadProc() Line 81	C#
 	mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown
 	mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()	Unknown
 	[Native to Managed Transition]	

We are using custom built NUnit framework in order to be able to debug it. Any suggestions would be much appreciated. We are ready to do some work ourselves - just need some pointers on what might be the issue. The whole setup is rather complex, event the test causing the hang is different every time.

Duplicate issue #2761: Infinite loop in nunit 3.9
Created: 2018-03-15T08:25:48Z
I am running a test suite with nunit 3.9 using nunit3-console, that randomly blocks at the end of the run. All of the tests derive from a base class that is declared with [Parallelizable(ParallelScope.All)] attribute.
I managed to break into nunit and the problem is that sometimes the NonParallel worker is stuck inside the OnEndOfShift() method of ParallelWorkItemDispatcher. The _topLevelWorkItem state is WorkItemState.Complete, and after all of the shifts have been run their queues are empty. No other worker is changing the state of the _topLevelWorkItem. Given this situation, the following code inside OnEndOfShift() is an endless loop:
// Shift has ended but all work may not yet be done
while (_topLevelWorkItem.State != WorkItemState.Complete)
{
    // This will return null if all queues are empty.
    nextShift = SelectNextShift();
    if (nextShift != null)
    {
        ShiftStarting?.Invoke(nextShift);
        nextShift.Start();
        return;
    }
}

The name of the _topLevelWorkItem is the name of the dll containing all the tests.
I was not able to recreate the problem with a small set of tests but I can make investigations about variable values, execution stacks, or order of events, if you need info.

Closing comment (2018-07-06T15:46:07Z): Ah, this sounds similar to #2328!