Skip to content

Commit

Permalink
Fixing the timeouts. (#1909)
Browse files Browse the repository at this point in the history
* Fixing the timeouts.
1. Made DesignModeClient timeout to connect to translation layer process configurable.
2. Removed redundant timeouts
3. ConnectionTimeout in VsTestConsoleWrapperAsync.

* Fixed the Acceptance tests related to Framework 3.5 changes
  • Loading branch information
singhsarab authored Feb 1, 2019
1 parent e16098b commit b7b6283
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 66 deletions.
25 changes: 17 additions & 8 deletions src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/// <summary>
/// The design mode client.
/// </summary>
public class DesignModeClient : IDesignModeClient
{
/// <summary>
/// The timeout for the client to connect to the server.
/// </summary>
private const int ClientListenTimeOut = 5 * 1000;

private readonly ICommunicationManager communicationManager;

private readonly IDataSerializer dataSerializer;
Expand Down Expand Up @@ -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 comment has been minimized.

Copy link
@ShreyasRmsft

ShreyasRmsft Feb 3, 2019

Member

shouldnt this have been x 1000?

{
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)
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,11 +20,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities
/// </summary>
public class SocketCommunicationManager : ICommunicationManager
{
/// <summary>
/// Time for which the client wait for executor/runner process to start, and host server
/// </summary>
private const int CONNECTIONRETRYTIMEOUT = 50 * 1000;

/// <summary>
/// The server stream read timeout constant (in microseconds).
/// </summary>
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
18 changes: 0 additions & 18 deletions test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @"<?xml version=""1.0"" encoding=""utf-8""?>
<RunSettings>
<RunConfiguration>
<TargetFrameworkVersion>Framework35</TargetFrameworkVersion>
<DesignMode>true</DesignMode>
</RunConfiguration>
</RunSettings>";

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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ public void DesignModeClientOnBadConnectionShouldStopServerAndThrowTimeoutExcept
{
this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny<int>())).Returns(false);

Assert.ThrowsException<TimeoutException>(() => this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object));
var ex = Assert.ThrowsException<TimeoutException>(() => 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<int>()), Times.Once);
Expand Down

0 comments on commit b7b6283

Please sign in to comment.