diff --git a/src/Microsoft.TestPlatform.Build/Tasks/VSTestForwardingApp.cs b/src/Microsoft.TestPlatform.Build/Tasks/VSTestForwardingApp.cs index 1625063eee..7ab3596282 100644 --- a/src/Microsoft.TestPlatform.Build/Tasks/VSTestForwardingApp.cs +++ b/src/Microsoft.TestPlatform.Build/Tasks/VSTestForwardingApp.cs @@ -58,7 +58,7 @@ public void Cancel() } catch(ArgumentException ex) { - Tracing.Trace(string.Format("VSTest: Killing process throws ArgumentException with the following message {0}. It may be that process is not running", ex.Message)); + Tracing.Trace(string.Format("VSTest: Killing process throws ArgumentException with the following message {0}. It may be that process is not running", ex)); } } } diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 8320aeaaca..419f6d24d6 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -136,7 +136,11 @@ private void ProcessRequests(ITestRequestManager testRequestManager) { var message = this.communicationManager.ReceiveMessage(); - EqtTrace.Info("DesignModeClient: Processing Message of message type: {0}", message.MessageType); + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("DesignModeClient.ProcessRequests: Processing Message: {0}", message); + } + switch (message.MessageType) { case MessageType.VersionCheck: diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs index 56e6113c1e..0d7180d0a5 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs @@ -131,7 +131,7 @@ public List GetAttachments(DataCollectionContext dataCollectionCo } catch (Exception ex) { - EqtTrace.Error(ex.Message); + EqtTrace.Error("DataCollectionAttachmentManager.GetAttachments: Fail to get attachments: {0} ", ex); } List attachments = new List(); @@ -295,7 +295,7 @@ private void AddNewFileTransfer(FileTransferInformation fileTransferInfo, AsyncC catch (Exception ex) { this.LogError( - ex.Message, + ex.ToString(), uri, friendlyName, Guid.Parse(testCaseId)); diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs index 0d529994e1..9ffe6861cd 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs @@ -450,7 +450,7 @@ private void LoadAndInitialize(DataCollectorSettings dataCollectorSettings, stri } // Log error. - dataCollectorInfo.Logger.LogError(this.dataCollectionEnvironmentContext.SessionDataCollectionContext, string.Format(CultureInfo.CurrentCulture, Resources.Resources.DataCollectorInitializationError, dataCollectorConfig.FriendlyName, ex.Message)); + dataCollectorInfo.Logger.LogError(this.dataCollectionEnvironmentContext.SessionDataCollectionContext, string.Format(CultureInfo.CurrentCulture, Resources.Resources.DataCollectorInitializationError, dataCollectorConfig.FriendlyName, ex)); // Dispose datacollector. dataCollectorInfo.DisposeDataCollector(); diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/VSExtensionManager.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/VSExtensionManager.cs index 5ab02e1d03..75e3b0825f 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/VSExtensionManager.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/VSExtensionManager.cs @@ -62,7 +62,7 @@ public IEnumerable GetUnitTestExtensions() } catch (Exception ex) { - string message = string.Format(CultureInfo.CurrentCulture, Resources.FailedToFindInstalledUnitTestExtensions, ex.Message); + string message = string.Format(CultureInfo.CurrentCulture, Resources.FailedToFindInstalledUnitTestExtensions, ex); throw new TestPlatformException(message, ex); } } diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs index 6d5908923d..5b6245163f 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs @@ -164,6 +164,12 @@ public void ProcessRequests() do { var message = this.communicationManager.ReceiveMessage(); + + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("DataCollectionRequestHandler.ProcessRequests : Datacollector received message: {0}", message); + } + switch (message.MessageType) { case MessageType.BeforeTestRunStart: @@ -214,7 +220,7 @@ public void ProcessRequests() { EqtTrace.Error( "DataCollectionRequestHandler.ProcessRequests : Error occured during initialization of TestHost : {0}", - e.Message); + e); } } }, @@ -253,7 +259,7 @@ public void ProcessRequests() { if (EqtTrace.IsErrorEnabled) { - EqtTrace.Error("DataCollectionRequestHandler.ProcessRequests : {0}", ex.Message); + EqtTrace.Error("DataCollectionRequestHandler.ProcessRequests : {0}", ex.ToString()); } } diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs index b39d6bb7b7..2dd998270b 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs @@ -55,6 +55,11 @@ internal DataCollectionRequestSender(ICommunicationManager communicationManager, /// Port number public int InitializeCommunication() { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("DataCollectionRequestSender.InitializeCommunication : Initialize communication. "); + } + var endpoint = this.communicationManager.HostServer(new IPEndPoint(IPAddress.Loopback, 0)); this.communicationManager.AcceptClientAsync(); return endpoint.Port; @@ -67,6 +72,11 @@ public int InitializeCommunication() /// True, if Handler is connected public bool WaitForRequestHandlerConnection(int clientConnectionTimeout) { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("DataCollectionRequestSender.WaitForRequestHandlerConnection : Waiting for connection with timeout: {0}", clientConnectionTimeout); + } + return this.communicationManager.WaitForClientConnection(clientConnectionTimeout); } @@ -97,12 +107,22 @@ public BeforeTestRunStartResult SendBeforeTestRunStartAndGetResult(string settin var isDataCollectionStarted = false; BeforeTestRunStartResult result = null; + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("DataCollectionRequestSender.SendBeforeTestRunStartAndGetResult : Send BeforeTestRunStart message with settingsXml: {0}", settingsXml); + } + this.communicationManager.SendMessage(MessageType.BeforeTestRunStart, settingsXml); while (!isDataCollectionStarted) { var message = this.communicationManager.ReceiveMessage(); + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("DataCollectionRequestSender.SendBeforeTestRunStartAndGetResult : Received message: {0}", message); + } + if (message.MessageType == MessageType.DataCollectionMessage) { var dataCollectionMessageEventArgs = this.dataSerializer.DeserializePayload(message); @@ -124,6 +144,11 @@ public Collection SendAfterTestRunStartAndGetResult(ITestMessageE var isDataCollectionComplete = false; Collection attachmentSets = null; + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("DataCollectionRequestSender.SendAfterTestRunStartAndGetResult : Send AfterTestRunEnd message with isCancelled: {0}", isCancelled); + } + this.communicationManager.SendMessage(MessageType.AfterTestRunEnd, isCancelled); // Cycle through the messages that the datacollector sends. @@ -132,6 +157,11 @@ public Collection SendAfterTestRunStartAndGetResult(ITestMessageE { var message = this.communicationManager.ReceiveMessage(); + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("DataCollectionRequestSender.SendAfterTestRunStartAndGetResult : Received message: {0}", message); + } + if (message.MessageType == MessageType.DataCollectionMessage) { var dataCollectionMessageEventArgs = this.dataSerializer.DeserializePayload(message); diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs index 1d7fe6efe6..093a19b7d2 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs @@ -196,7 +196,7 @@ public async Task SetupClientAsync(IPEndPoint endpoint) } catch (Exception ex) { - EqtTrace.Verbose("Connection Failed with error {0}, retrying", ex.Message); + EqtTrace.Verbose("Connection Failed with error {0}, retrying", ex.ToString()); } } while ((this.tcpClient != null) && !this.tcpClient.Connected && watch.ElapsedMilliseconds < CONNECTIONRETRYTIMEOUT); diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs index 9e68a20d34..bf570335fe 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs @@ -6,7 +6,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities using System; using System.Collections.Generic; using System.Globalization; - using System.Net; using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; @@ -110,6 +109,11 @@ internal TestRequestSender( /// public int InitializeCommunication() { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.InitializeCommunication: initialize communication. "); + } + // this.clientExitCancellationSource = new CancellationTokenSource(); this.clientExitErrorMessage = string.Empty; @@ -133,6 +137,11 @@ public int InitializeCommunication() /// public bool WaitForRequestHandlerConnection(int connectionTimeout) { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.WaitForRequestHandlerConnection: waiting for connection with timeout: {0}", connectionTimeout); + } + return this.connected.Wait(connectionTimeout); } @@ -148,22 +157,21 @@ public void CheckVersionWithTestHost() { var message = this.dataSerializer.DeserializeMessage(args.Data); + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.CheckVersionWithTestHost: onMessageReceived received message: {0}", message); + } + if (message.MessageType == MessageType.VersionCheck) { this.protocolVersion = this.dataSerializer.DeserializePayload(message); - - EqtTrace.Info(@"TestRequestSender: VersionCheck Succeeded, NegotiatedVersion = {0}", this.protocolVersion); } // TRH can also send TestMessage if tracing is enabled, so log it at runner end else if (message.MessageType == MessageType.TestMessage) { - // Only Deserialize if Tracing is enabled - if (EqtTrace.IsInfoEnabled) - { - var testMessagePayload = this.dataSerializer.DeserializePayload(message); - EqtTrace.Info("TestRequestSender.CheckVersionWithTestHost: " + testMessagePayload.Message); - } + // Ignore test messages. Currently we don't have handler(which sends messages to client/console.) here. + // Above we are logging it to EqtTrace. } else if (message.MessageType == MessageType.ProtocolError) { @@ -242,6 +250,11 @@ public void InitializeExecution(IEnumerable pathToAdditionalExtensions) MessageType.ExecutionInitialize, pathToAdditionalExtensions, this.protocolVersion); + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.InitializeExecution: Sending initializing execution with message: {0}", message); + } + this.channel.Send(message); } @@ -260,6 +273,12 @@ public void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsH MessageType.StartTestExecutionWithSources, runCriteria, this.protocolVersion); + + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.StartTestRun: Sending test run with message: {0}", message); + } + this.channel.Send(message); } @@ -278,18 +297,33 @@ public void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHan MessageType.StartTestExecutionWithTests, runCriteria, this.protocolVersion); + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.StartTestRun: Sending test run with message: {0}", message); + } + this.channel.Send(message); } /// public void SendTestRunCancel() { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.SendTestRunCancel: Sending test run cancel."); + } + this.channel?.Send(this.dataSerializer.SerializeMessage(MessageType.CancelTestRun)); } /// public void SendTestRunAbort() { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.SendTestRunAbort: Sending test run abort."); + } + this.channel?.Send(this.dataSerializer.SerializeMessage(MessageType.AbortTestRun)); } @@ -300,6 +334,11 @@ public void EndSession() { if (!this.IsOperationComplete()) { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.EndSession: Sending end session."); + } + this.channel.Send(this.dataSerializer.SerializeMessage(MessageType.SessionEnd)); } } @@ -309,7 +348,12 @@ public void OnClientProcessExit(string stdError) { // This method is called on test host exit. If test host has any errors, stdError // provides the crash call stack. - EqtTrace.Info("TestRequestSender.OnClientProcessExit: Test host process exited. Standard error: " + stdError); + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("TestRequestSender.OnClientProcessExit: Test host process exited. Standard error: " + + stdError); + } + this.clientExitErrorMessage = stdError; this.clientExited.Set(); @@ -340,6 +384,10 @@ private void OnExecutionMessageReceived(object sender, MessageReceivedEventArgs try { var rawMessage = messageReceived.Data; + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.OnExecutionMessageReceived: Received message: {0}", rawMessage); + } // Send raw message first to unblock handlers waiting to send message to IDEs testRunEventsHandler.HandleRawMessage(rawMessage); @@ -375,6 +423,10 @@ private void OnExecutionMessageReceived(object sender, MessageReceivedEventArgs MessageType.LaunchAdapterProcessWithDebuggerAttachedCallback, processId, this.protocolVersion); + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.OnExecutionMessageReceived: Sending LaunchAdapterProcessWithDebuggerAttachedCallback message: {0}", data); + } this.channel.Send(data); break; @@ -393,9 +445,9 @@ private void OnDiscoveryMessageReceived(ITestDiscoveryEventsHandler2 discoveryEv var rawMessage = args.Data; // Currently each of the operations are not separate tasks since they should not each take much time. This is just a notification. - if (EqtTrace.IsInfoEnabled) + if (EqtTrace.IsVerboseEnabled) { - EqtTrace.Info("TestRequestSender: Received message: {0}", rawMessage); + EqtTrace.Verbose("TestRequestSender.OnDiscoveryMessageReceived: Received message: {0}", rawMessage); } // Send raw message first to unblock handlers waiting to send message to IDEs @@ -539,6 +591,11 @@ private bool IsOperationComplete() private void SetOperationComplete() { // Complete the currently ongoing operation (Discovery/Execution) + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("TestRequestSender.SetOperationComplete: Setting operation complete."); + } + Interlocked.CompareExchange(ref this.operationCompleted, 1, 0); } @@ -563,4 +620,4 @@ private void SetCommunicationEndPoint() } } } -} +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs index 82126e78da..c62c0cb4dd 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs @@ -111,7 +111,7 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve EqtTrace.Error("ProxyDiscoveryManager.DiscoverTests: Failed to discover tests: {0}", exception); // Log to vs ide test output - var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.Message }; + var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.ToString() }; var rawMessage = this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload); this.HandleRawMessage(rawMessage); @@ -120,7 +120,7 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve // Aborted is `true`: in case of parallel discovery (or non shared host), an aborted message ensures another discovery manager // created to replace the current one. This will help if the current discovery manager is aborted due to irreparable error // and the test host is lost as well. - this.HandleLogMessage(TestMessageLevel.Error, exception.Message); + this.HandleLogMessage(TestMessageLevel.Error, exception.ToString()); var discoveryCompleteEventsArgs = new DiscoveryCompleteEventArgs(-1, true); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs index c64ec9f2c7..0252c39484 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs @@ -152,7 +152,7 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH catch (Exception exception) { EqtTrace.Error("ProxyExecutionManager.StartTestRun: Failed to start test run: {0}", exception); - this.LogMessage(TestMessageLevel.Error, exception.Message); + this.LogMessage(TestMessageLevel.Error, exception.ToString()); // Send a run complete to caller. Similar logic is also used in ParallelProxyExecutionManager.StartTestRunOnConcurrentManager // Aborted is `true`: in case of parallel run (or non shared host), an aborted message ensures another execution manager diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs index 687066c8ce..89b59fde03 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs @@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection using System; using System.Collections.Generic; using System.Collections.ObjectModel; + using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -34,6 +35,9 @@ internal class ProxyDataCollectionManager : IProxyDataCollectionManager private const string PortOption = "--port"; private const string DiagOption = "--diag"; private const string ParentProcessIdOption = "--parentprocessid"; + public const int DataCollectorConnectionTimeout = 30 * 1000; // In milliseconds. + public const string TimeoutEnvironmentVaribleName = "VSTEST_DATACOLLECTOR_CONNECTION_TIMEOUT"; + public const string DebugEnvironmentVaribleName = "VSTEST_DATACOLLECTOR_DEBUG"; private IDataCollectionRequestSender dataCollectionRequestSender; private IDataCollectionLauncher dataCollectionLauncher; @@ -100,7 +104,7 @@ internal ProxyDataCollectionManager(IRequestData requestData, string settingsXml this.dataCollectionRequestSender = dataCollectionRequestSender; this.dataCollectionLauncher = dataCollectionLauncher; this.processHelper = processHelper; - this.connectionTimeout = 5 * 1000; + this.connectionTimeout = ProxyDataCollectionManager.DataCollectorConnectionTimeout; this.LogEnabledDataCollectors(); } @@ -182,19 +186,34 @@ public void Initialize() // Warn the user that execution will wait for debugger attach. var processId = this.dataCollectionLauncher.LaunchDataCollector(null, this.GetCommandLineArguments(port)); - var dataCollectorDebugEnabled = Environment.GetEnvironmentVariable("VSTEST_DATACOLLECTOR_DEBUG"); - if (!string.IsNullOrEmpty(dataCollectorDebugEnabled) && dataCollectorDebugEnabled.Equals("1", StringComparison.Ordinal)) + ChangeConnectionTimeoutIfRequired(processId); + var connected = this.dataCollectionRequestSender.WaitForRequestHandlerConnection(this.connectionTimeout); + if (connected == false) + { + throw new TestPlatformException(string.Format(CultureInfo.CurrentUICulture, CrossPlatEngineResources.FailedToConnectDataCollector)); + } + } + + private void ChangeConnectionTimeoutIfRequired(int processId) + { + // Increase connection timeout when debugging is enabled. + var dataCollectorDebugEnabled = Environment.GetEnvironmentVariable(DebugEnvironmentVaribleName); + if (!string.IsNullOrEmpty(dataCollectorDebugEnabled) && + dataCollectorDebugEnabled.Equals("1", StringComparison.Ordinal)) { ConsoleOutput.Instance.WriteLine(CrossPlatEngineResources.DataCollectorDebuggerWarning, OutputLevel.Warning); ConsoleOutput.Instance.WriteLine( string.Format("Process Id: {0}, Name: {1}", processId, this.processHelper.GetProcessName(processId)), OutputLevel.Information); - - // Increase connection timeout when debugging is enabled. this.connectionTimeout = 5 * this.connectionTimeout; } - this.dataCollectionRequestSender.WaitForRequestHandlerConnection(this.connectionTimeout); + // Change connection timeout if user specified environment variable VSTEST_DATACOLLECTOR_CONNECTION_TIMEOUT. + var userSpecifiedTimeout = Environment.GetEnvironmentVariable(TimeoutEnvironmentVaribleName); + if (!string.IsNullOrEmpty(userSpecifiedTimeout) && Int32.TryParse(userSpecifiedTimeout, out int result)) + { + this.connectionTimeout = result * 1000; + } } private void InvokeDataCollectionServiceAction(Action action, ITestMessageEventHandler runEventsHandler) @@ -230,7 +249,7 @@ private void HandleExceptionMessage(ITestMessageEventHandler runEventsHandler, E EqtTrace.Error(exception); } - runEventsHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, exception.Message); + runEventsHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, exception.ToString()); } private IList GetCommandLineArguments(int portNumber) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs index 8ff5b92acd..1060128bef 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs @@ -129,7 +129,7 @@ private void LoadTestsFromAnExtension(string extensionAssembly, IEnumerable + /// Looks up a localized string similar to Failed to connect to datacollector process.. + /// + internal static string FailedToConnectDataCollector { + get { + return ResourceManager.GetString("FailedToConnectDataCollector", resourceCulture); + } + } + /// /// Looks up a localized string similar to Failed to launch testhost with error: {0}. /// diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx index d757b30a89..9c5444edee 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx @@ -189,4 +189,7 @@ You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + + Failed to connect to datacollector process. + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf index 19419347c4..d1875ce2e1 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ Používáte starší verzi sady Microsoft.NET.Test.Sdk. Přejděte prosím na verzi 15.3.0 nebo vyšší. + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf index 911c9621ed..d2a9e1ce6a 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ Sie verwenden eine ältere Version von Microsoft.NET.Test.Sdk. Wechseln Sie zu Version 15.3.0 oder höher. + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf index 3ae4979e84..ad583b5fe7 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ Está utilizando una versión anterior de Microsoft.NET.Test.Sdk. Cámbiese a una versión igual o superior a 15.3.0. + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf index 65d27a36e9..553f8f2c53 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ Vous utilisez une ancienne version de Microsoft.NET.Test.Sdk. Passez à une version égale ou supérieure à la version 15.3.0. + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf index 37fca9c862..33a0c8611d 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ La versione di Microsoft.NET.Test.Sdk è obsoleta. Passare alla versione 15.3.0 o a una versione successiva. + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf index 16c6cfd130..565e3a66f9 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ Microsoft.NET.Test.Sdk の古いバージョンを使用しています。15.3.0 以降のバージョンに移行することをお勧めします。 + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf index a7701adcd1..a45d854dd6 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ 이전 버전의 Microsoft.NET.Test.Sdk를 사용하고 있습니다. 15.3.0 이상 버전으로 이동하세요. + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf index 9ea1fa0101..ae48a217ca 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ Używamy starszej wersji zestawu Microsoft.NET.Test.Sdk. Przejdź na wersję 15.3.0 lub nowszą. + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf index 81a974b795..3f5d359d98 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ Você está usando uma versão mais antiga do Microsoft.NET.Test.Sdk. Mude para uma versão igual ou maior que 15.3.0. + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf index d7b7025d06..aa961d93b0 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ Вы используете более старую версию Microsoft.NET.Test.Sdk. Перейдите на версию 15.3.0 или более позднюю. + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf index b1e65c204a..341ebaffbc 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ Eski bir Microsoft.NET.Test.Sdk sürümü kullanıyorsunuz. Lütfen 15.3.0 veya daha yeni bir sürüme geçin. + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf index 9065983d4e..ff42d08ab4 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf @@ -102,6 +102,11 @@ You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf index 2794a7edd1..6869392d9b 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ 你使用的是旧版 Microsoft.NET.Test.Sdk。请迁移到 15.3.0 及更高版本。 + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf index afebc9e83d..e1c1947cb4 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf @@ -1,4 +1,4 @@ - +
@@ -191,6 +191,11 @@ 您正使用較舊版的 Microsoft.NET.Test.Sdk。請移到等於或大於 15.3.0 的版本。 + + Failed to connect to datacollector process. + Failed to connect datacollector. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs index 386d806420..2332edf5cc 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/XML/XmlPersistence.cs @@ -670,7 +670,7 @@ private void SaveSimpleData(object value, XmlNode nodeToSaveAt, object defaultVa } catch (NotSupportedException nosupportEx) { - EqtTrace.Info("TypeConverter not supported for {0} : NotSupportedException Exception Message {1}", value.ToString(), nosupportEx.Message); + EqtTrace.Info("TypeConverter not supported for {0} : NotSupportedException: {1}", value.ToString(), nosupportEx); valueToSave = value.ToString(); } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs index d0b1dd84b4..a07e4d50ee 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs @@ -376,7 +376,7 @@ private static string GetArchitectureForSource(string imagePath) //Ignore all exception if (EqtTrace.IsErrorEnabled) { - EqtTrace.Error("AssemblyLoadWorker:GetArchitectureForSource() Returning default:{0}. Unhandled exception: {1}.", "AnyCPU", ex.Message); + EqtTrace.Error("AssemblyLoadWorker:GetArchitectureForSource() Returning default:{0}. Unhandled exception: {1}.", "AnyCPU", ex.ToString()); } } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/PlatformEqtTrace.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/PlatformEqtTrace.cs index 2036d38065..fd8ade04f0 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/PlatformEqtTrace.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/PlatformEqtTrace.cs @@ -352,7 +352,7 @@ private static bool EnsureTraceIsInitialized() catch (Exception e) { UnInitializeVerboseTrace(); - ErrorOnInitialization = e.Message; + ErrorOnInitialization = e.ToString(); return false; } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index d758197d69..db0d036239 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -390,7 +390,8 @@ private bool LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToke } catch (OperationCanceledException ex) { - this.messageLogger.SendMessage(TestMessageLevel.Error, ex.Message); + EqtTrace.Error("DefaultTestHostManager.LaunchHost: Failed to launch testhost: {0}", ex); + this.messageLogger.SendMessage(TestMessageLevel.Error, ex.ToString()); return false; } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 77c10fabc6..4b5adb2ed7 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -345,7 +345,8 @@ private bool LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToke } catch (OperationCanceledException ex) { - this.messageLogger.SendMessage(TestMessageLevel.Error, ex.Message); + EqtTrace.Error("DotnetTestHostManager.LaunchHost: Failed to launch testhost: {0}", ex); + this.messageLogger.SendMessage(TestMessageLevel.Error, ex.ToString()); return false; } diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 5721ede87f..d75d81ce88 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -85,7 +85,7 @@ private string MergeCodeCoverageFiles(IList files) { if (EqtTrace.IsErrorEnabled) { - EqtTrace.Error("CodeCoverageDataCollectorAttachmentsHandler: Failed to load datacollector of type : {0} from location : {1}. Error : ", CodeCoverageAnalysisAssemblyName, assemblyPath, ex.Message); + EqtTrace.Error("CodeCoverageDataCollectorAttachmentsHandler: Failed to load datacollector of type : {0} from location : {1}. Error : {2}", CodeCoverageAnalysisAssemblyName, assemblyPath, ex.ToString()); } } diff --git a/src/datacollector/Program.cs b/src/datacollector/Program.cs index dd281f8376..c05a0b43ec 100644 --- a/src/datacollector/Program.cs +++ b/src/datacollector/Program.cs @@ -55,20 +55,23 @@ public static void Main(string[] args) WaitForDebuggerIfEnabled(); Run(args); } - catch (SocketException ex) - { - EqtTrace.Error("DataCollector: Socket exception is thrown : {0}", ex); - } catch (Exception ex) { EqtTrace.Error("DataCollector: Error occured during initialization of Datacollector : {0}", ex); + throw; } } private static void Run(string[] args) { var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); - var requestHandler = DataCollectionRequestHandler.Create(new SocketCommunicationManager(), new MessageSink()); + + // Setup logging if enabled + string logFile; + if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) + { + EqtTrace.InitializeVerboseTrace(logFile); + } // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessArgument); @@ -83,13 +86,6 @@ private static void Run(string[] args) Environment.Exit(1); }); - // Setup logging if enabled - string logFile; - if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) - { - EqtTrace.InitializeVerboseTrace(logFile); - } - // Get server port and initialize communication. string portValue; int port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0; @@ -99,6 +95,7 @@ private static void Run(string[] args) throw new ArgumentException("Incorrect/No Port number"); } + var requestHandler = DataCollectionRequestHandler.Create(new SocketCommunicationManager(), new MessageSink()); requestHandler.InitializeCommunication(port); // Can only do this after InitializeCommunication because datacollector cannot "Send Log" unless communications are initialized diff --git a/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs b/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs index 10a5f145cc..ee4e0b570e 100644 --- a/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs +++ b/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs @@ -243,7 +243,7 @@ public Architecture GetArchitectureForSource(string imagePath) //Ignore all exception EqtTrace.Info( "GetArchitectureForSource: Returning default:{0}. Unhandled exception: {1}.", - archType, ex.Message); + archType, ex); } return archType; diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs index 5d645754a9..7b2630b412 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs @@ -100,6 +100,7 @@ public void InitializeShouldSaveExceptionMessagesIfThrownByDataCollectionProcess { var mockRequestSender = new Mock(); mockRequestSender.Setup(x => x.SendBeforeTestRunStartAndGetResult(It.IsAny(), It.IsAny())).Throws(new Exception("MyException")); + mockRequestSender.Setup(x => x.WaitForRequestHandlerConnection(ProxyDataCollectionManager.DataCollectorConnectionTimeout)).Returns(true); var mockDataCollectionLauncher = new Mock(); var proxyDataCollectonManager = new ProxyDataCollectionManager(this.mockRequestData.Object, string.Empty, mockRequestSender.Object, this.mockProcessHelper.Object, mockDataCollectionLauncher.Object); @@ -108,7 +109,7 @@ public void InitializeShouldSaveExceptionMessagesIfThrownByDataCollectionProcess proxyExecutionManager.Initialize(); Assert.IsNotNull(proxyExecutionManager.DataCollectionRunEventsHandler.Messages); Assert.AreEqual(TestMessageLevel.Error, proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item1); - Assert.AreEqual("MyException", proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item2); + StringAssert.Contains(proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item2, "MyException"); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs index ba778d8021..89b08ebbbd 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs @@ -48,10 +48,45 @@ public void Initialize() [TestMethod] public void InitializeShouldInitializeCommunication() { + this.mockDataCollectionRequestSender.Setup(x => x.WaitForRequestHandlerConnection(ProxyDataCollectionManager.DataCollectorConnectionTimeout)).Returns(true); this.proxyDataCollectionManager.Initialize(); this.mockDataCollectionLauncher.Verify(x => x.LaunchDataCollector(It.IsAny>(), It.IsAny>()), Times.Once); - this.mockDataCollectionRequestSender.Verify(x => x.WaitForRequestHandlerConnection(5000), Times.Once); + this.mockDataCollectionRequestSender.Verify(x => x.WaitForRequestHandlerConnection(ProxyDataCollectionManager.DataCollectorConnectionTimeout), Times.Once); + } + + [TestMethod] + public void InitializeShouldThrowExceptionIfConnectionTimeouts() + { + this.mockDataCollectionRequestSender.Setup( x => x.WaitForRequestHandlerConnection(ProxyDataCollectionManager.DataCollectorConnectionTimeout)).Returns(false); + + Assert.ThrowsException(() => this.proxyDataCollectionManager.Initialize()); + } + + [TestMethod] + public void InitializeShouldSetTimeoutBasedOnTimeoutEnvironmentVarible() + { + + var timeout = 10; + Environment.SetEnvironmentVariable(ProxyDataCollectionManager.TimeoutEnvironmentVaribleName, timeout.ToString()); + this.mockDataCollectionRequestSender.Setup(x => x.WaitForRequestHandlerConnection(timeout * 1000)).Returns(true); + + this.proxyDataCollectionManager.Initialize(); + Environment.SetEnvironmentVariable(ProxyDataCollectionManager.TimeoutEnvironmentVaribleName, string.Empty); + + this.mockDataCollectionRequestSender.Verify(x => x.WaitForRequestHandlerConnection(timeout * 1000), Times.Once); + } + + [TestMethod] + public void InitializeShouldSetTimeoutBasedOnDebugEnvironmentVaribleName() + { + Environment.SetEnvironmentVariable(ProxyDataCollectionManager.DebugEnvironmentVaribleName, "1"); + this.mockDataCollectionRequestSender.Setup(x => x.WaitForRequestHandlerConnection(ProxyDataCollectionManager.DataCollectorConnectionTimeout * 5)).Returns(true); + + this.proxyDataCollectionManager.Initialize(); + Environment.SetEnvironmentVariable(ProxyDataCollectionManager.DebugEnvironmentVaribleName, string.Empty); + + this.mockDataCollectionRequestSender.Verify(x => x.WaitForRequestHandlerConnection(ProxyDataCollectionManager.DataCollectorConnectionTimeout * 5), Times.Once); } [TestMethod] @@ -70,6 +105,7 @@ public void InitializeShouldPassDiagArgumentsIfDiagIsEnabled() try { EqtTrace.InitializeVerboseTrace("mylog.txt"); + this.mockDataCollectionRequestSender.Setup(x => x.WaitForRequestHandlerConnection(ProxyDataCollectionManager.DataCollectorConnectionTimeout)).Returns(true); this.proxyDataCollectionManager.Initialize(); @@ -79,7 +115,7 @@ public void InitializeShouldPassDiagArgumentsIfDiagIsEnabled() It.IsAny>(), It.Is>(list => list.Contains("--diag"))), Times.Once); - this.mockDataCollectionRequestSender.Verify(x => x.WaitForRequestHandlerConnection(5000), Times.Once); + this.mockDataCollectionRequestSender.Verify(x => x.WaitForRequestHandlerConnection(ProxyDataCollectionManager.DataCollectorConnectionTimeout), Times.Once); } finally { @@ -135,7 +171,7 @@ public void BeforeTestRunStartsShouldInvokeRunEventsHandlerIfExceptionIsThrown() var result = this.proxyDataCollectionManager.BeforeTestRunStart(true, true, mockRunEventsHandler.Object); - mockRunEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, "Exception of type 'System.Exception' was thrown."), Times.Once); + mockRunEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.IsRegex("Exception of type 'System.Exception' was thrown..*")), Times.Once); Assert.AreEqual(0, result.EnvironmentVariables.Count); Assert.AreEqual(false, result.AreTestCaseLevelEventsRequired); Assert.AreEqual(0, result.DataCollectionEventsPort); @@ -171,7 +207,7 @@ public void AfterTestRunEndShouldInvokeRunEventsHandlerIfExceptionIsThrown() var result = this.proxyDataCollectionManager.AfterTestRunEnd(false, mockRunEventsHandler.Object); - mockRunEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, "Exception of type 'System.Exception' was thrown."), Times.Once); + mockRunEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.IsRegex("Exception of type 'System.Exception' was thrown..*")), Times.Once); }