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

BatchSize Runsettings #550

Merged
merged 4 commits into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions src/Microsoft.TestPlatform.ObjectModel/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public static class Constants
/// </summary>
public const int DefaultCpuCount = 1;

/// <summary>
/// The default batch size.
/// </summary>
public const long DefaultBatchSize = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this public?


/// <summary>
/// Name of the results directory
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ public class RunConfiguration : TestRunSettings
/// Maximum number of cores that the engine can use to run tests in parallel
/// </summary>
private int maxCpuCount;

/// <summary>
/// .Net framework which rocksteady should use for discovery/execution
/// </summary>
private Framework framework;

/// <summary>
/// Specifies the frequency of the runStats/discoveredTests event
/// </summary>
private long batchSize;

/// <summary>
/// Directory in which rocksteady/adapter should keep their run specific data.
/// </summary>
Expand Down Expand Up @@ -71,6 +76,7 @@ public RunConfiguration() : base(Constants.RunConfigurationSettingsName)
this.BinariesRoot = null;
this.testAdaptersPaths = null;
this.maxCpuCount = Constants.DefaultCpuCount;
this.batchSize = Constants.DefaultBatchSize;
this.disableAppDomain = false;
this.disableParallelization = false;
}
Expand Down Expand Up @@ -121,6 +127,22 @@ public int MaxCpuCount
}
}

/// <summary>
/// Gets or sets the frequency of the runStats/discoveredTests event. Should be non-negative integer.
/// </summary>
public long BatchSize
{
get
{
return this.batchSize;
}
set
{
this.batchSize = value;
this.BatchSizeSet = true;
}
}

/// <summary>
/// Gets or sets a value indicating whether app domain creation should be disabled.
/// </summary>
Expand Down Expand Up @@ -171,7 +193,7 @@ public Architecture TargetPlatform
this.TargetPlatformSet = true;
}
}

/// <summary>
/// Gets or sets the target Framework this run is targeting. Possible values are Framework3.5|Framework4.0|Framework4.5
/// </summary>
Expand Down Expand Up @@ -237,6 +259,15 @@ public bool MaxCpuCountSet
private set;
}

/// <summary>
/// Gets a value indicating batch size is set
/// </summary>
public bool BatchSizeSet
{
get;
private set;
}

/// <summary>
/// Gets a value indicating whether app domain needs to be disabled by the adapters.
/// </summary>
Expand Down Expand Up @@ -289,7 +320,7 @@ public bool ResultsDirectorySet
public string BinariesRoot { get; private set; }

#endregion

/// <inheritdoc/>
[SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver",
Justification = "XmlDocument.XmlResolver is not available in core. Suppress until fxcop issue is fixed.")]
Expand All @@ -311,6 +342,10 @@ public override XmlElement ToXml()
maxCpuCount.InnerXml = this.MaxCpuCount.ToString();
root.AppendChild(maxCpuCount);

XmlElement batchSize = doc.CreateElement("BatchSize");
batchSize.InnerXml = this.BatchSize.ToString();
root.AppendChild(batchSize);

XmlElement disableAppDomain = doc.CreateElement("DisableAppDomain");
disableAppDomain.InnerXml = this.DisableAppDomain.ToString();
root.AppendChild(disableAppDomain);
Expand Down Expand Up @@ -343,7 +378,7 @@ public override XmlElement ToXml()

return root;
}

/// <summary>
/// Loads RunConfiguration from XmlReader.
/// </summary>
Expand Down Expand Up @@ -390,6 +425,25 @@ public static RunConfiguration FromXml(XmlReader reader)
runConfiguration.MaxCpuCount = count;
break;

case "BatchSize":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

string batchSize = reader.ReadElementContentAsString();
long size;
if (!long.TryParse(batchSize, out size) || size < 0)
{
throw new SettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue,
Constants.RunConfigurationSettingsName,
batchSize,
elementName));
}

runConfiguration.BatchSize = size;
break;

case "DisableAppDomain":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

Expand Down
19 changes: 13 additions & 6 deletions src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;

/// <summary>
/// Defines the TestRequestManger which can fire off discovery and test run requests
Expand Down Expand Up @@ -54,8 +55,8 @@ internal class TestRequestManager : ITestRequestManager
public TestRequestManager() :
this(CommandLineOptions.Instance,
TestPlatformFactory.GetTestPlatform(),
TestLoggerManager.Instance,
TestRunResultAggregator.Instance,
TestLoggerManager.Instance,
TestRunResultAggregator.Instance,
TestPlatformEventSource.Instance)
{
}
Expand All @@ -75,7 +76,7 @@ internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform
{
var consoleLogger = new ConsoleLogger();
this.testLoggerManager.AddLogger(consoleLogger, ConsoleLogger.ExtensionUri, null);
}
}
}

#endregion
Expand Down Expand Up @@ -126,8 +127,11 @@ public bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscove

bool success = false;

var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(discoveryPayload.RunSettings);
var batchSize = runConfiguration.BatchSize;

// create discovery request
var criteria = new DiscoveryCriteria(discoveryPayload.Sources, this.commandLineOptions.BatchSize, this.commandLineOptions.TestStatsEventTimeout, discoveryPayload.RunSettings);
var criteria = new DiscoveryCriteria(discoveryPayload.Sources, batchSize, this.commandLineOptions.TestStatsEventTimeout, discoveryPayload.RunSettings);
using (IDiscoveryRequest discoveryRequest = this.testPlatform.CreateDiscoveryRequest(criteria))
{
try
Expand Down Expand Up @@ -182,12 +186,15 @@ public bool RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc
{
EqtTrace.Info("TestRequestManager.RunTests: run tests started.");

var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunRequestPayload.RunSettings);
var batchSize = runConfiguration.BatchSize;

TestRunCriteria runCriteria = null;
if (testRunRequestPayload.Sources != null && testRunRequestPayload.Sources.Any())
{
runCriteria = new TestRunCriteria(
testRunRequestPayload.Sources,
this.commandLineOptions.BatchSize,
batchSize,
testRunRequestPayload.KeepAlive,
testRunRequestPayload.RunSettings,
this.commandLineOptions.TestStatsEventTimeout,
Expand All @@ -198,7 +205,7 @@ public bool RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc
{
runCriteria = new TestRunCriteria(
testRunRequestPayload.TestCases,
this.commandLineOptions.BatchSize,
batchSize,
testRunRequestPayload.KeepAlive,
testRunRequestPayload.RunSettings,
this.commandLineOptions.TestStatsEventTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should move inside namespace?

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Microsoft.TestPlatform.ObjectModel.UnitTests
{
Expand All @@ -22,6 +19,7 @@ public void RunConfigurationDefaultValuesMustBeUsedOnCreation()
// Verify Default
Assert.AreEqual(Constants.DefaultPlatform, runConfiguration.TargetPlatform);
Assert.AreEqual(Framework.DefaultFramework, runConfiguration.TargetFrameworkVersion);
Assert.AreEqual(Constants.DefaultBatchSize, runConfiguration.BatchSize);
Assert.AreEqual(Constants.DefaultResultsDirectory, runConfiguration.ResultsDirectory);
Assert.AreEqual(null, runConfiguration.SolutionDirectory);
Assert.AreEqual(Constants.DefaultTreatTestAdapterErrorsAsWarnings, runConfiguration.TreatTestAdapterErrorsAsWarnings);
Expand Down Expand Up @@ -63,6 +61,7 @@ public void RunConfigurationReadsValuesCorrectlyFromXml()
<DisableAppDomain>true</DisableAppDomain>
<DisableParallelization>true</DisableParallelization>
<MaxCpuCount>2</MaxCpuCount>
<BatchSize>5</BatchSize>
<TestAdaptersPaths>C:\a\b;D:\x\y</TestAdaptersPaths>
<BinariesRoot>E:\x\z</BinariesRoot>
</RunConfiguration>
Expand All @@ -87,8 +86,41 @@ public void RunConfigurationReadsValuesCorrectlyFromXml()
Assert.AreEqual(@"E:\x\z", runConfiguration.BinariesRoot);
Assert.AreEqual(@"C:\a\b;D:\x\y", runConfiguration.TestAdaptersPaths);
Assert.AreEqual(2, runConfiguration.MaxCpuCount);
Assert.AreEqual(5, runConfiguration.BatchSize);
Assert.AreEqual(true, runConfiguration.DisableAppDomain);
Assert.AreEqual(true, runConfiguration.DisableParallelization);
}

[TestMethod]
public void RunConfigurationFromXmlThrowsSettingsExceptionIfBatchSizeIsInvalid()
{
string settingsXml =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<RunSettings>
<RunConfiguration>
<BatchSize>Foo</BatchSize>
</RunConfiguration>
</RunSettings>";

Assert.ThrowsException<SettingsException>(
() => XmlRunSettingsUtilities.GetRunConfigurationNode(settingsXml)
).Message.Equals("");
}

[TestMethod]
public void RunConfigurationFromXmlThrowsSettingsExceptionIfBatchSizeIsNegativeInteger()
{
string settingsXml =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<RunSettings>
<RunConfiguration>
<BatchSize>-10</BatchSize>
</RunConfiguration>
</RunSettings>";

Assert.ThrowsException<SettingsException>(
() => XmlRunSettingsUtilities.GetRunConfigurationNode(settingsXml)
).Message.Equals("");
}
}
}
Loading