@@ -5,14 +5,20 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer
5
5
{
6
6
using System . Collections . Generic ;
7
7
using System . Diagnostics ;
8
+ using System . Globalization ;
8
9
using System . Linq ;
9
10
10
11
using Microsoft . TestPlatform . VsTestConsole . TranslationLayer . Interfaces ;
12
+ using Microsoft . VisualStudio . TestPlatform . CoreUtilities . Helpers ;
11
13
using Microsoft . VisualStudio . TestPlatform . CoreUtilities . Tracing ;
12
14
using Microsoft . VisualStudio . TestPlatform . CoreUtilities . Tracing . Interfaces ;
13
15
using Microsoft . VisualStudio . TestPlatform . ObjectModel ;
14
16
using Microsoft . VisualStudio . TestPlatform . ObjectModel . Client ;
15
17
using Microsoft . VisualStudio . TestPlatform . ObjectModel . Client . Interfaces ;
18
+ using Microsoft . VisualStudio . TestPlatform . PlatformAbstractions ;
19
+ using Microsoft . VisualStudio . TestPlatform . PlatformAbstractions . Interfaces ;
20
+ using CommunicationUtilitiesResources = Microsoft . VisualStudio . TestPlatform . CommunicationUtilities . Resources . Resources ;
21
+ using CoreUtilitiesConstants = Microsoft . VisualStudio . TestPlatform . CoreUtilities . Constants ;
16
22
17
23
/// <summary>
18
24
/// An implementation of <see cref="IVsTestConsoleWrapper"/> to invoke test operations
@@ -28,6 +34,8 @@ public class VsTestConsoleWrapper : IVsTestConsoleWrapper
28
34
29
35
private readonly ITranslationLayerRequestSender requestSender ;
30
36
37
+ private readonly IProcessHelper processHelper ;
38
+
31
39
private bool sessionStarted ;
32
40
33
41
/// <summary>
@@ -63,7 +71,7 @@ public VsTestConsoleWrapper(string vstestConsolePath) :
63
71
/// <param name="vstestConsolePath">Path to the test runner <c>vstest.console.exe</c>.</param>
64
72
/// <param name="consoleParameters">The parameters to be passed onto the runner process</param>
65
73
public VsTestConsoleWrapper ( string vstestConsolePath , ConsoleParameters consoleParameters ) :
66
- this ( new VsTestConsoleRequestSender ( ) , new VsTestConsoleProcessManager ( vstestConsolePath ) , consoleParameters , TestPlatformEventSource . Instance )
74
+ this ( new VsTestConsoleRequestSender ( ) , new VsTestConsoleProcessManager ( vstestConsolePath ) , consoleParameters , TestPlatformEventSource . Instance , new ProcessHelper ( ) )
67
75
{
68
76
}
69
77
@@ -74,12 +82,14 @@ public VsTestConsoleWrapper(string vstestConsolePath, ConsoleParameters consoleP
74
82
/// <param name="processManager">Process manager.</param>
75
83
/// <param name="consoleParameters">The parameters to be passed onto the runner process</param>
76
84
/// <param name="testPlatformEventSource">Performance event source</param>
77
- internal VsTestConsoleWrapper ( ITranslationLayerRequestSender requestSender , IProcessManager processManager , ConsoleParameters consoleParameters , ITestPlatformEventSource testPlatformEventSource )
85
+ /// <param name="processHelper">Helper for process related utilities</param>
86
+ internal VsTestConsoleWrapper ( ITranslationLayerRequestSender requestSender , IProcessManager processManager , ConsoleParameters consoleParameters , ITestPlatformEventSource testPlatformEventSource , IProcessHelper processHelper )
78
87
{
79
88
this . requestSender = requestSender ;
80
89
this . vstestConsoleProcessManager = processManager ;
81
90
this . consoleParameters = consoleParameters ;
82
91
this . testPlatformEventSource = testPlatformEventSource ;
92
+ this . processHelper = processHelper ;
83
93
this . pathToAdditionalExtensions = new List < string > ( ) ;
84
94
85
95
this . vstestConsoleProcessManager . ProcessExited += ( sender , args ) => this . requestSender . OnProcessExited ( ) ;
@@ -263,20 +273,29 @@ private void EnsureInitialized()
263
273
EqtTrace . Info ( "VsTestConsoleWrapper.EnsureInitialized: Process Started." ) ;
264
274
this . sessionStarted = this . WaitForConnection ( ) ;
265
275
}
266
-
267
- if ( ! this . sessionStarted )
268
- {
269
- throw new TransationLayerException ( "Error connecting to Vstest Command Line" ) ;
270
- }
271
276
}
272
277
273
278
private bool WaitForConnection ( )
274
279
{
275
280
EqtTrace . Info ( "VsTestConsoleWrapper.WaitForConnection: Waiting for connection to command line runner." ) ;
276
- var connected = this . requestSender . WaitForRequestHandlerConnection ( ConnectionTimeout ) ;
277
- this . testPlatformEventSource . TranslationLayerInitializeStop ( ) ;
278
281
279
- return connected ;
282
+ var timeout = EnvironmentHelper . GetConnectionTimeout ( ) ;
283
+ if ( ! this . requestSender . WaitForRequestHandlerConnection ( timeout * 1000 ) )
284
+ {
285
+ var processName = this . processHelper . GetCurrentProcessFileName ( ) ;
286
+ throw new TransationLayerException (
287
+ string . Format (
288
+ CultureInfo . CurrentUICulture ,
289
+ CommunicationUtilitiesResources . ConnectionTimeoutErrorMessage ,
290
+ processName ,
291
+ CoreUtilitiesConstants . VstestConsoleProcessName ,
292
+ timeout ,
293
+ EnvironmentHelper . VstestConnectionTimeout )
294
+ ) ;
295
+ }
296
+
297
+ this . testPlatformEventSource . TranslationLayerInitializeStop ( ) ;
298
+ return true ;
280
299
}
281
300
}
282
301
}
0 commit comments