private static TestHostConnectionInfo GetConnectionInfo(IDictionary <string, string> argsDictionary) { // vstest.console < 15.5 won't send endpoint and role arguments. // So derive endpoint from port argument and Make connectionRole as Client. var endpoint = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, EndpointArgument); if (string.IsNullOrWhiteSpace(endpoint)) { var port = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, "--port"); endpoint = IPAddress.Loopback + ":" + port; } EqtTrace.Info("DefaultEngineInvoker.GetConnectionInfo: Initialize communication on endpoint address: '{0}'", endpoint); 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 var connectionInfo = new TestHostConnectionInfo { Endpoint = endpoint, Role = connectionRole, Transport = Transport.Sockets }; return(connectionInfo); }
public void Invoke(IDictionary <string, string> argsDictionary) { DefaultEngineInvoker.InitializeEqtTrace(argsDictionary); if (EqtTrace.IsInfoEnabled) { EqtTrace.Info("DefaultEngineInvoker.Invoke: Testhost process started with args :{0}", string.Join(",", argsDictionary)); #if NET451 var appConfigText = System.IO.File.ReadAllText(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); EqtTrace.Info("DefaultEngineInvoker: Using Application Configuration: '{0}'", appConfigText); #endif } #if NETCOREAPP TestHostTraceListener.Setup(); #endif this.SetParentProcessExitCallback(argsDictionary); this.requestHandler.ConnectionInfo = DefaultEngineInvoker.GetConnectionInfo(argsDictionary); // Initialize Communication with vstest.console this.requestHandler.InitializeCommunication(); // skipping because 0 is the default value, and also the value the the callers use when they // call with the parameter specified, but without providing an actual port var dcPort = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, DataCollectionPortArgument); if (dcPort > 0) { this.ConnectToDatacollector(dcPort); } var requestData = DefaultEngineInvoker.GetRequestData(argsDictionary); // Start processing async in a different task EqtTrace.Info("DefaultEngineInvoker.Invoke: Start Request Processing."); try { this.StartProcessingAsync(requestHandler, new TestHostManagerFactory(requestData)).Wait(); } finally { if (dcPort > 0) { // Close datacollector communication. this.dataCollectionTestCaseEventSender.Close(); } this.requestHandler.Dispose(); } }
public void Run(string[] args) { WaitForDebuggerIfEnabled(); var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { EqtTrace.InitializeVerboseTrace(logFile); } else { EqtTrace.DoNotInitailize = true; } EqtTrace.Info("DataCollectorMain.Run: Starting data collector run with args: {0}", string.Join(",", args)); // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessArgument); EqtTrace.Info("DataCollector: Monitoring parent process with id: '{0}'", parentProcessId); this.processHelper.SetExitCallback( parentProcessId, (obj) => { EqtTrace.Info("DataCollector: ParentProcess '{0}' Exited.", parentProcessId); this.environment.Exit(1); }); // Get server port and initialize communication. string portValue; int port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0; if (port <= 0) { throw new ArgumentException("Incorrect/No Port number"); } this.requestHandler.InitializeCommunication(port); // Can only do this after InitializeCommunication because datacollector cannot "Send Log" unless communications are initialized if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { ((DataCollectionRequestHandler)this.requestHandler).SendDataCollectionMessage(new DataCollectionMessageEventArgs(TestMessageLevel.Informational, string.Format("Logging DataCollector Diagnostics in file: {0}", EqtTrace.LogFile))); } // Start processing async in a different task EqtTrace.Info("DataCollector: Start Request Processing."); StartProcessing(); }
private static void Run(string[] args) { var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); // 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); EqtTrace.Info("DataCollector: Monitoring parent process with id: '{0}'", parentProcessId); var processHelper = new ProcessHelper(); processHelper.SetExitCallback( parentProcessId, (obj) => { EqtTrace.Info("DataCollector: ParentProcess '{0}' Exited.", parentProcessId); Environment.Exit(1); }); // Get server port and initialize communication. string portValue; int port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0; if (port <= 0) { 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 if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { requestHandler.SendDataCollectionMessage(new DataCollectionMessageEventArgs(TestMessageLevel.Informational, string.Format("Logging DataCollector Diagnostics in file: {0}", EqtTrace.LogFile))); } // Start processing async in a different task EqtTrace.Info("DataCollector: Start Request Processing."); var processingTask = StartProcessingAsync(requestHandler); // Wait for processing to complete. Task.WaitAny(processingTask); }
public void GetIntArgFromDictShouldReturnTheValueIfKeyIsPresent() { var args = new List <string>() { "--port", "1000" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); int data = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, "--port"); Assert.AreEqual(1000, data); }
public void GetIntArgFromDictShouldReturnZeroIfKeyIsNotPresent() { var args = new List <string>() { "--hello", "--world" }; var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray()); int data = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, "--port"); Assert.AreEqual(0, data); }
private static void InitializeEqtTrace(IDictionary <string, string> argsDictionary) { // Setup logging if enabled if (argsDictionary.TryGetValue(LogFileArgument, out var logFile)) { var traceLevelInt = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, TraceLevelArgument); // In case traceLevelInt is not defined in PlatfromTraceLevel, default it to verbose. var traceLevel = Enum.IsDefined(typeof(PlatformTraceLevel), traceLevelInt) ? (PlatformTraceLevel)traceLevelInt : PlatformTraceLevel.Verbose; EqtTrace.InitializeTrace(logFile, traceLevel); } else { EqtTrace.DoNotInitailize = true; } }
private void SetParentProcessExitCallback(IDictionary <string, string> argsDictionary) { // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessIdArgument); EqtTrace.Info("DefaultEngineInvoker.SetParentProcessExitCallback: 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) { this.processHelper.SetExitCallback( parentProcessId, (obj) => { EqtTrace.Info("DefaultEngineInvoker.SetParentProcessExitCallback: ParentProcess '{0}' Exited.", parentProcessId); new PlatformEnvironment().Exit(1); }); } }
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 Run(string[] args) { WaitForDebuggerIfEnabled(); var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { var traceLevelInt = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, TraceLevelArgument); var isTraceLevelArgValid = Enum.IsDefined(typeof(PlatformTraceLevel), traceLevelInt); // In case traceLevelInt is not defined in PlatfromTraceLevel, default it to verbose. var traceLevel = isTraceLevelArgValid ? (PlatformTraceLevel)traceLevelInt : PlatformTraceLevel.Verbose; // Initialize trace. EqtTrace.InitializeTrace(logFile, traceLevel); // Log warning in case tracelevel passed in arg is invalid if (!isTraceLevelArgValid) { EqtTrace.Warning("DataCollectorMain.Run: Invalid trace level: {0}, defaulting to verbose tracelevel.", traceLevelInt); } } else { EqtTrace.DoNotInitailize = true; } if (EqtTrace.IsVerboseEnabled) { var version = typeof(DataCollectorMain) .GetTypeInfo() .Assembly .GetCustomAttribute <AssemblyInformationalVersionAttribute>()?.InformationalVersion; EqtTrace.Verbose($"Version: { version }"); } SetCultureSpecifiedByUser(); EqtTrace.Info("DataCollectorMain.Run: Starting data collector run with args: {0}", string.Join(",", args)); // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessArgument); EqtTrace.Info("DataCollector: Monitoring parent process with id: '{0}'", parentProcessId); this.processHelper.SetExitCallback( parentProcessId, (obj) => { EqtTrace.Info("DataCollector: ParentProcess '{0}' Exited.", parentProcessId); this.environment.Exit(1); }); // Get server port and initialize communication. string portValue; int port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0; if (port <= 0) { throw new ArgumentException("Incorrect/No Port number"); } this.requestHandler.InitializeCommunication(port); // Can only do this after InitializeCommunication because datacollector cannot "Send Log" unless communications are initialized if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { (this.requestHandler as DataCollectionRequestHandler)?.SendDataCollectionMessage(new DataCollectionMessageEventArgs(TestMessageLevel.Informational, string.Format("Logging DataCollector Diagnostics in file: {0}", EqtTrace.LogFile))); } // Start processing async in a different task EqtTrace.Info("DataCollector: Start Request Processing."); StartProcessing(); }
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(); } } }