Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private static RequestData GetRequestData(IDictionary <string, string> argsDictionary)
        {
            // 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
            };

            return(requestData);
        }
        public void GetStringArgFromDictShouldReturnStringValueOrEmpty()
        {
            var args = new List <string>()
            {
                "--port", "12312", "--parentprocessid", "2312", "--testsourcepath", @"C:\temp\1.dll"
            };
            var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray());

            string data = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, "--port");

            Assert.AreEqual("12312", data);
        }
        public void GetStringArgFromDictShouldReturnEmptyStringIfKeyIsNotPresent()
        {
            var args = new List <string>()
            {
                "--hello", "--world"
            };
            var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray());

            string data = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, "--port");

            Assert.IsTrue(argsDictionary.Count == 2);
            Assert.AreEqual(string.Empty, data);
        }
Ejemplo n.º 5
0
        public void GetStringArgFromDictShouldReturnNullIfValueIsNotPresent()
        {
            var args = new List <string>()
            {
                "--hello", "--world"
            };
            var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray());

            string data = CommandLineArgumentsHelper.GetStringArgFromDict(argsDictionary, "--hello");

            Assert.IsTrue(argsDictionary.Count == 2);
            Assert.IsNull(data);
        }
Ejemplo n.º 6
0
        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();
                }
            }
        }