Skip to content

Commit d1d0986

Browse files
committed
Fix lookup issue exposed by STAFact and STATheory
1 parent 3cb9c58 commit d1d0986

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

xunit.runner.visualstudio.testadapter/Visitors/VsExecutionVisitor.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public class VsExecutionVisitor : TestMessageVisitor<ITestAssemblyFinished>
1414
readonly Func<bool> cancelledThunk;
1515
readonly ITestFrameworkExecutionOptions executionOptions;
1616
readonly ITestExecutionRecorder recorder;
17-
readonly Dictionary<ITestCase, TestCase> testCases;
17+
readonly Dictionary<string, TestCase> testCases;
1818

1919
public VsExecutionVisitor(ITestExecutionRecorder recorder,
20-
Dictionary<ITestCase, TestCase> testCases,
20+
Dictionary<string, TestCase> testCases,
2121
ITestFrameworkExecutionOptions executionOptions,
2222
Func<bool> cancelledThunk)
2323
{
@@ -66,7 +66,7 @@ protected override bool Visit(ITestSkipped testSkipped)
6666

6767
protected override bool Visit(ITestStarting testStarting)
6868
{
69-
recorder.RecordStart(testCases[testStarting.TestCase]);
69+
recorder.RecordStart(testCases[testStarting.TestCase.UniqueID]);
7070

7171
return !cancelledThunk();
7272
}
@@ -123,8 +123,7 @@ private VsTestResult MakeVsTestResult(TestOutcome outcome, ITestResultMessage te
123123

124124
private VsTestResult MakeVsTestResult(TestOutcome outcome, ITestCase testCase, string displayName, double executionTime = 0.0, string output = null)
125125
{
126-
var vsTestCase = testCases[testCase];
127-
var fqTestMethodName = String.Format("{0}.{1}", testCase.TestMethod.TestClass.Class.Name, testCase.TestMethod.Method.Name);
126+
var vsTestCase = testCases[testCase.UniqueID];
128127

129128
var result = new VsTestResult(vsTestCase)
130129
{

xunit.runner.visualstudio.testadapter/VsTestRunner.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,20 @@ void RunTests(IRunContext runContext, IFrameworkHandle frameworkHandle, Stopwatc
271271
using (AssemblyHelper.SubscribeResolve())
272272
if (parallelizeAssemblies)
273273
assemblies
274-
.Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, toDispose, runInfo, stopwatch))
274+
.Select(runInfo => RunTestsInAssemblyAsync(frameworkHandle, toDispose, runInfo, stopwatch))
275275
.ToList()
276276
.ForEach(@event => @event.WaitOne());
277277
else
278278
assemblies
279-
.ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, toDispose, runInfo, stopwatch));
279+
.ForEach(runInfo => RunTestsInAssembly(frameworkHandle, toDispose, runInfo, stopwatch));
280280
}
281281
finally
282282
{
283283
toDispose.ForEach(disposable => disposable.Dispose());
284284
}
285285
}
286286

287-
void RunTestsInAssembly(IDiscoveryContext discoveryContext,
288-
IFrameworkHandle frameworkHandle,
287+
void RunTestsInAssembly(IFrameworkHandle frameworkHandle,
289288
List<IDisposable> toDispose,
290289
AssemblyRunInfo runInfo,
291290
Stopwatch stopwatch)
@@ -319,12 +318,19 @@ void RunTestsInAssembly(IDiscoveryContext discoveryContext,
319318
lock (toDispose)
320319
toDispose.Add(controller);
321320

322-
var xunitTestCases = runInfo.TestCases.ToDictionary(tc => controller.Deserialize(tc.GetPropertyValue<string>(SerializedTestCaseProperty, null)));
321+
var testCaseMappings = runInfo.TestCases
322+
.Select(tc => new
323+
{
324+
VsTestCase = tc,
325+
XunitTestCase = controller.Deserialize(tc.GetPropertyValue<string>(SerializedTestCaseProperty, null))
326+
})
327+
.ToList();
328+
var testCaseLookup = testCaseMappings.ToDictionary(tc => tc.XunitTestCase.UniqueID, tc => tc.VsTestCase);
323329
var executionOptions = TestFrameworkOptions.ForExecution(runInfo.Configuration);
324330

325-
using (var executionVisitor = new VsExecutionVisitor(frameworkHandle, xunitTestCases, executionOptions, () => cancelled))
331+
using (var executionVisitor = new VsExecutionVisitor(frameworkHandle, testCaseLookup, executionOptions, () => cancelled))
326332
{
327-
controller.RunTests(xunitTestCases.Keys.ToList(), executionVisitor, executionOptions);
333+
controller.RunTests(testCaseMappings.Select(tc => tc.XunitTestCase).ToList(), executionVisitor, executionOptions);
328334
executionVisitor.Finished.WaitOne();
329335
}
330336

@@ -333,8 +339,7 @@ void RunTestsInAssembly(IDiscoveryContext discoveryContext,
333339
frameworkHandle.SendMessage(TestMessageLevel.Informational, String.Format("[xUnit.net {0}] Execution finished: {1}", stopwatch.Elapsed, assemblyDisplayName));
334340
}
335341

336-
ManualResetEvent RunTestsInAssemblyAsync(IDiscoveryContext discoveryContext,
337-
IFrameworkHandle frameworkHandle,
342+
ManualResetEvent RunTestsInAssemblyAsync(IFrameworkHandle frameworkHandle,
338343
List<IDisposable> toDispose,
339344
AssemblyRunInfo runInfo,
340345
Stopwatch stopwatch)
@@ -344,7 +349,7 @@ ManualResetEvent RunTestsInAssemblyAsync(IDiscoveryContext discoveryContext,
344349
{
345350
try
346351
{
347-
RunTestsInAssembly(discoveryContext, frameworkHandle, toDispose, runInfo, stopwatch);
352+
RunTestsInAssembly(frameworkHandle, toDispose, runInfo, stopwatch);
348353
}
349354
finally
350355
{

0 commit comments

Comments
 (0)