Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.

Commit 0dc7716

Browse files
lewurmakoeplinger
authored andcommitted
[FinallyDelegate] make key for lookupTable actually unique (#6)
Attributes like `[TestCase]` execute the same test method multiple times, therefore there could be a clash in `lookupTable` when adding more elements to it. Use GUID in order to make key for `lookupTable` without doubt unique
1 parent a8bef89 commit 0dc7716

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

NUnitLite-1.0.0/src/framework/FinallyDelegate.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ namespace NUnit.Framework.Internal
3535
{
3636
[Serializable]
3737
class Container : ILogicalThreadAffinative {
38-
public string testName;
39-
public Container(string testName) {
40-
this.testName = testName;
38+
public Guid guid;
39+
public Container(Guid guid) {
40+
this.guid = guid;
4141
}
4242
}
4343

@@ -58,29 +58,30 @@ public class FinallyDelegate
5858
// so we need a stack of finally delegate continuations
5959
Stack<Tuple<TestExecutionContext, long, TestResult>> testStack;
6060

61-
Dictionary<string, TestResult> lookupTable;
61+
Dictionary<Guid, TestResult> lookupTable;
6262

6363
private static readonly string CONTEXT_KEY = "TestResultName";
6464

6565
public FinallyDelegate () {
6666
this.testStack = new Stack<Tuple<TestExecutionContext, long, TestResult>>();
67-
this.lookupTable = new Dictionary<string, TestResult>();
67+
this.lookupTable = new Dictionary<Guid, TestResult>();
6868
}
6969

7070
public void Set (TestExecutionContext context, long startTicks, TestResult result) {
7171
var frame = new Tuple<TestExecutionContext, long, TestResult>(context, startTicks, result);
7272

7373
/* keep name in LogicalCallContext, because this will be inherited by
7474
* Threads spawned by the test case */
75-
CallContext.SetData(CONTEXT_KEY, new Container(result.Test.FullName));
75+
var guid = Guid.NewGuid();
76+
CallContext.SetData(CONTEXT_KEY, new Container(guid));
7677

77-
this.lookupTable.Add(result.Test.FullName, result);
78+
this.lookupTable.Add(guid, result);
7879
this.testStack.Push(frame);
7980
}
8081

8182
public void HandleUnhandledExc (Exception ex) {
8283
Container c = (Container) CallContext.GetData(CONTEXT_KEY);
83-
TestResult result = this.lookupTable [c.testName];
84+
TestResult result = this.lookupTable [c.guid];
8485
result.RecordException(ex);
8586
result.ThreadCrashFail = true;
8687
}

0 commit comments

Comments
 (0)