Пример #1
0
 void LogTestProgress(
     TestGroup group,
     TestRange testRange,
     int testCount,
     int i)
 {
     if (testCount != group.ParallelTests.Count)
     {
         mLog.InfoFormat("Test {0} of {1}. {2}/{3}",
                         i, group.ParallelTests.Count, i - testRange.StartTest + 1,
                         testCount);
     }
     else
     {
         mLog.InfoFormat("Test {0} of {1}", i + 1,
                         group.ParallelTests.Count);
     }
 }
Пример #2
0
        static bool CheckValidInterval(TestRange testRange, TestGroup group)
        {
            if ((testRange.StartTest > testRange.EndTest) ||
                (testRange.StartTest < 0) ||
                (testRange.StartTest > group.ParallelTests.Count - 1))
            {
                Console.WriteLine("Start test must be in a correct test range");
                return(false);
            }

            if ((testRange.EndTest < testRange.StartTest) ||
                (testRange.EndTest < 0) ||
                (testRange.EndTest > group.ParallelTests.Count - 1))
            {
                Console.WriteLine("End test must be in a correct test range");
                return(false);
            }
            return(true);
        }
Пример #3
0
        static TestRange LaunchARange(string arg, TestGroup group)
        {
            string rangeText = arg.Substring("--range=".Length);

            string[] limits = rangeText.Split('-');

            if (!CheckValidRangeValues(rangeText, limits))
            {
                return(null);
            }

            TestRange result = CalculateRange(limits, group);

            if (!CheckValidInterval(result, group))
            {
                return(null);
            }

            mLog.InfoFormat("Starting test range [{0}-{1}]",
                            result.StartTest, result.EndTest);

            return(result);
        }
Пример #4
0
        internal Runner[] RunTests(
            TestGroup group,
            List <string> testsList,
            int maxRetry,
            bool bShellMode,
            int retryOnFailure,
            string failedfile,
            TestSuiteLogger testSuiteLogger,
            int testsTimeout,
            TestRange testRange,
            Hashtable userValues,
            LogWriter logWriter,
            string listenAddress,
            string reportFile)
        {
            if (testRange == null)
            {
                mLog.Warn("No tests are selected to run. Exiting.");
                return(new Runner[0]);
            }

            int testCount          = testRange.EndTest - testRange.StartTest + 1;
            int testToExecuteCount = (testsList != null) ? testsList.Count : testCount;

            mStatus = new LauncherStatus(testCount, testToExecuteCount);

            Runner[]            runners      = new Runner[testCount];
            List <ParallelTest> failedGroups = new List <ParallelTest>();

            for (int currentTest = testRange.StartTest; currentTest <= testRange.EndTest;)
            {
                int ini = Environment.TickCount;

                ParallelTest test = group.ParallelTests[currentTest] as ParallelTest;

                if (!IsSelectedTest(test, testsList))
                {
                    mLog.ErrorFormat(
                        "Test with name [{0}] is not invited to this party.",
                        test.Name);

                    ++currentTest;
                    mStatus.Increment();
                    continue;
                }

                mStatus.SetCurrentTestName(test.Name);

                int retryCount = 0;

                bool bRetry = true;

                while (bRetry && retryCount < maxRetry)
                {
                    bRetry = false;

                    LogTestProgress(group, testRange, testCount, currentTest);

                    Runner runner = new Runner(
                        test, userValues, testsTimeout, logWriter, mStatus, listenAddress);

                    if (bShellMode)
                    {
                        runner.ShellMode = bShellMode;
                    }

                    runners[currentTest - testRange.StartTest] = runner;

                    if (reportFile != null)
                    {
                        StatusReport.Write(reportFile, mStatus, false);
                    }

                    runner.Run();

                    TestResult[] runnerResults = runner.GetTestResults();

                    if (runnerResults == null)
                    {
                        mLog.InfoFormat("Error. Results for test [{0}] are NULL",
                                        test.Name);

                        ++currentTest;
                        mStatus.Increment();
                        mStatus.IncrementExecuted();
                        continue;
                    }

                    bool isRepeated = retryCount > 0;

                    if (reportFile == null)
                    {
                        LogTestResultsToTTS(
                            testSuiteLogger, runnerResults, test.Name, isRepeated);
                    }
                    else
                    {
                        LogTestResultsToFile(
                            reportFile, runnerResults, test.Name, isRepeated, true);
                    }

                    bRetry = RetryTest(runnerResults);
                    bool bFailed = FailedTest(runnerResults);

                    if (bRetry ||
                        ((bFailed && (retryOnFailure > 0) &&
                          ((retryCount + 1) < maxRetry)) /* so that list time is printed*/))
                    {
                        bRetry = true;
                        ++retryCount;
                        mLog.Info("Test failed with retry option, trying again");

                        mStatus.AddRepeated(test.Name);

                        continue;
                    }

                    if (bFailed)
                    {
                        failedGroups.Add(test);
                        WriteGroup(failedGroups, failedfile);
                        mStatus.AddFailed(test.Name);
                    }

                    if (IgnoredTest(runnerResults))
                    {
                        mStatus.AddIgnored(test.Name);
                    }
                }

                // updated at the bottom so it's not affected by retries
                mStatus.Increment();
                mStatus.IncrementExecuted();
                ++currentTest;

                mLog.DebugFormat("Test {0} time {1} ms",
                                 test.Name, Environment.TickCount - ini);
            }

            if (reportFile != null)
            {
                StatusReport.Write(reportFile, mStatus, true);
            }

            return(runners);
        }