Skip to content

Commit b7b6283

Browse files
authored
Fixing the timeouts. (#1909)
* 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
1 parent e16098b commit b7b6283

File tree

7 files changed

+27
-66
lines changed

7 files changed

+27
-66
lines changed

src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs

+17-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode
55
{
66
using System;
77
using System.Collections.Generic;
8+
using System.Globalization;
89
using System.Net;
910
using System.Threading;
1011
using System.Threading.Tasks;
@@ -14,22 +15,20 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode
1415
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
1516
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
1617
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;
18+
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
1719
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
1820
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
1921
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
2022
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
2123
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
24+
using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources;
25+
using CoreUtilitiesConstants = Microsoft.VisualStudio.TestPlatform.CoreUtilities.Constants;
2226

2327
/// <summary>
2428
/// The design mode client.
2529
/// </summary>
2630
public class DesignModeClient : IDesignModeClient
2731
{
28-
/// <summary>
29-
/// The timeout for the client to connect to the server.
30-
/// </summary>
31-
private const int ClientListenTimeOut = 5 * 1000;
32-
3332
private readonly ICommunicationManager communicationManager;
3433

3534
private readonly IDataSerializer dataSerializer;
@@ -96,17 +95,27 @@ public void ConnectToClientAndProcessRequests(int port, ITestRequestManager test
9695
EqtTrace.Info("Trying to connect to server on port : {0}", port);
9796
this.communicationManager.SetupClientAsync(new IPEndPoint(IPAddress.Loopback, port));
9897

98+
var connectionTimeout = EnvironmentHelper.GetConnectionTimeout();
99+
99100
// Wait for the connection to the server and listen for requests.
100-
if (this.communicationManager.WaitForServerConnection(ClientListenTimeOut))
101+
if (this.communicationManager.WaitForServerConnection(connectionTimeout))
101102
{
102103
this.communicationManager.SendMessage(MessageType.SessionConnected);
103104
this.ProcessRequests(testRequestManager);
104105
}
105106
else
106107
{
107-
EqtTrace.Info("Client timed out while connecting to the server.");
108+
EqtTrace.Error("DesignModeClient : ConnectToClientAndProcessRequests : Client timed out while connecting to the server.");
108109
this.Dispose();
109-
throw new TimeoutException();
110+
throw new TimeoutException(
111+
string.Format(
112+
CultureInfo.CurrentUICulture,
113+
CommunicationUtilitiesResources.ConnectionTimeoutErrorMessage,
114+
CoreUtilitiesConstants.VstestConsoleProcessName,
115+
"translation layer",
116+
connectionTimeout,
117+
EnvironmentHelper.VstestConnectionTimeout)
118+
);
110119
}
111120
}
112121

src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities
1111
using System.Threading;
1212
using System.Threading.Tasks;
1313
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
14+
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
1415
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
1516
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
1617

@@ -19,11 +20,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities
1920
/// </summary>
2021
public class SocketCommunicationManager : ICommunicationManager
2122
{
22-
/// <summary>
23-
/// Time for which the client wait for executor/runner process to start, and host server
24-
/// </summary>
25-
private const int CONNECTIONRETRYTIMEOUT = 50 * 1000;
26-
2723
/// <summary>
2824
/// The server stream read timeout constant (in microseconds).
2925
/// </summary>
@@ -176,10 +172,12 @@ public async Task SetupClientAsync(IPEndPoint endpoint)
176172

177173
Stopwatch watch = new Stopwatch();
178174
watch.Start();
175+
var connectionTimeout = EnvironmentHelper.GetConnectionTimeout();
179176
do
180177
{
181178
try
182179
{
180+
EqtTrace.Verbose("SocketCommunicationManager : SetupClientAsync : Attempting to connect to the server.");
183181
await this.tcpClient.ConnectAsync(endpoint.Address, endpoint.Port);
184182

185183
if (this.tcpClient.Connected)
@@ -201,10 +199,10 @@ public async Task SetupClientAsync(IPEndPoint endpoint)
201199
}
202200
catch (Exception ex)
203201
{
204-
EqtTrace.Verbose("Connection Failed with error {0}, retrying", ex.ToString());
202+
EqtTrace.Error("Connection Failed with error {0}, retrying", ex.ToString());
205203
}
206204
}
207-
while ((this.tcpClient != null) && !this.tcpClient.Connected && watch.ElapsedMilliseconds < CONNECTIONRETRYTIMEOUT);
205+
while ((this.tcpClient != null) && !this.tcpClient.Connected && watch.ElapsedMilliseconds < connectionTimeout);
208206
}
209207

210208
/// <summary>

src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public class VsTestConsoleWrapper : IVsTestConsoleWrapper
2828
{
2929
#region Private Members
3030

31-
private const int ConnectionTimeout = 30 * 1000;
32-
3331
private readonly IProcessManager vstestConsoleProcessManager;
3432

3533
private readonly ITranslationLayerRequestSender requestSender;

src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapperAsync.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer
99
using System.Threading.Tasks;
1010

1111
using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;
12+
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
1213
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;
1314
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces;
1415
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
@@ -23,8 +24,6 @@ public class VsTestConsoleWrapperAsync : IVsTestConsoleWrapperAsync
2324
{
2425
#region Private Members
2526

26-
private const int ConnectionTimeout = 30 * 1000;
27-
2827
private readonly IProcessManager vstestConsoleProcessManager;
2928

3029
private readonly ITranslationLayerRequestSenderAsync requestSender;
@@ -93,8 +92,9 @@ public async Task StartSessionAsync()
9392
{
9493
this.testPlatformEventSource.TranslationLayerInitializeStart();
9594

95+
var timeout = EnvironmentHelper.GetConnectionTimeout();
9696
// Start communication
97-
var port = await this.requestSender.InitializeCommunicationAsync(ConnectionTimeout);
97+
var port = await this.requestSender.InitializeCommunicationAsync(timeout * 1000);
9898

9999
if (port > 0)
100100
{

test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs

-18
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,5 @@ public void IncompatibleSourcesWarningShouldBeDisplayedInTheConsole(RunnerInfo r
231231
// When both x64 & x86 DLL is passed x64 dll will be ignored.
232232
this.StdOutputContains(expectedWarningContains);
233233
}
234-
235-
[TestMethod]
236-
[NetFullTargetFrameworkDataSource(useCoreRunner:false)]
237-
public void ExecuteTestsForFramework35ShouldPrintErrorMessage(RunnerInfo runnerInfo)
238-
{
239-
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
240-
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\".";
241-
var assemblyPaths = this.GetAssetFullPath("SimpleTestProject.dll");
242-
243-
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue, runnerInfo.InIsolationValue);
244-
arguments = string.Concat(arguments, " /Framework:.NETFramework,Version=v3.5");
245-
246-
this.InvokeVsTest(arguments);
247-
248-
this.ExitCodeEquals(1);
249-
250-
this.StdErrorContains(expectedWarningContains);
251-
}
252234
}
253235
}

test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs

-27
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,6 @@ public void DiscoverTestsUsingDiscoveryEventHandler2AndTelemetryOptedOut(RunnerI
7373
Assert.AreEqual(0, this.discoveryEventHandler2.Metrics.Count);
7474
}
7575

76-
[TestMethod]
77-
[NetFullTargetFrameworkDataSource]
78-
public void DiscoverTestsShouldFailForFramework35(RunnerInfo runnerInfo)
79-
{
80-
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);
81-
this.ExecuteNotSupportedRunnerFrameworkTests(runnerInfo.RunnerFramework, Netcoreapp, Message);
82-
this.Setup();
83-
84-
string runSettingsXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
85-
<RunSettings>
86-
<RunConfiguration>
87-
<TargetFrameworkVersion>Framework35</TargetFrameworkVersion>
88-
<DesignMode>true</DesignMode>
89-
</RunConfiguration>
90-
</RunSettings>";
91-
92-
this.vstestConsoleWrapper.DiscoverTests(
93-
this.GetTestAssemblies(),
94-
runSettingsXml,
95-
new TestPlatformOptions() { CollectMetrics = false },
96-
this.discoveryEventHandler2);
97-
98-
Assert.AreEqual(1, this.discoveryEventHandler2.testMessages.Count);
99-
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\".");
100-
Assert.AreEqual(TestMessageLevel.Error, this.discoveryEventHandler2.testMessages[0].testMessageLevel);
101-
}
102-
10376
[TestMethod]
10477
[NetFullTargetFrameworkDataSource]
10578
[NetCoreTargetFrameworkDataSource]

test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ public void DesignModeClientOnBadConnectionShouldStopServerAndThrowTimeoutExcept
252252
{
253253
this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny<int>())).Returns(false);
254254

255-
Assert.ThrowsException<TimeoutException>(() => this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object));
255+
var ex = Assert.ThrowsException<TimeoutException>(() => this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object));
256+
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);
256257

257258
this.mockCommunicationManager.Verify(cm => cm.SetupClientAsync(new IPEndPoint(IPAddress.Loopback, PortNumber)), Times.Once);
258259
this.mockCommunicationManager.Verify(cm => cm.WaitForServerConnection(It.IsAny<int>()), Times.Once);

0 commit comments

Comments
 (0)