Skip to content

Commit

Permalink
Fix lookup issue exposed by STAFact and STATheory
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Feb 16, 2015
1 parent 3cb9c58 commit d1d0986
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class VsExecutionVisitor : TestMessageVisitor<ITestAssemblyFinished>
readonly Func<bool> cancelledThunk;
readonly ITestFrameworkExecutionOptions executionOptions;
readonly ITestExecutionRecorder recorder;
readonly Dictionary<ITestCase, TestCase> testCases;
readonly Dictionary<string, TestCase> testCases;

public VsExecutionVisitor(ITestExecutionRecorder recorder,
Dictionary<ITestCase, TestCase> testCases,
Dictionary<string, TestCase> testCases,
ITestFrameworkExecutionOptions executionOptions,
Func<bool> cancelledThunk)
{
Expand Down Expand Up @@ -66,7 +66,7 @@ protected override bool Visit(ITestSkipped testSkipped)

protected override bool Visit(ITestStarting testStarting)
{
recorder.RecordStart(testCases[testStarting.TestCase]);
recorder.RecordStart(testCases[testStarting.TestCase.UniqueID]);

return !cancelledThunk();
}
Expand Down Expand Up @@ -123,8 +123,7 @@ private VsTestResult MakeVsTestResult(TestOutcome outcome, ITestResultMessage te

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

var result = new VsTestResult(vsTestCase)
{
Expand Down
25 changes: 15 additions & 10 deletions xunit.runner.visualstudio.testadapter/VsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,20 @@ void RunTests(IRunContext runContext, IFrameworkHandle frameworkHandle, Stopwatc
using (AssemblyHelper.SubscribeResolve())
if (parallelizeAssemblies)
assemblies
.Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, toDispose, runInfo, stopwatch))
.Select(runInfo => RunTestsInAssemblyAsync(frameworkHandle, toDispose, runInfo, stopwatch))
.ToList()
.ForEach(@event => @event.WaitOne());
else
assemblies
.ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, toDispose, runInfo, stopwatch));
.ForEach(runInfo => RunTestsInAssembly(frameworkHandle, toDispose, runInfo, stopwatch));
}
finally
{
toDispose.ForEach(disposable => disposable.Dispose());
}
}

void RunTestsInAssembly(IDiscoveryContext discoveryContext,
IFrameworkHandle frameworkHandle,
void RunTestsInAssembly(IFrameworkHandle frameworkHandle,
List<IDisposable> toDispose,
AssemblyRunInfo runInfo,
Stopwatch stopwatch)
Expand Down Expand Up @@ -319,12 +318,19 @@ void RunTestsInAssembly(IDiscoveryContext discoveryContext,
lock (toDispose)
toDispose.Add(controller);

var xunitTestCases = runInfo.TestCases.ToDictionary(tc => controller.Deserialize(tc.GetPropertyValue<string>(SerializedTestCaseProperty, null)));
var testCaseMappings = runInfo.TestCases
.Select(tc => new
{
VsTestCase = tc,
XunitTestCase = controller.Deserialize(tc.GetPropertyValue<string>(SerializedTestCaseProperty, null))
})
.ToList();
var testCaseLookup = testCaseMappings.ToDictionary(tc => tc.XunitTestCase.UniqueID, tc => tc.VsTestCase);
var executionOptions = TestFrameworkOptions.ForExecution(runInfo.Configuration);

using (var executionVisitor = new VsExecutionVisitor(frameworkHandle, xunitTestCases, executionOptions, () => cancelled))
using (var executionVisitor = new VsExecutionVisitor(frameworkHandle, testCaseLookup, executionOptions, () => cancelled))
{
controller.RunTests(xunitTestCases.Keys.ToList(), executionVisitor, executionOptions);
controller.RunTests(testCaseMappings.Select(tc => tc.XunitTestCase).ToList(), executionVisitor, executionOptions);
executionVisitor.Finished.WaitOne();
}

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

ManualResetEvent RunTestsInAssemblyAsync(IDiscoveryContext discoveryContext,
IFrameworkHandle frameworkHandle,
ManualResetEvent RunTestsInAssemblyAsync(IFrameworkHandle frameworkHandle,
List<IDisposable> toDispose,
AssemblyRunInfo runInfo,
Stopwatch stopwatch)
Expand All @@ -344,7 +349,7 @@ ManualResetEvent RunTestsInAssemblyAsync(IDiscoveryContext discoveryContext,
{
try
{
RunTestsInAssembly(discoveryContext, frameworkHandle, toDispose, runInfo, stopwatch);
RunTestsInAssembly(frameworkHandle, toDispose, runInfo, stopwatch);
}
finally
{
Expand Down

0 comments on commit d1d0986

Please sign in to comment.