diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index fafb7058e8..c02675df99 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode { using System; using System.Collections.Generic; + using System.Globalization; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -14,22 +15,20 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; 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; /// /// The design mode client. /// public class DesignModeClient : IDesignModeClient { - /// - /// The timeout for the client to connect to the server. - /// - private const int ClientListenTimeOut = 5 * 1000; - private readonly ICommunicationManager communicationManager; private readonly IDataSerializer dataSerializer; @@ -96,17 +95,27 @@ public void ConnectToClientAndProcessRequests(int port, ITestRequestManager test EqtTrace.Info("Trying to connect to server on port : {0}", port); this.communicationManager.SetupClientAsync(new IPEndPoint(IPAddress.Loopback, port)); + var connectionTimeout = EnvironmentHelper.GetConnectionTimeout(); + // Wait for the connection to the server and listen for requests. - if (this.communicationManager.WaitForServerConnection(ClientListenTimeOut)) + if (this.communicationManager.WaitForServerConnection(connectionTimeout)) { this.communicationManager.SendMessage(MessageType.SessionConnected); this.ProcessRequests(testRequestManager); } else { - EqtTrace.Info("Client timed out while connecting to the server."); + EqtTrace.Error("DesignModeClient : ConnectToClientAndProcessRequests : Client timed out while connecting to the server."); this.Dispose(); - throw new TimeoutException(); + throw new TimeoutException( + string.Format( + CultureInfo.CurrentUICulture, + CommunicationUtilitiesResources.ConnectionTimeoutErrorMessage, + CoreUtilitiesConstants.VstestConsoleProcessName, + "translation layer", + connectionTimeout, + EnvironmentHelper.VstestConnectionTimeout) + ); } } diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs index bc9a5b0208..34cc1a21da 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs @@ -11,6 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities using System.Threading; using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; + using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; @@ -19,11 +20,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities /// public class SocketCommunicationManager : ICommunicationManager { - /// - /// Time for which the client wait for executor/runner process to start, and host server - /// - private const int CONNECTIONRETRYTIMEOUT = 50 * 1000; - /// /// The server stream read timeout constant (in microseconds). /// @@ -176,10 +172,12 @@ public async Task SetupClientAsync(IPEndPoint endpoint) Stopwatch watch = new Stopwatch(); watch.Start(); + var connectionTimeout = EnvironmentHelper.GetConnectionTimeout(); do { try { + EqtTrace.Verbose("SocketCommunicationManager : SetupClientAsync : Attempting to connect to the server."); await this.tcpClient.ConnectAsync(endpoint.Address, endpoint.Port); if (this.tcpClient.Connected) @@ -201,10 +199,10 @@ public async Task SetupClientAsync(IPEndPoint endpoint) } catch (Exception ex) { - EqtTrace.Verbose("Connection Failed with error {0}, retrying", ex.ToString()); + EqtTrace.Error("Connection Failed with error {0}, retrying", ex.ToString()); } } - while ((this.tcpClient != null) && !this.tcpClient.Connected && watch.ElapsedMilliseconds < CONNECTIONRETRYTIMEOUT); + while ((this.tcpClient != null) && !this.tcpClient.Connected && watch.ElapsedMilliseconds < connectionTimeout); } /// diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index 672d9b4164..b3415fda3c 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -28,8 +28,6 @@ public class VsTestConsoleWrapper : IVsTestConsoleWrapper { #region Private Members - private const int ConnectionTimeout = 30 * 1000; - private readonly IProcessManager vstestConsoleProcessManager; private readonly ITranslationLayerRequestSender requestSender; diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs index 7d828d0c0c..67f6a8471e 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs @@ -9,6 +9,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer using System.Threading.Tasks; 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; @@ -23,8 +24,6 @@ public class VsTestConsoleWrapperAsync : IVsTestConsoleWrapperAsync { #region Private Members - private const int ConnectionTimeout = 30 * 1000; - private readonly IProcessManager vstestConsoleProcessManager; private readonly ITranslationLayerRequestSenderAsync requestSender; @@ -93,8 +92,9 @@ public async Task StartSessionAsync() { this.testPlatformEventSource.TranslationLayerInitializeStart(); + var timeout = EnvironmentHelper.GetConnectionTimeout(); // Start communication - var port = await this.requestSender.InitializeCommunicationAsync(ConnectionTimeout); + var port = await this.requestSender.InitializeCommunicationAsync(timeout * 1000); if (port > 0) { diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs index 3707a3339e..42aa0fa34d 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs @@ -231,23 +231,5 @@ public void IncompatibleSourcesWarningShouldBeDisplayedInTheConsole(RunnerInfo r // When both x64 & x86 DLL is passed x64 dll will be ignored. this.StdOutputContains(expectedWarningContains); } - - [TestMethod] - [NetFullTargetFrameworkDataSource(useCoreRunner:false)] - public void ExecuteTestsForFramework35ShouldPrintErrorMessage(RunnerInfo runnerInfo) - { - AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); - var expectedWarningContains = "Framework35 is not supported. For projects targeting .Net Framework 3.5, please use Framework40 to run tests in CLR 4.0 \"compatibility mode\"."; - var assemblyPaths = this.GetAssetFullPath("SimpleTestProject.dll"); - - var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue, runnerInfo.InIsolationValue); - arguments = string.Concat(arguments, " /Framework:.NETFramework,Version=v3.5"); - - this.InvokeVsTest(arguments); - - this.ExitCodeEquals(1); - - this.StdErrorContains(expectedWarningContains); - } } } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs index 1f6b61202a..5ee70392f6 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs @@ -73,33 +73,6 @@ public void DiscoverTestsUsingDiscoveryEventHandler2AndTelemetryOptedOut(RunnerI Assert.AreEqual(0, this.discoveryEventHandler2.Metrics.Count); } - [TestMethod] - [NetFullTargetFrameworkDataSource] - public void DiscoverTestsShouldFailForFramework35(RunnerInfo runnerInfo) - { - AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); - this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message); - this.Setup(); - - string runSettingsXml = @" - - - Framework35 - true - - "; - - this.vstestConsoleWrapper.DiscoverTests( - this.GetTestAssemblies(), - runSettingsXml, - new TestPlatformOptions() { CollectMetrics = false }, - this.discoveryEventHandler2); - - Assert.AreEqual(1, this.discoveryEventHandler2.testMessages.Count); - StringAssert.Contains(this.discoveryEventHandler2.testMessages[0].message, "Framework35 is not supported. For projects targeting .Net Framework 3.5, please use Framework40 to run tests in CLR 4.0 \"compatibility mode\"."); - Assert.AreEqual(TestMessageLevel.Error, this.discoveryEventHandler2.testMessages[0].testMessageLevel); - } - [TestMethod] [NetFullTargetFrameworkDataSource] [NetCoreTargetFrameworkDataSource] diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index abd58c571e..443794f5e0 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -252,7 +252,8 @@ public void DesignModeClientOnBadConnectionShouldStopServerAndThrowTimeoutExcept { this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(false); - Assert.ThrowsException(() => this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object)); + var ex = Assert.ThrowsException(() => this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object)); + Assert.AreEqual("vstest.console process failed to connect to translation layer process after 90 seconds. This may occur due to machine slowness, please set environment variable VSTEST_CONNECTION_TIMEOUT to increase timeout.", ex.Message); this.mockCommunicationManager.Verify(cm => cm.SetupClientAsync(new IPEndPoint(IPAddress.Loopback, PortNumber)), Times.Once); this.mockCommunicationManager.Verify(cm => cm.WaitForServerConnection(It.IsAny()), Times.Once);