示例#1
0
        public async Task MergeAfterStartAndStop()
        {
            var first  = new Timer();
            var second = new Timer();

            second.StartTimer();
            await Task.Delay(300);

            second.StopTimer();

            first.Merge(second);
            RecorderUtils.AssertRecorderOutput(new[] { 300.0M }, Unit.MilliSecond, first.FlushToString(), 30.0M);
        }
        public void TestRecorders()
        {
            var collector = new MetricsCollector();

            collector.Record("Recorder1", 1.0M, Unit.MilliSecond);
            collector.Record("Recorder1", 11.0M, Unit.MilliSecond);
            collector.Record("Recorder2", 2.0M, Unit.Second);
            collector.Record("Recorder2", 22.0M, Unit.Second);

            var metrics = collector.GetMetrics();

            Assert.Equal(2, metrics.Count);
            RecorderUtils.AssertRecorderOutput(new[] { 1.0M, 11.0M }, Unit.MilliSecond,
                                               metrics["Recorder1"].FlushToString());
            RecorderUtils.AssertRecorderOutput(new[] { 2.0M, 22.0M }, Unit.Second, metrics["Recorder2"].FlushToString());
        }
        public async Task TestStartStopTimers()
        {
            var collector = new MetricsCollector();

            using (collector.StartTimer("Clock1"))
            {
                await Task.Delay(100);
            }

            using (collector.StartTimer("Clock2"))
            {
                await Task.Delay(200);
            }

            var metrics = collector.GetMetrics();

            Assert.Equal(2, metrics.Count);
            RecorderUtils.AssertRecorderOutput(new[] { 100.0M }, Unit.MilliSecond, metrics["Clock1"].FlushToString(),
                                               10.0M);
            RecorderUtils.AssertRecorderOutput(new[] { 200.0M }, Unit.MilliSecond, metrics["Clock2"].FlushToString(),
                                               10.0M);
        }