Handled conflicting values for DisableParallelization & NumberOfTestWorkers
MODIFY
src/NUnitTestAdapter/AdapterSettings.cs
src/NUnitTestAdapter/AdapterSettings.cs
@@ -206,11 +206,8 @@ namespace NUnit.VisualStudio.TestAdapter
DomainUsage = "None";
}
- // If DisableParallelization setting is passed from the testplatform, set the NumberOfTestWorkers to 0
- if(DisableParallelization)
- {
- NumberOfTestWorkers = 0;
- }
+ // Update NumberOfTestWorkers based on the DisableParallelization and NumberOfTestWorkers from runsettings.
+ UpdateNumberOfTestWorkers();
}
public void SaveRandomSeed(string dirname)
@@ -246,6 +243,19 @@ namespace NUnit.VisualStudio.TestAdapter
#region Helper Methods
+ private void UpdateNumberOfTestWorkers()
+ {
+ if(DisableParallelization && NumberOfTestWorkers <=0)
+ {
+ 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;
+ }
+ }
+
private string GetInnerText(XmlNode startNode, string xpath, params string[] validValues)
{
if (startNode != null)

MODIFY
src/NUnitTestAdapterTests/AdapterSettingsTests.cs
src/NUnitTestAdapterTests/AdapterSettingsTests.cs
@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using NUnit.Framework;
+using NUnit.VisualStudio.TestAdapter.Tests.Fakes;
namespace NUnit.VisualStudio.TestAdapter.Tests
{
@@ -15,7 +16,7 @@ namespace NUnit.VisualStudio.TestAdapter.Tests
[SetUp]
public void SetUp()
{
- _settings = new AdapterSettings(null);
+ _settings = new AdapterSettings(new TestLogger(new MessageLoggerStub(), 0));
}
[Test]
@@ -111,6 +112,15 @@ namespace NUnit.VisualStudio.TestAdapter.Tests
Assert.That(_settings.NumberOfTestWorkers, Is.EqualTo(0));
}
+ [Test]
+ public void UpdateNumberOfTestWorkersWhenConflictingSettings()
+ {
+ _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.
+ Assert.That(_settings.NumberOfTestWorkers, Is.EqualTo(0));
+ }
+
[Test]
public void DesignModeSetting()
{

Handled conflicting values for DisableParallelization & NumberOfTestWorkers