示例#1
0
        // This method must be called with the desktop resource acquired
        // (which is why it takes an IAcquiredResources as a parameter without using it in the function itself).
        public async Task <TestExecutingResult> RestoreNugetsAsync(ILog log, IAcquiredResource resource)
        {
            if (!RestoreNugets)
            {
                return(TestExecutingResult.Ignored);
            }

            if (!File.Exists(SolutionPath ?? TestProject.Path))
            {
                throw new FileNotFoundException("Could not find the solution whose nugets to restore.", SolutionPath ?? TestProject.Path);
            }

            // might happen that the project does contain reference projects with nugets, grab the reference projects and ensure
            // thast they have the nugets restored (usually, watch os test projects
            if (SolutionPath == null)
            {
                var references = GetNestedReferenceProjects(TestProject.Path);
                foreach (var referenceProject in references)
                {
                    var execResult = await RestoreNugetsAsync(referenceProject, log);                      // do the replace in case we use win paths

                    if (execResult == TestExecutingResult.TimedOut)
                    {
                        return(execResult);
                    }
                }
            }

            // restore for the main project/solution]
            return(await RestoreNugetsAsync(SolutionPath ?? TestProject.Path, log));
        }
示例#2
0
        public async Task <(TestExecutingResult ExecutionResult, (string HumanMessage, string IssueLink)? KnownFailure)> ExecuteAsync(
            string projectPlatform,
            string projectConfiguration,
            string projectFile,
            IAcquiredResource resource,
            bool dryRun,
            IFileBackedLog buildLog,
            ILog mainLog)
        {
            BuildLog = buildLog;
            (TestExecutingResult ExecutionResult, (string HumanMessage, string IssueLink)? KnownFailure)result = (TestExecutingResult.NotStarted, ((string HumanMessage, string IssueLink)?)null);
            var restoreResult = await RestoreNugetsAsync(buildLog, resource);

            if ((restoreResult & TestExecutingResult.Failed) == TestExecutingResult.Failed)
            {
                BuildLog.WriteLine($"Failed to restore nugets: {restoreResult}");
                result.ExecutionResult = restoreResult;
                return(result);
            }

            using (var xbuild = new Process()) {
                xbuild.StartInfo.FileName         = msbuildPath();
                xbuild.StartInfo.Arguments        = StringUtils.FormatArguments(GetToolArguments(projectPlatform, projectConfiguration, projectFile, buildLog));
                xbuild.StartInfo.WorkingDirectory = Path.GetDirectoryName(projectFile);
                EnvironmentManager.SetEnvironmentVariables(xbuild);
                xbuild.StartInfo.EnvironmentVariables ["MSBuildExtensionsPath"] = null;
                EventLogger.LogEvent(buildLog, "Building {0} ({1})", TestName, Mode);
                if (!dryRun)
                {
                    var timeout       = TimeSpan.FromMinutes(60);
                    var processResult = await ProcessManager.RunAsync(xbuild, buildLog, timeout);

                    if (processResult.TimedOut)
                    {
                        result.ExecutionResult = TestExecutingResult.TimedOut;
                        buildLog.WriteLine("Build timed out after {0} seconds.", timeout.TotalSeconds);
                    }
                    else if (processResult.Succeeded)
                    {
                        result.ExecutionResult = TestExecutingResult.Succeeded;
                    }
                    else
                    {
                        result.ExecutionResult = TestExecutingResult.Failed;
                        if (errorKnowledgeBase.IsKnownBuildIssue(buildLog, out result.KnownFailure))
                        {
                            buildLog.WriteLine($"Build has a known failure: '{result.KnownFailure}'");
                        }
                    }
                }
                mainLog.WriteLine("Built {0} ({1})", TestName, Mode);
            }
            return(result);
        }