From ca5aadd9378e24d978314c79cac24640096897aa Mon Sep 17 00:00:00 2001 From: Abhitej Anoop John John Bandi Date: Sun, 12 Feb 2017 01:34:55 +0530 Subject: [PATCH 1/2] Nit fix to honor stats timeout instead of just passing max value. Since discovery is a very fast operation the batch size should be sufficient to trigger the discovery cache but just in case the batch size is made configurable and for some strange reason discovery is slow, this would help clear up the cache sooner. --- src/vstest.console/TestPlatformHelpers/TestRequestManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 1bfbd9b512..0e5d9d4ddb 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -123,7 +123,7 @@ public bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscove bool success = false; // create discovery request - var criteria = new DiscoveryCriteria(discoveryPayload.Sources, this.commandLineOptions.BatchSize, TimeSpan.MaxValue, discoveryPayload.RunSettings); + var criteria = new DiscoveryCriteria(discoveryPayload.Sources, this.commandLineOptions.BatchSize, this.commandLineOptions.TestRunStatsEventTimeout, discoveryPayload.RunSettings); using (IDiscoveryRequest discoveryRequest = this.testPlatform.CreateDiscoveryRequest(criteria)) { try From 64d1f5ce1e5874cd0bc7f798976d77920a1af2cd Mon Sep 17 00:00:00 2001 From: Abhitej Anoop John Bandi Date: Sun, 12 Feb 2017 20:16:06 +0530 Subject: [PATCH 2/2] Tests and rename. --- .../CommandLine/CommandLineOptions.cs | 6 +-- .../TestPlatformHelpers/TestRequestManager.cs | 6 +-- .../CommandLine/CommandLineOptionsTests.cs | 2 +- .../TestRequestManagerTests.cs | 46 +++++++++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/vstest.console/CommandLine/CommandLineOptions.cs b/src/vstest.console/CommandLine/CommandLineOptions.cs index 773559ac91..8a902dd482 100644 --- a/src/vstest.console/CommandLine/CommandLineOptions.cs +++ b/src/vstest.console/CommandLine/CommandLineOptions.cs @@ -81,7 +81,7 @@ internal static CommandLineOptions Instance private CommandLineOptions() { this.BatchSize = DefaultBatchSize; - this.TestRunStatsEventTimeout = this.DefaultRetrievalTimeout; + this.TestStatsEventTimeout = this.DefaultRetrievalTimeout; this.FileHelper = new FileHelper(); #if TODO UseVsixExtensions = Utilities.GetAppSettingValue(UseVsixExtensionsKey, false); @@ -164,9 +164,9 @@ public IEnumerable Sources public long BatchSize { get; set; } /// - /// Specifies the timeout of the runStats event + /// Specifies the timeout of the test stats cache timeout event /// - public TimeSpan TestRunStatsEventTimeout { get; set; } + public TimeSpan TestStatsEventTimeout { get; set; } /// /// Test case filter value for run with sources. diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index bab18a1e99..cbbb977ada 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -127,7 +127,7 @@ public bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscove bool success = false; // create discovery request - var criteria = new DiscoveryCriteria(discoveryPayload.Sources, this.commandLineOptions.BatchSize, this.commandLineOptions.TestRunStatsEventTimeout, discoveryPayload.RunSettings); + var criteria = new DiscoveryCriteria(discoveryPayload.Sources, this.commandLineOptions.BatchSize, this.commandLineOptions.TestStatsEventTimeout, discoveryPayload.RunSettings); using (IDiscoveryRequest discoveryRequest = this.testPlatform.CreateDiscoveryRequest(criteria)) { try @@ -190,7 +190,7 @@ public bool RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc this.commandLineOptions.BatchSize, testRunRequestPayload.KeepAlive, testRunRequestPayload.RunSettings, - this.commandLineOptions.TestRunStatsEventTimeout, + this.commandLineOptions.TestStatsEventTimeout, testHostLauncher); runCriteria.TestCaseFilter = this.commandLineOptions.TestCaseFilterValue; } @@ -201,7 +201,7 @@ public bool RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc this.commandLineOptions.BatchSize, testRunRequestPayload.KeepAlive, testRunRequestPayload.RunSettings, - this.commandLineOptions.TestRunStatsEventTimeout, + this.commandLineOptions.TestStatsEventTimeout, testHostLauncher); } diff --git a/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs b/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs index 4674e200df..35ce556d37 100644 --- a/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs +++ b/test/vstest.console.UnitTests/CommandLine/CommandLineOptionsTests.cs @@ -36,7 +36,7 @@ public void CommandLineOptionsDefaultBatchSizeIsTen() public void CommandLineOptionsDefaultTestRunStatsEventTimeoutIsOnePointFiveSec() { var timeout = new TimeSpan(0, 0, 0, 1, 500); - Assert.AreEqual(timeout, CommandLineOptions.Instance.TestRunStatsEventTimeout); + Assert.AreEqual(timeout, CommandLineOptions.Instance.TestStatsEventTimeout); } [TestMethod] diff --git a/test/vstest.console.UnitTests/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestRequestManagerTests.cs index db1da61a72..cdf9f3acfc 100644 --- a/test/vstest.console.UnitTests/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestRequestManagerTests.cs @@ -3,12 +3,19 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests { + using System; + using System.Collections.Generic; + + using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine; using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers; + using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestTools.UnitTesting; + + using Moq; using vstest.console.UnitTests.TestDoubles; @@ -24,6 +31,12 @@ public TestRequestManagerTests() this.mockLoggerManager = new DummyTestLoggerManager(this.mockLoggerEvents); } + [TestCleanup] + public void Cleanup() + { + CommandLineOptions.Instance.Reset(); + } + [TestMethod] public void TestRequestManagerShouldInitializeConsoleLogger() { @@ -49,5 +62,38 @@ public void TestRequestManagerShouldNotInitializeConsoleLoggerIfDesignModeIsSet( Assert.IsFalse(mockLoggerEvents.EventsSubscribed()); } + + [TestMethod] + public void DiscoverTestsShouldHonorStatsConfiguration() + { + // Arrange. + long batchSize = 512; + var testStatsTimeout = new TimeSpan(0, 0, 0, 59, 0); + + CommandLineOptions.Instance.BatchSize = batchSize; + CommandLineOptions.Instance.TestStatsEventTimeout = testStatsTimeout; + + DiscoveryCriteria receivedCriteria = null; + var mockTestPlatform = new Mock(); + + // Setup. + mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny())) + .Returns(new Mock().Object) + .Callback((DiscoveryCriteria criteria) => { receivedCriteria = criteria; }); + + var requestManager = new TestRequestManager(CommandLineOptions.Instance, + mockTestPlatform.Object, + this.mockLoggerManager, + TestRunResultAggregator.Instance, + new Mock().Object); + + // Act. + requestManager.DiscoverTests(new DiscoveryRequestPayload() { Sources = new List { "C:\\somerandomfile.foo" } }, new Mock().Object); + + // Assert. + Assert.IsNotNull(receivedCriteria); + Assert.AreEqual(batchSize, receivedCriteria.FrequencyOfDiscoveredTestsEvent); + Assert.AreEqual(testStatsTimeout, receivedCriteria.DiscoveredTestEventTimeout); + } } }