コード例 #1
0
        public void apply_simple_check_no_failures()
        {
            var records = new PerfRecord[]
            {
                new PerfRecord("Grammar", "One", 0, 0),
                new PerfRecord("Grammar", "Two", 0, 0),
                new PerfRecord("Grammar", "Three", 0, 0),
                new PerfRecord("Request", "One", 0, 0),
                new PerfRecord("Request", "Two", 0, 0),
                new PerfRecord("Request", "Three", 0, 0),
                new PerfRecord("Request", "One", 0, 0),
                new PerfRecord("Request", "Two", 0, 0),
            };

            PerformancePolicies.PerfLimit(25, r => r.Subject == "One");

            records[2].MarkEnd(10);
            records[3].MarkEnd(10);

            var context = SpecContext.Basic();

            PerformancePolicies.Apply(context, records);

            records.Any(x => x.PerfViolation).ShouldBeFalse();

            context.Counts.Exceptions.ShouldBe(0);
        }
コード例 #2
0
            public void Close(bool isAggregated)
            {
                PerfRecord shouldBeThis = PerformanceTimer.Cursor.Pop();

                if (this != shouldBeThis)
                {
                    throw new Exception();                       // invalid state
                }
                this.Milliseconds = DateTime.Now.Ticks / 10000.0 - this.startMilliseconds;

                // not interested in sub sections. Just want to see what all the direct children of identical names add up to.
                if (isAggregated)
                {
                    Dictionary <string, PerfRecord> nodes = new Dictionary <string, PerfRecord>();
                    PerfRecord primeEntry;
                    for (int i = 0; i < this.SubRecords.Count; ++i)
                    {
                        PerfRecord subrecord = this.SubRecords[i];
                        if (nodes.ContainsKey(subrecord.Name))
                        {
                            primeEntry = nodes[subrecord.Name];
                            primeEntry.Milliseconds += this.SubRecords[i].Milliseconds;
                            primeEntry.Aggregations++;

                            this.SubRecords.RemoveAt(i--);
                        }
                        else
                        {
                            nodes[subrecord.Name]  = subrecord;
                            subrecord.Aggregations = 1;
                            subrecord.SubRecords.Clear();
                        }
                    }
                }
            }
コード例 #3
0
        public void apply_simple_check()
        {
            var records = new PerfRecord[]
            {
                new PerfRecord("Grammar", "One", 0, 0),
                new PerfRecord("Grammar", "Two", 0, 0),
                new PerfRecord("Grammar", "Three", 0, 0),
                new PerfRecord("Request", "One", 0, 0),
                new PerfRecord("Request", "Two", 0, 0),
                new PerfRecord("Request", "Three", 0, 0),
                new PerfRecord("Request", "One", 0, 0),
                new PerfRecord("Request", "Two", 0, 0),
            };

            PerformancePolicies.PerfLimit(25, r => r.Subject == "One");

            records[2].MarkEnd(10);
            records[3].MarkEnd(50);

            var context = SpecContext.Basic();

            PerformancePolicies.Apply(context, records);

            records.Where(x => x.PerfViolation).ShouldHaveTheSameElementsAs(records[3]);

            context.Counts.Exceptions.ShouldBe(1);
        }
コード例 #4
0
 public void MarkPerformance(PerfRecord record)
 {
     duration = record.Duration;
     if (record.PerfViolation && (status == ResultStatus.ok || status == ResultStatus.success))
     {
         status       = ResultStatus.error;
         errorDisplay = ErrorDisplay.markdown;
         error        = $"**Performance threshold violation**: actual {duration} > max {record.Threshold}";
     }
 }
コード例 #5
0
        public HttpRequestTag(HttpContext context, PerfRecord perf)
        {
            Cell(context.Request.Path);
            Cell(context.Response.StatusCode.ToString());

            Cell(perf.Duration.ToString()).Style("text-align", "right");

            headerCell(context.Request.Headers);
            headerCell(context.Response.Headers);
        }
コード例 #6
0
        public void mark_performance_happy_path()
        {
            var record = new PerfRecord("foo", "bar", 0, 100);

            record.MarkEnd(50);

            theResult.MarkPerformance(record);

            theResult.duration.ShouldBe(50);
            theResult.exceeded.ShouldBeFalse();
        }
コード例 #7
0
        public void mark_performance_sad_path()
        {
            var record = new PerfRecord("foo", "bar", 0, 100);

            record.MarkEnd(150);

            theResult.MarkPerformance(record);

            theResult.duration.ShouldBe(150);
            theResult.threshold.ShouldBe(100);
            theResult.exceeded.ShouldBeTrue();
        }
コード例 #8
0
        public void mark_performance_happy_path()
        {
            var record = new PerfRecord("something", "something", 0, 100);

            record.MarkEnd(50);

            var result = new StepResult("foo", ResultStatus.ok);

            result.MarkPerformance(record);

            result.duration.ShouldBe(record.Duration);
            result.status.ShouldBe(ResultStatus.ok);
        }
コード例 #9
0
        public void mark_performance_threshold_record()
        {
            var record = new PerfRecord("something", "something", 0, 100);

            record.MarkEnd(200);

            var result = new StepResult("foo", ResultStatus.ok);

            result.MarkPerformance(record);

            result.status.ShouldBe(ResultStatus.error);
            result.error.ShouldBe("**Performance threshold violation**: actual 200 > max 100");
            result.errorDisplay = ErrorDisplay.markdown;
        }
コード例 #10
0
        private bool convertData(SpecContext context, PerfRecord record)
        {
            _expected.Each(x =>
            {
                x.DoDelayedConversions(context);
                if (!x.Errors.Any())
                {
                    return;
                }

                context.LogResult(x.ToConversionErrorResult(), record);
            });

            return(_expected.All(x => !x.HasErrors()));
        }
コード例 #11
0
        public void LogException(string id, Exception ex, PerfRecord record, object position = null)
        {
            if (id.IsEmpty())
            {
                id       = Specification.id;
                position = Stage.context;
            }

            Reporting.ReporterFor <ExceptionReport>().Log(ex);

            ex = unwrapException(ex);

            if (ex is StorytellerCriticalException)
            {
                HadCriticalException = true;

                // TODO -- hokey. Watch if this becomes a pattern
                if (ex.InnerException is MissingFixtureException)
                {
                    LogResult(new StepResult(id, ResultStatus.invalid)
                    {
                        error    = ex.InnerException.Message,
                        position = position
                    }, record);
                    return;
                }
            }

            CatastrophicException = ex as StorytellerCatastrophicException;

            var result = new StepResult(id, ResultStatus.error)
            {
                position = position
            };

            result.error = ExceptionFormatting.ToDisplayMessage(ex, out result.errorDisplay);

            LogResult(result, record);
        }
コード例 #12
0
        public void perf_record_threshold()
        {
            var record1 = new PerfRecord("grammar", "key1", 100, 0);

            record1.MarkEnd(200);

            record1.PerfViolation.ShouldBeFalse();


            var record2 = new PerfRecord("grammar", "key1", 100, 300);

            record2.MarkEnd(200);

            record2.PerfViolation.ShouldBeFalse();


            var record3 = new PerfRecord("grammar", "key1", 100, 300);

            record3.MarkEnd(500);

            record3.PerfViolation.ShouldBeTrue();
        }
コード例 #13
0
        public void LogResult <T>(T result, PerfRecord record) where T : IResultMessage
        {
            if (_latched)
            {
                return;
            }

            if (record != null)
            {
                Timings.End(record, result);
            }

            if (result.id.IsEmpty())
            {
                throw new ArgumentOutOfRangeException(nameof(result), "The id of the result cannot be empty");
            }

            result.spec = Specification.id;

            _resultObserver.Handle(result);
            result.Tabulate(Counts);
            Results.Add(result);
        }
コード例 #14
0
 public void MarkPerformance(PerfRecord record)
 {
     duration  = record.Duration;
     threshold = record.Threshold;
     exceeded  = record.PerfViolation;
 }
コード例 #15
0
 public Marker(PerfRecord record, Stopwatch stopwatch)
 {
     _record = record;
     _stopwatch = stopwatch;
 }
コード例 #16
0
 public IDisposable Subject(string category, string subject, Dictionary<string, object> metadata = null)
 {
     var record = new PerfRecord(category, subject, _stopwatch.ElapsedMilliseconds, metadata);
     _records.Add(record);
     return new Marker(record, _stopwatch);
 }
コード例 #17
0
 public void Start(string operationName)
 {
     _main = new PerfRecord("operation", operationName, 0);
     _records.Add(_main);
     _stopwatch.Start();
 }
コード例 #18
0
 // Make this smart enough to cancel the spec if the exception is catastropic or critical
 public void LogException(string id, Exception ex, PerfRecord record, object position = null)
 {
     throw new NotImplementedException();
 }
コード例 #19
0
 // Make this smart enough to cancel using the project if the result requires it
 public void LogResult <T>(T result, PerfRecord record) where T : IResultMessage
 {
     throw new NotImplementedException();
 }
コード例 #20
0
 public void LogResult <TMessage>(TMessage result, PerfRecord record) where TMessage : IResultMessage
 {
     _specContext.LogResult(result, record);
 }
コード例 #21
0
 public void LogException(string id, Exception ex, PerfRecord record, object position = null)
 {
     _specContext.LogException(id, ex, record, position);
 }
コード例 #22
0
 public void Record(HttpContext context, PerfRecord perf)
 {
     _table.TBody.Append(new HttpRequestTag(context, perf));
 }