Skip to content

Commit

Permalink
fixed parallel discovery bug by synchronizing list
Browse files Browse the repository at this point in the history
  • Loading branch information
csoltenborn committed Dec 6, 2017
1 parent 2f92e7b commit ffc306e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions GoogleTestAdapter/TestAdapter/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ private IEnumerable<TestCase> GetAllTestCasesInExecutables(IEnumerable<string> e

var discoveryActions = executables
.OrderBy(e => e)
.Select(executable => (Action) (() => AddTestCasesOfExecutable(allTestCasesInExecutables, executable, _settings.Clone(), _logger, () => _canceled)))
.Select(executable => (Action) (() =>
{
var testCases = GetTestCasesOfExecutable(executable, _settings.Clone(), _logger, () => _canceled);
lock (allTestCasesInExecutables)
{
allTestCasesInExecutables.AddRange(testCases);
}
}))
.ToArray();
Utils.SpawnAndWait(discoveryActions);

Expand All @@ -172,16 +179,20 @@ private IEnumerable<TestCase> GetAllTestCasesInExecutables(IEnumerable<string> e
return allTestCasesInExecutables;
}

private static void AddTestCasesOfExecutable(List<TestCase> allTestCasesInExecutables, string executable, SettingsWrapper settings, ILogger logger, Func<bool> testrunIsCanceled)
private static IList<TestCase> GetTestCasesOfExecutable(string executable, SettingsWrapper settings, ILogger logger, Func<bool> testrunIsCanceled)
{
IList<TestCase> testCases = new List<TestCase>();

if (testrunIsCanceled())
return;
return testCases;

var discoverer = new GoogleTestDiscoverer(logger, settings);
settings.ExecuteWithSettingsForExecutable(executable, () =>
{
allTestCasesInExecutables.AddRange(discoverer.GetTestsFromExecutable(executable));
testCases = discoverer.GetTestsFromExecutable(executable);
}, logger);

return testCases;
}

private ISet<string> GetAllTraitNames(IEnumerable<TestCase> testCases)
Expand Down

0 comments on commit ffc306e

Please sign in to comment.