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

Honor cache timeout for discovery. #470

Merged
merged 4 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions src/vstest.console/CommandLine/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -164,9 +164,9 @@ public IEnumerable<string> Sources
public long BatchSize { get; set; }

/// <summary>
/// Specifies the timeout of the runStats event
/// Specifies the timeout of the test stats cache timeout event
/// </summary>
public TimeSpan TestRunStatsEventTimeout { get; set; }
public TimeSpan TestStatsEventTimeout { get; set; }

/// <summary>
/// Test case filter value for run with sources.
Expand Down
6 changes: 3 additions & 3 deletions src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, TimeSpan.MaxValue, discoveryPayload.RunSettings);
var criteria = new DiscoveryCriteria(discoveryPayload.Sources, this.commandLineOptions.BatchSize, this.commandLineOptions.TestStatsEventTimeout, discoveryPayload.RunSettings);
using (IDiscoveryRequest discoveryRequest = this.testPlatform.CreateDiscoveryRequest(criteria))
{
try
Expand Down Expand Up @@ -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;
}
Expand All @@ -201,7 +201,7 @@ public bool RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc
this.commandLineOptions.BatchSize,
testRunRequestPayload.KeepAlive,
testRunRequestPayload.RunSettings,
this.commandLineOptions.TestRunStatsEventTimeout,
this.commandLineOptions.TestStatsEventTimeout,
testHostLauncher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
46 changes: 46 additions & 0 deletions test/vstest.console.UnitTests/TestRequestManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,6 +31,12 @@ public TestRequestManagerTests()
this.mockLoggerManager = new DummyTestLoggerManager(this.mockLoggerEvents);
}

[TestCleanup]
public void Cleanup()
{
CommandLineOptions.Instance.Reset();
}

[TestMethod]
public void TestRequestManagerShouldInitializeConsoleLogger()
{
Expand All @@ -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<ITestPlatform>();

// Setup.
mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny<DiscoveryCriteria>()))
.Returns(new Mock<IDiscoveryRequest>().Object)
.Callback((DiscoveryCriteria criteria) => { receivedCriteria = criteria; });

var requestManager = new TestRequestManager(CommandLineOptions.Instance,
mockTestPlatform.Object,
this.mockLoggerManager,
TestRunResultAggregator.Instance,
new Mock<ITestPlatformEventSource>().Object);

// Act.
requestManager.DiscoverTests(new DiscoveryRequestPayload() { Sources = new List<string> { "C:\\somerandomfile.foo" } }, new Mock<ITestDiscoveryEventsRegistrar>().Object);

// Assert.
Assert.IsNotNull(receivedCriteria);
Assert.AreEqual(batchSize, receivedCriteria.FrequencyOfDiscoveredTestsEvent);
Assert.AreEqual(testStatsTimeout, receivedCriteria.DiscoveredTestEventTimeout);
}
}
}