Example #1
0
        private async Task <RunSummary> Remote_RunTestCasesAsync(string instanceId, IEnumerable <VsTestCaseBase> testCases, IMessageBus messageBus, CancellationTokenSource cancellationTokenSource)
        {
            if (testCases.All(tc => !string.IsNullOrEmpty(tc.SkipReason)))
            {
                return(await Local_RunTestCasesAsync(testCases, messageBus, cancellationTokenSource));
            }

            var instanceTestCase = TestCases.OfType <VsInstanceTestCase>().FirstOrDefault(tc => tc.InstanceId == instanceId);

            return(await ThreadUtil.RunOnStaThreadAsync(async() =>
            {
                var runner = new VsInstanceTestAssemblyRunner(TestAssembly, testCases, instanceTestCase, DiagnosticMessageSink, ExecutionMessageSink, ExecutionOptions, () => CreateMessageBus(), Aggregator);

                try
                {
                    using (var retryFilter = new RetryMessageFilter())
                    {
                        return await runner.RunAsync(cancellationTokenSource);
                    }
                }
                finally
                {
                    await runner.DisposeAsync();
                }
            }));
        }
Example #2
0
 public void EnsureHost()
 {
     if (_visualStudioHost == null || !_visualStudioHost.IsRunning)
     {
         _messageFilterSingleton = new RetryMessageFilter();
         _visualStudioHost       = Operations.CreateAndStartHost <VisualStudioHost>(VisualStudioHostConfiguration);
     }
 }
 public async Task LaunchAndDebug(IMessageBus messageBus, CancellationTokenSource cancellationTokenSource)
 {
     await ThreadUtil.RunOnStaThreadAsync(async() =>
     {
         using (var retryFilter = new RetryMessageFilter())
         {
             var diagnostics         = new VisualDiagnostics(this, DiagnosticMessageSink, messageBus, cancellationTokenSource);
             var extensionsToInstall = VsInstance.GetExtensionsToInstall(ExtensionDirectories);
             var installation        = VisualStudioUtil.FindInstallations().First(i => i.ApplicationPath == ApplicationPath);
             var hive = new VsHive(installation, RootSuffix);
             await VsInstance.Prepare(hive, extensionsToInstall, resetSettings: false, diagnostics, installInvoker: false);
             var process = await diagnostics.RunAsync("Launching Instance", () => Task.FromResult(VisualStudioUtil.StartProcess(hive)));
             if (Debugger.IsAttached)
             {
                 await VsInstance.AttachDebugger(process, DebugMixedMode, diagnostics);
             }
         }
     });
 }
Example #4
0
        /// <summary>
        /// ITestAdapter method: called to initialize run context for this adapter.
        /// </summary>
        /// <param name="runContext">The run context to be used for this run</param>
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            Contract.Assert(runContext != null);

            _runContext = runContext;
            _runConfig  = _runContext.RunConfig.TestRun.RunConfiguration;
            _workingDir = _runContext.RunContextVariables.GetStringValue("TestDeploymentDir");

            Contract.Assert(_runConfig != null);
            Contract.Assert(!string.IsNullOrEmpty(_workingDir));

            SetupChannels();

            // Install COM message filter to retry COM calls when VS IDE is busy, e.g. when getting the addin from VS IDE.
            // This prevents RPC_E_CALL_REJECTED error when VS IDE is busy.
            _comMessageFilter = new RetryMessageFilter();

            InitHostSide();
        }
Example #5
0
        private static int StartProcess(string filename)
        {
            var executablePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename);

            File.Copy(Process.GetCurrentProcess().MainModule.FileName, executablePath, true);
            using (var retryFilter = new RetryMessageFilter())
            {
                var dte     = VisualStudioUtil.GetDteFromDebuggedProcess(Process.GetCurrentProcess());
                var process = Process.Start(new ProcessStartInfo
                {
                    FileName        = executablePath,
                    Arguments       = Environment.CommandLine,
                    UseShellExecute = false,
                });
                if (dte != null)
                {
                    VisualStudioUtil.AttachDebugger(dte, process);
                }
                process.WaitForExit();
                FileUtil.TryDelete(executablePath);
                return(process.ExitCode);
            }
        }
Example #6
0
        private int Run(string applicationPath, string rootSuffix, string[] args)
        {
            try
            {
                if (!ExtensionManagerUtil.IsValidProcessFileName(applicationPath, out var expectedFileName))
                {
                    return(StartProcess(expectedFileName));
                }

                var commands = new Dictionary <string, Func <int> >
                {
                    {
                        "Install", () =>
                        {
                            var extensionPaths = CommandLineParser.Many(args, "Install");
                            return(Installer.Install(applicationPath, rootSuffix, extensionPaths, allUsers: false));
                        }
                    },
                    {
                        "InstallAndStart", () =>
                        {
                            var extensionPaths = CommandLineParser.Many(args, "InstallAndStart");
                            var result         = Installer.Install(applicationPath, rootSuffix, extensionPaths, allUsers: false);
                            using (var retryFilter = new RetryMessageFilter())
                            {
                                var dte     = VisualStudioUtil.GetDteFromDebuggedProcess(Process.GetCurrentProcess());
                                var process = Process.Start(applicationPath, $"/RootSuffix {rootSuffix}");
                                if (dte != null)
                                {
                                    VisualStudioUtil.AttachDebugger(dte, process);
                                }
                                return(result);
                            }
                        }
                    },
                    {
                        "Uninstall", () =>
                        {
                            var extensionIds = CommandLineParser.Many(args, "Uninstall");
                            return(Installer.Uninstall(applicationPath, rootSuffix, extensionIds, skipGlobal: false));
                        }
                    },
                    {
                        "IsProfileInitialized", () =>
                        {
                            using (var externalSettingsManager = ExternalSettingsManager.CreateForApplication(applicationPath, rootSuffix))
                            {
                                var settings             = externalSettingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
                                var isProfileInitialized = settings.CollectionExists("Profile") && settings.GetPropertyNames("Profile").Contains("LastResetSettingsFile");
                                return(Convert.ToInt32(isProfileInitialized));
                            }
                        }
                    },
                };

                foreach (var cmd in commands)
                {
                    if (CommandLineParser.Contains(args, cmd.Key))
                    {
                        return(cmd.Value());
                    }
                }

                throw new Exception($@"Invalid command");
            }
            catch (Exception e)
            {
                Console.Error.Write(e.ToString());
                return(-1);
            }
        }
        /// <summary>
        /// ITestAdapter method: called to initialize run context for this adapter.
        /// </summary>
        /// <param name="runContext">The run context to be used for this run</param>
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            Contract.Assert(runContext != null);

            _runContext = runContext;
            _runConfig = _runContext.RunConfig.TestRun.RunConfiguration;
            _workingDir = _runContext.RunContextVariables.GetStringValue("TestDeploymentDir");

            Contract.Assert(_runConfig != null);
            Contract.Assert(!string.IsNullOrEmpty(_workingDir));

            SetupChannels();

            // Install COM message filter to retry COM calls when VS IDE is busy, e.g. when getting the addin from VS IDE.
            // This prevents RPC_E_CALL_REJECTED error when VS IDE is busy.
            _comMessageFilter = new RetryMessageFilter();

            InitHostSide();
        }