Exemplo n.º 1
0
        string ProgressFeedback(StreamReader reader)
        {
            var    result    = "";
            string writePath = Environment.ExpandEnvironmentVariables(ProgressFeedbackFilePath);

            TestCleanupUtils.WaitForFileUnlock(writePath);
            TestCleanupUtils.CopyOnWrite(writePath);
            string startMessageText = $"Starting pull at {DateTime.Now.ToLongTimeString()} on {DateTime.Now.ToLongDateString()}:";
            var    startMessage     = Encoding.UTF8.GetBytes(startMessageText);

            File.WriteAllText(writePath, startMessageText);
            using (var fileWriteStream = new FileStream(writePath, FileMode.Open, FileAccess.Write, FileShare.Read))
            {
                fileWriteStream.Position = startMessage.Length;
                while (!reader.EndOfStream)
                {
                    var readChar = (char)reader.Read();
                    result += readChar;
                    fileWriteStream.WriteByte((byte)readChar);
                }
                byte[] finishedMessage = Encoding.UTF8.GetBytes($"Finished pull at {DateTime.Now.ToLongTimeString()} on {DateTime.Now.ToLongDateString()}.");
                fileWriteStream.Write(finishedMessage, 0, finishedMessage.Length);
            }
            return(result);
        }
Exemplo n.º 2
0
        public void RetryTestFailures(string jobName, string testAssembliesList, List <string> TestAssembliesDirectories, string testSettingsFile, string FullTRXFilePath, int currentRetryCount)
        {
            TestRunner.TestsResultsPath = Path.Combine(TestRunner.TestsResultsPath, "..", NumberToWords(currentRetryCount) + "RetryTestResults");
            TestRunner.TestsResultsPath = Path.GetFullPath((new Uri(TestRunner.TestsResultsPath)).LocalPath);
            if (ciRemoteContainerLauncher != null)
            {
                ciRemoteContainerLauncher.LogOutputDirectory = TestRunner.TestsResultsPath;
            }

            TestCleanupUtils.WaitForFileUnlock(FullTRXFilePath);
            TestRunner.TestList = "";
            var         TestFailures = new List <string>();
            XmlDocument trxContent   = new XmlDocument();

            trxContent.Load(FullTRXFilePath);
            var namespaceManager = new XmlNamespaceManager(trxContent.NameTable);

            namespaceManager.AddNamespace("a", "http://microsoft.com/schemas/VisualStudio/TeamTest/2010");
            if (trxContent.DocumentElement.SelectNodes("/a:TestRun/a:TestDefinitions/a:UnitTest/a:TestMethod", namespaceManager).Count > 0)
            {
                foreach (XmlNode TestResult in trxContent.DocumentElement.SelectNodes("/a:TestRun/a:Results/a:UnitTestResult", namespaceManager))
                {
                    if (TestResult.Attributes["outcome"] == null || TestResult.Attributes["outcome"].InnerText == "Failed")
                    {
                        TestFailures.Add(TestResult.Attributes["testName"].InnerXml);
                    }
                }
            }
            else
            {
                Console.WriteLine($"Error parsing /TestRun/Results/UnitTestResult from trx file at {FullTRXFilePath}");
            }
            string TestRunnerPath;

            if (TestFailures.Count > 0)
            {
                TestRunner.TestList = string.Join(",", TestFailures);
                TestRunnerPath      = TestRunner.WriteTestRunner(jobName, "", "", testAssembliesList, testSettingsFile, Path.Combine(TestRunner.TestsResultsPath, "RetryResults"), RecordScreen != null, JobSpecs);
            }
            else
            {
                Console.WriteLine($"No failing tests found to retry in trx file at {FullTRXFilePath}");
                return;
            }
            Console.WriteLine($"Re-running all test failures in \"{FullTRXFilePath}\".");
            var retryResults = RunTests(jobName, testAssembliesList, TestAssembliesDirectories, testSettingsFile, TestRunnerPath);

            if (!string.IsNullOrEmpty(retryResults) && retryResults != FullTRXFilePath)
            {
                TestResultsMerger.MergeRetryResults(FullTRXFilePath, retryResults);
            }
            else
            {
                Console.WriteLine($"{TestRunnerPath} did not produce a test result trx file in {TestRunner.TestsResultsPath}");
            }
        }