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

Translation Layer timeout #1843

Merged
merged 2 commits into from
Nov 20, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer
{
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;

using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources;
using CoreUtilitiesConstants = Microsoft.VisualStudio.TestPlatform.CoreUtilities.Constants;

/// <summary>
/// An implementation of <see cref="IVsTestConsoleWrapper"/> to invoke test operations
Expand All @@ -28,6 +34,8 @@ public class VsTestConsoleWrapper : IVsTestConsoleWrapper

private readonly ITranslationLayerRequestSender requestSender;

private readonly IProcessHelper processHelper;

private bool sessionStarted;

/// <summary>
Expand Down Expand Up @@ -63,7 +71,7 @@ public class VsTestConsoleWrapper : IVsTestConsoleWrapper
/// <param name="vstestConsolePath">Path to the test runner <c>vstest.console.exe</c>.</param>
/// <param name="consoleParameters">The parameters to be passed onto the runner process</param>
public VsTestConsoleWrapper(string vstestConsolePath, ConsoleParameters consoleParameters) :
this(new VsTestConsoleRequestSender(), new VsTestConsoleProcessManager(vstestConsolePath), consoleParameters, TestPlatformEventSource.Instance)
this(new VsTestConsoleRequestSender(), new VsTestConsoleProcessManager(vstestConsolePath), consoleParameters, TestPlatformEventSource.Instance, new ProcessHelper())
{
}

Expand All @@ -74,12 +82,14 @@ public class VsTestConsoleWrapper : IVsTestConsoleWrapper
/// <param name="processManager">Process manager.</param>
/// <param name="consoleParameters">The parameters to be passed onto the runner process</param>
/// <param name="testPlatformEventSource">Performance event source</param>
internal VsTestConsoleWrapper(ITranslationLayerRequestSender requestSender, IProcessManager processManager, ConsoleParameters consoleParameters, ITestPlatformEventSource testPlatformEventSource)
/// <param name="processHelper">Helper for process related utilities</param>
internal VsTestConsoleWrapper(ITranslationLayerRequestSender requestSender, IProcessManager processManager, ConsoleParameters consoleParameters, ITestPlatformEventSource testPlatformEventSource, IProcessHelper processHelper)
{
this.requestSender = requestSender;
this.vstestConsoleProcessManager = processManager;
this.consoleParameters = consoleParameters;
this.testPlatformEventSource = testPlatformEventSource;
this.processHelper = processHelper;
this.pathToAdditionalExtensions = new List<string>();

this.vstestConsoleProcessManager.ProcessExited += (sender, args) => this.requestSender.OnProcessExited();
Expand Down Expand Up @@ -263,20 +273,29 @@ private void EnsureInitialized()
EqtTrace.Info("VsTestConsoleWrapper.EnsureInitialized: Process Started.");
this.sessionStarted = this.WaitForConnection();
}

if (!this.sessionStarted)
{
throw new TransationLayerException("Error connecting to Vstest Command Line");
}
}

private bool WaitForConnection()
{
EqtTrace.Info("VsTestConsoleWrapper.WaitForConnection: Waiting for connection to command line runner.");
var connected = this.requestSender.WaitForRequestHandlerConnection(ConnectionTimeout);
this.testPlatformEventSource.TranslationLayerInitializeStop();

return connected;
var timeout = EnvironmentHelper.GetConnectionTimeout();
if (!this.requestSender.WaitForRequestHandlerConnection(timeout * 1000))
{
var processName = this.processHelper.GetCurrentProcessFileName();
throw new TransationLayerException(
string.Format(
CultureInfo.CurrentUICulture,
CommunicationUtilitiesResources.ConnectionTimeoutErrorMessage,
processName,
CoreUtilitiesConstants.VstestConsoleProcessName,
timeout,
EnvironmentHelper.VstestConnectionTimeout)
);
}

this.testPlatformEventSource.TranslationLayerInitializeStop();
return true;
}
}
}
15 changes: 12 additions & 3 deletions test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Moq;
Expand All @@ -23,6 +24,8 @@ public class VsTestConsoleWrapperTests

private Mock<IProcessManager> mockProcessManager;

private Mock<IProcessHelper> mockProcessHelper;

private Mock<ITranslationLayerRequestSender> mockRequestSender;

private readonly List<string> testSources = new List<string> { "Hello", "World" };
Expand All @@ -42,11 +45,13 @@ public void TestInitialize()

this.mockRequestSender = new Mock<ITranslationLayerRequestSender>();
this.mockProcessManager = new Mock<IProcessManager>();
this.mockProcessHelper = new Mock<IProcessHelper>();
this.consoleWrapper = new VsTestConsoleWrapper(
this.mockRequestSender.Object,
this.mockProcessManager.Object,
this.consoleParameters,
new Mock<ITestPlatformEventSource>().Object);
new Mock<ITestPlatformEventSource>().Object,
this.mockProcessHelper.Object);

this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);
this.mockRequestSender.Setup(rs => rs.InitializeCommunication()).Returns(100);
Expand Down Expand Up @@ -124,9 +129,11 @@ public void InitializeExtensionsShouldSucceed()
[TestMethod]
public void InitializeExtensionsShouldThrowExceptionOnBadConnection()
{
this.mockProcessHelper.Setup(x => x.GetCurrentProcessFileName()).Returns("DummyProcess");
this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(false);

Assert.ThrowsException<TransationLayerException>(() => this.consoleWrapper.InitializeExtensions(new List<string> { "Hello", "World" }));
var exception = Assert.ThrowsException<TransationLayerException>(() => this.consoleWrapper.InitializeExtensions(new List<string> { "Hello", "World" }));
Assert.AreEqual("DummyProcess process failed to connect to vstest.console process after 90 seconds. This may occur due to machine slowness, please set environment variable VSTEST_CONNECTION_TIMEOUT to increase timeout.", exception.Message);
this.mockRequestSender.Verify(rs => rs.InitializeExtensions(It.IsAny<IEnumerable<string>>()), Times.Never);
}

Expand Down Expand Up @@ -158,9 +165,11 @@ public void DiscoverTestsShouldCallTestDiscoveryHandler2IfTestDiscoveryHandler1I
[TestMethod]
public void DiscoverTestsShouldThrowExceptionOnBadConnection()
{
this.mockProcessHelper.Setup(x => x.GetCurrentProcessFileName()).Returns("DummyProcess");
this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(false);

Assert.ThrowsException<TransationLayerException>(() => this.consoleWrapper.DiscoverTests(new List<string> { "Hello", "World" }, null, null, new Mock<ITestDiscoveryEventsHandler2>().Object));
var exception = Assert.ThrowsException<TransationLayerException>(() => this.consoleWrapper.DiscoverTests(new List<string> { "Hello", "World" }, null, null, new Mock<ITestDiscoveryEventsHandler2>().Object));
Assert.AreEqual("DummyProcess process failed to connect to vstest.console process after 90 seconds. This may occur due to machine slowness, please set environment variable VSTEST_CONNECTION_TIMEOUT to increase timeout.", exception.Message);
this.mockRequestSender.Verify(rs => rs.DiscoverTests(It.IsAny<IEnumerable<string>>(), It.IsAny<string>(), null, It.IsAny<ITestDiscoveryEventsHandler2>()), Times.Never);
}

Expand Down