Imported Upstream version 5.10.0.132

Former-commit-id: a9e918d5dd4e43efde300d26074ebd475b9927ef
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-02-22 09:08:32 +00:00
parent 65dc56118c
commit 4373cb63d5
45 changed files with 120 additions and 49 deletions

View File

@@ -29,9 +29,18 @@ using System.Diagnostics;
using System.Threading;
using NUnit.Framework.Api;
using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;
namespace NUnit.Framework.Internal
{
[Serializable]
class Container : ILogicalThreadAffinative {
public Guid guid;
public Container(Guid guid) {
this.guid = guid;
}
}
public class FinallyDelegate
{
// If our test spawns a thread that throws, we will bubble
@@ -49,19 +58,32 @@ namespace NUnit.Framework.Internal
// so we need a stack of finally delegate continuations
Stack<Tuple<TestExecutionContext, long, TestResult>> testStack;
Dictionary<Guid, TestResult> lookupTable;
private static readonly string CONTEXT_KEY = "TestResultName";
public FinallyDelegate () {
this.testStack = new Stack<Tuple<TestExecutionContext, long, TestResult>>();
this.lookupTable = new Dictionary<Guid, TestResult>();
}
public void Set (TestExecutionContext context, long startTicks, TestResult result) {
var frame = new Tuple<TestExecutionContext, long, TestResult>(context, startTicks, result);
/* keep name in LogicalCallContext, because this will be inherited by
* Threads spawned by the test case */
var guid = Guid.NewGuid();
CallContext.SetData(CONTEXT_KEY, new Container(guid));
this.lookupTable.Add(guid, result);
this.testStack.Push(frame);
}
public void HandleUnhandledExc (Exception ex) {
TestExecutionContext context = this.testStack.Peek().Item1;
context.CurrentResult.RecordException(ex);
context.CurrentResult.ThreadCrashFail = true;
Container c = (Container) CallContext.GetData(CONTEXT_KEY);
TestResult result = this.lookupTable [c.guid];
result.RecordException(ex);
result.ThreadCrashFail = true;
}
public void Complete () {

View File

@@ -180,6 +180,15 @@ namespace NUnit.Framework.Internal.WorkItems
#endif
private void RunTest()
{
/* using a separate ExecutionContext for every test case,
* guarantees us to have a dedicated "namespace" for the
* LogicalCallContext per testcase */
ExecutionContext ec = ExecutionContext.Capture();
ExecutionContext.Run(ec, DispatchWork, null);
}
private void DispatchWork(object o)
{
_context.CurrentTest = this.Test;
_context.CurrentResult = this.Result;
@@ -192,7 +201,7 @@ namespace NUnit.Framework.Internal.WorkItems
long startTicks = Stopwatch.GetTimestamp();
#endif
finD.Set(_context, startTicks, Result);
finD?.Set(_context, startTicks, Result);
PerformWork();
}
@@ -211,7 +220,7 @@ namespace NUnit.Framework.Internal.WorkItems
/// </summary>
protected void WorkItemComplete()
{
finD.Complete();
finD?.Complete();
_state = WorkItemState.Complete;
if (Completed != null)
Completed(this, EventArgs.Empty);