Skip to content

Commit

Permalink
Support multipler syntax in MSBuild runner
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Apr 20, 2024
1 parent 6790b48 commit b4aa876
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/xunit.runner.msbuild/xunit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@ public override bool Execute()
break;

default:
int threadValue;
if (!int.TryParse(MaxParallelThreads, out threadValue) || threadValue < 1)
{
Log.LogError("MaxParallelThreads value '{0}' is invalid: must be 'default', 'unlimited', or a positive number", MaxParallelThreads);
return false;
}

maxThreadCount = threadValue;
var match = ConfigUtility.MultiplierStyleMaxParallelThreadsRegex.Match(MaxParallelThreads);
// Use invariant format and convert ',' to '.' so we can always support both formats, regardless of locale
// If we stick to locale-only parsing, we could break people when moving from one locale to another (for example,
// from people running tests on their desktop in a comma locale vs. running them in CI with a decimal locale).
if (match.Success && decimal.TryParse(match.Groups[1].Value.Replace(',', '.'), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var maxThreadMultiplier))
maxThreadCount = (int)(maxThreadMultiplier * Environment.ProcessorCount);
else if (int.TryParse(MaxParallelThreads, out var threadValue) && threadValue > 0)
maxThreadCount = threadValue;
else
Log.LogError("MaxParallelThreads value '{0} is invalid: must be 'default', 'unlimited', a positive number, or a multiplier in the form of '{1}x')", MaxParallelThreads, 0.0m);
break;
}

Expand Down

0 comments on commit b4aa876

Please sign in to comment.