diff --git a/GoogleTestAdapter/TestAdapter/TestExecutor.cs b/GoogleTestAdapter/TestAdapter/TestExecutor.cs index 804601d83..496ed7c91 100644 --- a/GoogleTestAdapter/TestAdapter/TestExecutor.cs +++ b/GoogleTestAdapter/TestAdapter/TestExecutor.cs @@ -162,7 +162,14 @@ private IEnumerable GetAllTestCasesInExecutables(IEnumerable 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); @@ -172,16 +179,20 @@ private IEnumerable GetAllTestCasesInExecutables(IEnumerable e return allTestCasesInExecutables; } - private static void AddTestCasesOfExecutable(List allTestCasesInExecutables, string executable, SettingsWrapper settings, ILogger logger, Func testrunIsCanceled) + private static IList GetTestCasesOfExecutable(string executable, SettingsWrapper settings, ILogger logger, Func testrunIsCanceled) { + IList testCases = new List(); + 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 GetAllTraitNames(IEnumerable testCases)