Ejemplo n.º 1
0
 public void TimerMetric_CanCount()
 {
     timer.Value.Rate.Count.Should().Be(0);
     using (timer.NewContext()) { }
     timer.Value.Rate.Count.Should().Be(1);
     using (timer.NewContext()) { }
     timer.Value.Rate.Count.Should().Be(2);
     timer.Time(() => { });
     timer.Value.Rate.Count.Should().Be(3);
     timer.Time(() => 1);
     timer.Value.Rate.Count.Should().Be(4);
 }
Ejemplo n.º 2
0
 public void TimerCanCount()
 {
     TimerMetric timer = new TimerMetric();
     timer.Value.Rate.Count.Should().Be(0);
     using (timer.NewContext()) { }
     timer.Value.Rate.Count.Should().Be(1);
     using (timer.NewContext()) { }
     timer.Value.Rate.Count.Should().Be(2);
     timer.Time(() => { });
     timer.Value.Rate.Count.Should().Be(3);
     timer.Time(() => 1);
     timer.Value.Rate.Count.Should().Be(4);
 }
Ejemplo n.º 3
0
 public void can_count()
 {
     _timer.Value.Rate.Count.Should().Be(0);
     using (_timer.NewContext())
     {
     }
     _timer.Value.Rate.Count.Should().Be(1);
     using (_timer.NewContext())
     {
     }
     _timer.Value.Rate.Count.Should().Be(2);
     _timer.Time(() => { });
     _timer.Value.Rate.Count.Should().Be(3);
     _timer.Time(() => 1);
     _timer.Value.Rate.Count.Should().Be(4);
 }
Ejemplo n.º 4
0
        public void TimerCountsEvenIfActionThrows()
        {
            TimerMetric timer = new TimerMetric();

            Action action = () => timer.Time(() => { throw new InvalidOperationException(); });

            action.ShouldThrow <InvalidOperationException>();

            timer.Value.Rate.Count.Should().Be(1);
        }
Ejemplo n.º 5
0
        public void TimerCountsEvenIfActionThrows()
        {
            TimerMetric timer = new TimerMetric();

            Action action = () => timer.Time(() => { throw new InvalidOperationException(); });

            action.ShouldThrow<InvalidOperationException>();

            timer.Value.Rate.Count.Should().Be(1);
        }
Ejemplo n.º 6
0
        public void Can_time_closure()
        {
            var timer  = new TimerMetric(TimeUnit.Seconds, TimeUnit.Seconds);
            var result = timer.Time(() =>
            {
                Thread.Sleep(1);
                return(true);
            });

            Assert.True(result.IsStarted);
            Assert.True(result.IsStopped);
            Assert.True(result.StartedAt.HasValue);
            Assert.True(result.StoppedAt.HasValue);
            Assert.True(result);
            Assert.Equal(1, timer.Count);
            Assert.True(timer.Mean > 0);
        }