Skip to content

Commit

Permalink
chore(performance): Parallel mutation in solution mode (#2893)
Browse files Browse the repository at this point in the history
* stopwatch

* Add parallel foreach

* Mutate projects in parallel

* Format

* Fix unit test

---------

Co-authored-by: Richard Werkman <richard.werkman@infosupport.com>
  • Loading branch information
richardwerkman and Richard Werkman authored Mar 29, 2024
1 parent d93b08c commit 0ab0ab3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Mono.Cecil;
using Stryker.Core.Baseline.Providers;
Expand Down Expand Up @@ -52,7 +53,7 @@ public IEnumerable<IMutationTestProcess> MutateProjects(StrykerOptions options,
if (!projectInfos.Any())
{
_logger.LogWarning("No project to mutate. Stryker will exit prematurely.");
yield break;
return Enumerable.Empty<IMutationTestProcess>();
}

_initializationProcess.BuildProjects(options, projectInfos);
Expand All @@ -63,10 +64,12 @@ public IEnumerable<IMutationTestProcess> MutateProjects(StrykerOptions options,
InitializeDashboardProjectInformation(options, projectInfos.First());
var inputs = _initializationProcess.GetMutationTestInputs(options, projectInfos, _runner);

foreach (var mutationTestInput in inputs)
var mutationTestProcesses = new List<IMutationTestProcess>();
Parallel.ForEach(inputs, mutationTestInput =>
{
yield return _projectMutator.MutateProject(options, mutationTestInput, reporters);
}
mutationTestProcesses.Add(_projectMutator.MutateProject(options, mutationTestInput, reporters));
});
return mutationTestProcesses;
}

private void InitializeDashboardProjectInformation(StrykerOptions options, SourceProjectInfo projectInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public CsharpMutationProcess(
/// This constructor is used by the <see cref="MutationTestProcess"/> initialization logic.
/// </summary>
/// <param name="options"></param>
public CsharpMutationProcess(StrykerOptions options) : this( null, options)
public CsharpMutationProcess(StrykerOptions options) : this(null, options)
{ }

public void Mutate(MutationTestInput input)
Expand All @@ -59,7 +59,7 @@ public void Mutate(MutationTestInput input)
var semanticModels = compilingProcess.GetSemanticModels(projectInfo.GetAllFiles().Cast<CsharpFileLeaf>().Select(x => x.SyntaxTree));

// Mutate source files
foreach (var file in projectInfo.GetAllFiles().Cast<CsharpFileLeaf>())
foreach(var file in projectInfo.GetAllFiles().Cast<CsharpFileLeaf>())
{
_logger.LogDebug($"Mutating {file.FullPath}");
// Mutate the syntax tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private CoverageRunResult BuildCoverageRunResultFromCoverageInfo(string property
leakedMutants = string.IsNullOrEmpty(propertyPairValue)
? Enumerable.Empty<int>()
: propertyPairValue.Split(',').Select(int.Parse);
_logger.LogWarning(
_logger.LogDebug(
$"VsTestRunner: Some mutations were executed outside any test (mutation ids: {propertyPairValue}).");
}
else
Expand Down

0 comments on commit 0ab0ab3

Please sign in to comment.