Ejemplo n.º 1
0
        private bool CheckCompetitionLimitsCore(
            Benchmark benchmark,
            Summary summary,
            CompetitionLimit competitionLimit,
            CompetitionState competitionState,
            List <IWarning> warnings)
        {
            var actualValues = CompetitionLimitProvider.TryGetActualValues(benchmark, summary);

            if (actualValues == null)
            {
                competitionState.AddAnalyserWarning(
                    warnings, MessageSeverity.ExecutionError,
                    $"Could not obtain competition limits for {benchmark.ShortInfo}.",
                    summary.TryGetBenchmarkReport(benchmark));

                return(true);
            }

            if (competitionLimit.CheckLimitsFor(actualValues))
            {
                return(true);
            }

            var targetMethodTitle = benchmark.Target.MethodTitle;
            var message           = competitionLimit.IsEmpty
                                ? $"Method {targetMethodTitle} {actualValues} has empty limit. Please fill it."
                                : $"Method {targetMethodTitle} {actualValues} does not fit into limits {competitionLimit}.";

            competitionState.AddAnalyserWarning(
                warnings, MessageSeverity.TestError, message, summary.TryGetBenchmarkReport(benchmark));

            return(false);
        }
Ejemplo n.º 2
0
        private void CheckPostconditions(Summary summary, CompetitionState competitionState, List <IWarning> warnings)
        {
            var culture = EnvironmentInfo.MainCultureInfo;

            if (TooFastBenchmarkLimit > TimeSpan.Zero)
            {
                var tooFastReports = GetReportNames(
                    summary,
                    r => r.GetAverageNanoseconds() < TooFastBenchmarkLimit.TotalNanoseconds());

                if (tooFastReports.Any())
                {
                    competitionState.AddAnalyserWarning(
                        warnings, MessageSeverity.Warning,
                        "The benchmark(s) " + string.Join(", ", tooFastReports) +
                        $" run faster than {TooFastBenchmarkLimit.TotalMilliseconds.ToString(culture)}ms. Results cannot be trusted.");
                }
            }

            if (LongRunningBenchmarkLimit > TimeSpan.Zero)
            {
                var tooSlowReports = GetReportNames(
                    summary,
                    r => r.GetAverageNanoseconds() > LongRunningBenchmarkLimit.TotalNanoseconds());

                if (tooSlowReports.Any())
                {
                    competitionState.AddAnalyserWarning(
                        warnings, MessageSeverity.Warning,
                        "The benchmark(s) " + string.Join(", ", tooSlowReports) +
                        $" run longer than {LongRunningBenchmarkLimit.TotalSeconds.ToString(culture)}s." +
                        " Consider to rewrite the test as the peek timings will be hidden by averages" +
                        " or enable long running benchmarks support in the config.");
                }
            }
        }