Honouring DisableParallelization only if it's True.
MODIFY
src/NUnitTestAdapter/AdapterSettings.cs
src/NUnitTestAdapter/AdapterSettings.cs
@@ -68,7 +68,7 @@ namespace NUnit.VisualStudio.TestAdapter
/// <summary>
/// If true, an adapter should disable any test case parallelization
/// </summary>
- public bool? DisableParallelization { get; private set; }
+ public bool DisableParallelization { get; private set; }
/// <summary>
/// True if test run is triggered in an IDE/Editor context.
@@ -147,7 +147,7 @@ namespace NUnit.VisualStudio.TestAdapter
TestAdapterPaths = GetInnerText(runConfiguration, "TestAdapterPaths");
CollectSourceInformation = GetInnerTextAsBool(runConfiguration, "CollectSourceInformation", true);
DisableAppDomain = GetInnerTextAsBool(runConfiguration, "DisableAppDomain", false);
- DisableParallelization = GetInnerTextAsNullableBool(runConfiguration, "DisableParallelization");
+ DisableParallelization = GetInnerTextAsBool(runConfiguration, "DisableParallelization", false);
DesignMode = GetInnerTextAsBool(runConfiguration, "DesignMode", false);
TestProperties = new Dictionary<string, string>();
@@ -245,26 +245,16 @@ namespace NUnit.VisualStudio.TestAdapter
private void UpdateNumberOfTestWorkers()
{
- if(!DisableParallelization.HasValue)
- {
- return;
- }
-
- if(DisableParallelization.Value && NumberOfTestWorkers < 0)
+ // Overriding the NumberOfTestWorkers if DisableParallelization is true.
+ if(DisableParallelization && NumberOfTestWorkers < 0)
{
NumberOfTestWorkers = 0;
}
- else if(DisableParallelization.Value && NumberOfTestWorkers > 0)
+ else if(DisableParallelization && NumberOfTestWorkers > 0)
{
_logger.Warning(string.Format("DisableParallelization:{0} & NumberOfTestWorkers:{1} are conflicting settings, hence not running in parallel", DisableParallelization, NumberOfTestWorkers));
NumberOfTestWorkers = 0;
}
- else if(!DisableParallelization.Value && NumberOfTestWorkers == 0)
- {
- _logger.Warning(string.Format("DisableParallelization:{0} & NumberOfTestWorkers:{1} are conflicting settings, hence running in parallel", DisableParallelization, NumberOfTestWorkers));
- // Setting it to less than zero, so that framework will decide it.
- NumberOfTestWorkers = -1;
- }
}
private string GetInnerText(XmlNode startNode, string xpath, params string[] validValues)

MODIFY
src/NUnitTestAdapterTests/AdapterSettingsTests.cs
src/NUnitTestAdapterTests/AdapterSettingsTests.cs
@@ -52,7 +52,7 @@ namespace NUnit.VisualStudio.TestAdapter.Tests
Assert.Null(_settings.DomainUsage);
Assert.False(_settings.InProcDataCollectorsAvailable);
Assert.IsFalse(_settings.DisableAppDomain);
- Assert.IsFalse(_settings.DisableParallelization.HasValue);
+ Assert.IsFalse(_settings.DisableParallelization);
Assert.IsFalse(_settings.DesignMode);
}
@@ -117,12 +117,14 @@ namespace NUnit.VisualStudio.TestAdapter.Tests
{
_settings.Load("<RunSettings><RunConfiguration><DisableParallelization>true</DisableParallelization></RunConfiguration><NUnit><NumberOfTestWorkers>12</NumberOfTestWorkers></NUnit></RunSettings>");
- // When there's a conflicting values in DisableParallelization and NumberOfTestWorkers. Falling back to DisableParallelization setting.
+ // When there's a conflicting values in DisableParallelization and NumberOfTestWorkers. Override the NumberOfTestWorkers.
Assert.That(_settings.NumberOfTestWorkers, Is.EqualTo(0));
+ // Do not override the NumberOfTestWorkers when DisableParallelization is False
_settings.Load("<RunSettings><RunConfiguration><DisableParallelization>false</DisableParallelization></RunConfiguration><NUnit><NumberOfTestWorkers>0</NumberOfTestWorkers></NUnit></RunSettings>");
- Assert.That(_settings.NumberOfTestWorkers, Is.EqualTo(-1));
+ Assert.That(_settings.NumberOfTestWorkers, Is.EqualTo(0));
+ // Do not override the NumberOfTestWorkers when DisableParallelization is not defined
_settings.Load("<RunSettings><RunConfiguration></RunConfiguration><NUnit><NumberOfTestWorkers>12</NumberOfTestWorkers></NUnit></RunSettings>");
Assert.That(_settings.NumberOfTestWorkers, Is.EqualTo(12));
}

Honouring DisableParallelization only if it's True.