Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing incorrect logic when reducing to root test suite. Adding flags to allow for not reducing to root test suite. #331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GoogleTestAdapter/Core/GoogleTestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void ComputeTestRunner(ITestFrameworkReporter reporter, bool isBeingDebu
}
else
{
_runner = new PreparingTestRunner(reporter, _logger, _settings, _schedulingAnalyzer);
_runner = new PreparingTestRunner(reporter, _logger, _settings, _schedulingAnalyzer, true);
if (_settings.ParallelTestExecution && isBeingDebugged)
{
_logger.DebugInfo(
Expand Down
18 changes: 8 additions & 10 deletions GoogleTestAdapter/Core/Runners/CommandLineGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ internal Args(IList<TestCase> testCases, string commandLine)
private readonly string _resultXmlFile;
private readonly SettingsWrapper _settings;
private readonly string _userParameters;
private readonly bool _reduceToRootTestSuite;

public CommandLineGenerator(IEnumerable<TestCase> testCasesToRun,
int lengthOfExecutableString, string userParameters, string resultXmlFile,
SettingsWrapper settings)
SettingsWrapper settings, bool reduceToRootTestSuite)
{
_lengthOfExecutableString = lengthOfExecutableString;
_testCasesToRun = testCasesToRun.ToList();
_resultXmlFile = resultXmlFile;
_settings = settings;
_userParameters = userParameters ?? throw new ArgumentNullException(nameof(userParameters));
_reduceToRootTestSuite = reduceToRootTestSuite;
}

public IEnumerable<Args> GetCommandLines()
Expand Down Expand Up @@ -78,9 +80,8 @@ private IEnumerable<Args> GetFinalCommandLines(string baseCommandLine)
return commandLines;
}

List<string> suitesRunningAllTests = GetSuitesRunningAllTests();
List<string> suitesRunningAllTests = _reduceToRootTestSuite ? GetSuitesRunningAllTests() : new List<string>();
int maxSuiteLength = MaxCommandLength - _lengthOfExecutableString - userParam.Length - 1;

List<List<string>> suiteLists = GetSuiteListsForCommandLines(suitesRunningAllTests, maxSuiteLength);

// lambda to return the base commandline string (including suite filters) and the list of testcases to execute
Expand Down Expand Up @@ -286,14 +287,11 @@ private List<string> GetSuitesRunningAllTests()
foreach (string suite in GetAllSuitesOfTestCasesToRun())
{
List<TestCase> allMatchingTestCasesToBeRun = GetAllMatchingTestCases(_testCasesToRun, suite);
TestCaseMetaDataProperty metaData = allMatchingTestCasesToBeRun.First().Properties
.OfType<TestCaseMetaDataProperty>()
.SingleOrDefault();
if (metaData == null)
throw new Exception($"Test does not have meta data: {allMatchingTestCasesToBeRun.First()}");

if (allMatchingTestCasesToBeRun.Count == metaData.NrOfTestCasesInSuite)
if (allMatchingTestCasesToBeRun.All(_testCasesToRun.Contains)
&& allMatchingTestCasesToBeRun.Count == _testCasesToRun.Count)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, this still may not be strictly correct.

{
suitesRunningAllTests.Add(suite);
}
}
return suitesRunningAllTests;
}
Expand Down
2 changes: 1 addition & 1 deletion GoogleTestAdapter/Core/Runners/ParallelTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void RunTests(IEnumerable<TestCase> testCasesToRun, List<Thread> threads
int threadId = 0;
foreach (List<TestCase> testcases in splittedTestCasesToRun)
{
var runner = new PreparingTestRunner(threadId++, _frameworkReporter, _logger, _settings.Clone(), _schedulingAnalyzer);
var runner = new PreparingTestRunner(threadId++, _frameworkReporter, _logger, _settings.Clone(), _schedulingAnalyzer, false);
_testRunners.Add(runner);

var thread = new Thread(
Expand Down
8 changes: 4 additions & 4 deletions GoogleTestAdapter/Core/Runners/PreparingTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ public class PreparingTestRunner : ITestRunner
private readonly string _testDirectory;


public PreparingTestRunner(int threadId, ITestFrameworkReporter reporter, ILogger logger, SettingsWrapper settings, SchedulingAnalyzer schedulingAnalyzer)
public PreparingTestRunner(int threadId, ITestFrameworkReporter reporter, ILogger logger, SettingsWrapper settings, SchedulingAnalyzer schedulingAnalyzer, bool reduceToRootTestSuite)
{
_logger = logger;
_settings = settings;
string threadName = ComputeThreadName(threadId, _settings.MaxNrOfThreads);
_threadName = string.IsNullOrEmpty(threadName) ? "" : $"{threadName} ";
_threadId = Math.Max(0, threadId);
_testDirectory = Utils.GetTempDirectory();
_innerTestRunner = new SequentialTestRunner(_threadName, _threadId, _testDirectory, reporter, _logger, _settings, schedulingAnalyzer);
_innerTestRunner = new SequentialTestRunner(_threadName, _threadId, _testDirectory, reporter, _logger, _settings, schedulingAnalyzer, reduceToRootTestSuite);
}

public PreparingTestRunner(ITestFrameworkReporter reporter,
ILogger logger, SettingsWrapper settings, SchedulingAnalyzer schedulingAnalyzer)
: this(-1, reporter, logger, settings, schedulingAnalyzer){
ILogger logger, SettingsWrapper settings, SchedulingAnalyzer schedulingAnalyzer, bool reduceToRootTestSuite)
: this(-1, reporter, logger, settings, schedulingAnalyzer, reduceToRootTestSuite){
}


Expand Down
6 changes: 4 additions & 2 deletions GoogleTestAdapter/Core/Runners/SequentialTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public class SequentialTestRunner : ITestRunner
private readonly ILogger _logger;
private readonly SettingsWrapper _settings;
private readonly SchedulingAnalyzer _schedulingAnalyzer;
private readonly bool _reduceToRootTestSuite;

private IProcessExecutor _processExecutor;

public SequentialTestRunner(string threadName, int threadId, string testDir, ITestFrameworkReporter reporter, ILogger logger, SettingsWrapper settings, SchedulingAnalyzer schedulingAnalyzer)
public SequentialTestRunner(string threadName, int threadId, string testDir, ITestFrameworkReporter reporter, ILogger logger, SettingsWrapper settings, SchedulingAnalyzer schedulingAnalyzer, bool reduceToRootTestSuite)
{
_threadName = threadName;
_threadId = threadId;
Expand All @@ -40,6 +41,7 @@ public SequentialTestRunner(string threadName, int threadId, string testDir, ITe
_logger = logger;
_settings = settings;
_schedulingAnalyzer = schedulingAnalyzer;
_reduceToRootTestSuite = reduceToRootTestSuite;
}


Expand Down Expand Up @@ -90,7 +92,7 @@ private void RunTestsFromExecutable(string executable, string workingDir,
string resultXmlFile = Path.GetTempFileName();
var serializer = new TestDurationSerializer();

var generator = new CommandLineGenerator(testCasesToRun, executable.Length, userParameters, resultXmlFile, _settings);
var generator = new CommandLineGenerator(testCasesToRun, executable.Length, userParameters, resultXmlFile, _settings, _reduceToRootTestSuite);
foreach (CommandLineGenerator.Args arguments in generator.GetCommandLines())
{
if (_canceled)
Expand Down