Esempio n. 1
0
        public void Record_records_in_correct_units()
        {
            var pause     = TimeSpan.FromSeconds(1);
            var histogram = Create(DefaultHighestTrackableValue, DefaultSignificantFigures);

            histogram.Record(() =>
            {
                Spin.Wait(TimeSpan.FromSeconds(1));
            });

            var stringWriter = new StringWriter();

            histogram.OutputPercentileDistribution(stringWriter,
                                                   percentileTicksPerHalfDistance: 5,
                                                   outputValueUnitScalingRatio: OutputScalingFactor.TimeStampToMilliseconds,
                                                   useCsvFormat: true);

            //First column of second row.
            var recordedMilliseconds = GetCellValue(stringWriter.ToString(), 0, 1);
            var actual   = double.Parse(recordedMilliseconds);
            var expected = pause.TotalMilliseconds;

            //10% Variance to allow for slack in transitioning from Thread.Sleep
            actual.Should().BeInRange(expected * 0.9, expected * 1.1);
        }
        public void TimeStamp_values_are_accurate()
        {
            var  delay       = TimeSpan.FromSeconds(1);
            var  expected    = TimeStamp.Seconds(delay.Seconds);
            long minAccepted = (long)(expected * 0.95);
            long maxAccepted = (long)(expected * 1.05);

            var start = Stopwatch.GetTimestamp();

            Spin.Wait(delay);
            var end    = Stopwatch.GetTimestamp();
            var actual = end - start;

            actual.Should().BeInRange(minAccepted, maxAccepted);
            Assert.Equal(TimeStamp.Seconds(60), TimeStamp.Minutes(1));
            Assert.Equal(TimeStamp.Minutes(60), TimeStamp.Hours(1));
        }