Esempio n. 1
0
        void LogTestResultsToTTS(
            TestSuiteLogger testSuiteLogger,
            TestResult[] runnerResults,
            string testName,
            bool isRepeated)
        {
            if (testSuiteLogger == null)
            {
                return;
            }

            int ini = Environment.TickCount;

            testSuiteLogger.LogTestRunResults(
                runnerResults,
                testSuiteLogger.SuiteParams.SuiteType,
                testName,
                isRepeated);

            mLog.DebugFormat("Time logging to TTS {0} ms", Environment.TickCount - ini);
        }
Esempio n. 2
0
        static void RunLauncher(string customLogFolder, string[] args)
        {
            TestGroup group = TestConfLoader.LoadFromFile(args[0], args);

            LauncherArgs launcherArgs = CliArgsReader.ProcessArgs(args, group);

            if ((group == null) || (group.ParallelTests.Count == 0))
            {
                Console.WriteLine("No tests to run");
                return;
            }

            TestSuiteLoggerParams loggerParams = CliArgsReader.ProcessTestSuiteLoggerArgs(args);

            NUnitResultCollector nunitReport = new NUnitResultCollector();
            LogWriter            logWriter   = new LogWriter(launcherArgs.ResultLogFile, launcherArgs.ErrorLogFile);

            try
            {
                string portValue = CliArgsReader.GetArgumentValue("--port=", args);
                int    port      = portValue == null ? DEFAULT_LAUNCHER_PORT : int.Parse(portValue);

                string ipToBind = CliArgsReader.GetArgumentValue("--iptobind=", args);

                Configurator.ConfigureRemoting(port, ipToBind ?? string.Empty);

                DateTime beginTimeStamp = DateTime.Now;

                TestSuiteLogger testSuiteLogger = null;

                if (loggerParams.IsInitialized())
                {
                    testSuiteLogger = new TestSuiteLogger(loggerParams);
                    testSuiteLogger.SaveBuild();
                    testSuiteLogger.CreateSuite();
                }

                Hashtable userValues = CliArgsReader.GetUserValues(args);

                Launcher launcher = new Launcher();

                string listenAddress = string.Format("{0}:{1}",
                                                     ipToBind ?? Environment.MachineName, port);

                List <string> testList = string.IsNullOrEmpty(launcherArgs.ListTestsFile) ?
                                         null :
                                         LoadTestsToRunFromFile(launcherArgs.ListTestsFile);

                Runner[] runners = launcher.RunTests(
                    group,
                    testList,
                    launcherArgs.MaxRetry,
                    launcherArgs.ShellMode,
                    launcherArgs.RetryOnFailure,
                    launcherArgs.FailedConfigFile,
                    testSuiteLogger,
                    launcherArgs.TestsTimeout,
                    launcherArgs.TestRange,
                    userValues,
                    logWriter,
                    listenAddress,
                    launcherArgs.UseFileReport);

                DateTime endTimeStamp = DateTime.Now;

                FillNunitReport(nunitReport, runners);

                if (CliArgsReader.GetArgumentValue("--skipsummarylog", args) != null)
                {
                    return;
                }

                LogWriter.PrintResults(
                    runners,
                    beginTimeStamp, endTimeStamp, logWriter);
            }
            finally
            {
                logWriter.WriteFullLog(launcherArgs.ResultFile);
                nunitReport.SaveResults(Path.Combine(customLogFolder, "pnunit-results.xml"));
            }
        }
Esempio n. 3
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);
        }