public void InitializeShouldPassDiagArgumentsIfDiagIsEnabled() { // Saving the EqtTrace state #if NET451 var traceLevel = EqtTrace.TraceLevel; EqtTrace.TraceLevel = TraceLevel.Off; #else var traceLevel = (TraceLevel)EqtTrace.TraceLevel; EqtTrace.TraceLevel = (PlatformTraceLevel)TraceLevel.Off; #endif var traceFileName = EqtTrace.LogFile; try { EqtTrace.InitializeVerboseTrace("mylog.txt"); this.proxyDataCollectionManager.Initialize(); this.mockDataCollectionLauncher.Verify( x => x.LaunchDataCollector( It.IsAny <IDictionary <string, string> >(), It.Is <IList <string> >(list => list.Contains("--diag"))), Times.Once); this.mockDataCollectionRequestSender.Verify(x => x.WaitForRequestHandlerConnection(5000), Times.Once); } finally { // Restoring to initial state for EqtTrace EqtTrace.InitializeVerboseTrace(traceFileName); #if NET451 EqtTrace.TraceLevel = traceLevel; #else EqtTrace.TraceLevel = (PlatformTraceLevel)traceLevel; #endif } }
public void Invoke(IDictionary <string, string> argsDictionary) { // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { EqtTrace.InitializeVerboseTrace(logFile); } #if NET46 if (EqtTrace.IsInfoEnabled) { var appConfigText = System.IO.File.ReadAllText(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); EqtTrace.Info("DefaultEngineInvoker: Using Application Configuration: '{0}'", appConfigText); } #endif // Get port number and initialize communication var portNumber = GetIntArgFromDict(argsDictionary, PortArgument); // Start Processing of requests using (var requestHandler = new TestRequestHandler()) { // Attach to exit of parent process var parentProcessId = GetIntArgFromDict(argsDictionary, ParentProcessIdArgument); EqtTrace.Info("DefaultEngineInvoker: Monitoring parent process with id: '{0}'", parentProcessId); var parentProcessMonitoringTask = WaitForParentProcessExitAsync(parentProcessId); // Initialize Communication EqtTrace.Info("DefaultEngineInvoker: Initialize communication on port number: '{0}'", portNumber); requestHandler.InitializeCommunication(portNumber); // Can only do this after InitializeCommunication because TestHost cannot "Send Log" unless communications are initialized if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { requestHandler.SendLog(TestMessageLevel.Informational, string.Format("Logging TestHost Diagnostics in file: {0}", EqtTrace.LogFile)); } // Initialize DataCollection Communication if data collection port is provided. var dcPort = GetIntArgFromDict(argsDictionary, DataCollectionPortArgument); if (dcPort > 0) { var dataCollectionTestCaseEventSender = DataCollectionTestCaseEventSender.Create(); dataCollectionTestCaseEventSender.InitializeCommunication(dcPort); dataCollectionTestCaseEventSender.WaitForRequestSenderConnection(ClientListenTimeOut); } // Start processing async in a different task EqtTrace.Info("DefaultEngineInvoker: Start Request Processing."); var processingTask = this.StartProcessingAsync(requestHandler, new TestHostManagerFactory()); // Wait for either processing to complete or parent process exit Task.WaitAny(processingTask, parentProcessMonitoringTask); if (dcPort > 0) { // Close socket communication connection. DataCollectionTestCaseEventSender.Instance.Close(); } } }
public void Invoke(IDictionary <string, string> argsDictionary) { // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { EqtTrace.InitializeVerboseTrace(logFile); } #if NET451 if (EqtTrace.IsInfoEnabled) { var appConfigText = System.IO.File.ReadAllText(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); EqtTrace.Info("DefaultEngineInvoker: Using Application Configuration: '{0}'", appConfigText); } #endif // vstest.console < 15.5 won't send endpoint and role arguments. // So derive endpoint from port argument and Make connectionRole as Client. string endpoint = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, EndpointArgument); if (string.IsNullOrWhiteSpace(endpoint)) { var port = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, "--port"); endpoint = IPAddress.Loopback + ":" + port; } var connectionRole = ConnectionRole.Client; string role = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, RoleArgument); if (!string.IsNullOrWhiteSpace(role) && string.Equals(role, "host", StringComparison.OrdinalIgnoreCase)) { connectionRole = ConnectionRole.Host; } // Start Processing of requests using (var requestHandler = new TestRequestHandler(new TestHostConnectionInfo { Endpoint = endpoint, Role = connectionRole, Transport = Transport.Sockets })) { // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessIdArgument); EqtTrace.Info("DefaultEngineInvoker: Monitoring parent process with id: '{0}'", parentProcessId); // In remote scenario we cannot monitor parent process, so we expect user to pass parentProcessId as -1 if (parentProcessId != -1) { var processHelper = new ProcessHelper(); processHelper.SetExitCallback( parentProcessId, () => { EqtTrace.Info("DefaultEngineInvoker: ParentProcess '{0}' Exited.", parentProcessId); new PlatformEnvironment().Exit(1); }); } // Initialize Communication EqtTrace.Info("DefaultEngineInvoker: Initialize communication on endpoint address: '{0}'", endpoint); requestHandler.InitializeCommunication(); // Initialize DataCollection Communication if data collection port is provided. var dcPort = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, DataCollectionPortArgument); if (dcPort > 0) { var dataCollectionTestCaseEventSender = DataCollectionTestCaseEventSender.Create(); dataCollectionTestCaseEventSender.InitializeCommunication(dcPort); dataCollectionTestCaseEventSender.WaitForRequestSenderConnection(ClientListenTimeOut); } // Checks for Telemetry Opted in or not from Command line Arguments. // By Default opting out in Test Host to handle scenario when user running old version of vstest.console var telemetryStatus = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, TelemetryOptedIn); var telemetryOptedIn = false; if (!string.IsNullOrWhiteSpace(telemetryStatus)) { if (telemetryStatus.Equals("true", StringComparison.Ordinal)) { telemetryOptedIn = true; } } var requestData = new RequestData { MetricsCollection = telemetryOptedIn ? (IMetricsCollection) new MetricsCollection() : new NoOpMetricsCollection(), IsTelemetryOptedIn = telemetryOptedIn }; // Start processing async in a different task EqtTrace.Info("DefaultEngineInvoker: Start Request Processing."); var processingTask = this.StartProcessingAsync(requestHandler, new TestHostManagerFactory(requestData)); // Wait for processing to complete. Task.WaitAny(processingTask); if (dcPort > 0) { // Close socket communication connection. DataCollectionTestCaseEventSender.Instance.Close(); } } }
public void Invoke(IDictionary <string, string> argsDictionary) { // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { EqtTrace.InitializeVerboseTrace(logFile); } #if NET46 if (EqtTrace.IsInfoEnabled) { var appConfigText = System.IO.File.ReadAllText(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); EqtTrace.Info("DefaultEngineInvoker: Using Application Configuration: '{0}'", appConfigText); } #endif // Get port number and initialize communication var portNumber = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, PortArgument); // Start Processing of requests using (var requestHandler = new TestRequestHandler()) { // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessIdArgument); EqtTrace.Info("DefaultEngineInvoker: Monitoring parent process with id: '{0}'", parentProcessId); var processHelper = new ProcessHelper(); processHelper.SetExitCallback( parentProcessId, () => { EqtTrace.Info("DefaultEngineInvoker: ParentProcess '{0}' Exited.", parentProcessId); Environment.Exit(1); }); // Initialize Communication EqtTrace.Info("DefaultEngineInvoker: Initialize communication on port number: '{0}'", portNumber); requestHandler.InitializeCommunication(portNumber); // Initialize DataCollection Communication if data collection port is provided. var dcPort = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, DataCollectionPortArgument); if (dcPort > 0) { var dataCollectionTestCaseEventSender = DataCollectionTestCaseEventSender.Create(); dataCollectionTestCaseEventSender.InitializeCommunication(dcPort); dataCollectionTestCaseEventSender.WaitForRequestSenderConnection(ClientListenTimeOut); } // Start processing async in a different task EqtTrace.Info("DefaultEngineInvoker: Start Request Processing."); var processingTask = this.StartProcessingAsync(requestHandler, new TestHostManagerFactory()); // Wait for processing to complete. Task.WaitAny(processingTask); if (dcPort > 0) { // Close socket communication connection. DataCollectionTestCaseEventSender.Instance.Close(); } } }