private void VerifyGc(GcStatsCollector collector, string gen, string reason, string type)
        {
            using var gcReasonManualResetEvent = new AssertionManualResetEvent(() =>
                                                                               collector.GcReasons.WithLabels(gen, reason, type).Value > 0);
            gcReasonManualResetEvent.Wait(TimeSpan.FromSeconds(10));

            using var gcDurationManualResetEvent = new AssertionManualResetEvent(() =>
                                                                                 collector.GcDuration.WithLabels(gen, reason, type).Value.Sum > 0);
            gcReasonManualResetEvent.Wait(TimeSpan.FromSeconds(10));

            collector.GcReasons.WithLabels(gen, reason, type).Value
            .Should().BeGreaterThan(0);
            collector.GcDuration.WithLabels(gen, reason, type).Value
            .Sum.Should().BeGreaterThan(0);
        }
Example #2
0
 private void AssertWorkerThreadCountIncreased(ThreadPoolStatsCollector collector)
 {
     using var resetEvent = new AssertionManualResetEvent(() =>
                                                          collector.WorkerActiveThreadCount.Value >= 0);
     resetEvent.Wait();
     collector.WorkerActiveThreadCount.Value.Should().BeGreaterThan(0);
 }
Example #3
0
 private void ExceptionShouldBeCollected <TException>(ExceptionStatsCollector collector)
     where TException : Exception
 {
     using var assertionManualResetEvent = new AssertionManualResetEvent(() =>
                                                                         collector.ExceptionCount.WithLabels(typeof(TException).FullName).Value >= 1);
     assertionManualResetEvent.Wait();
     collector.ExceptionCount
     .WithLabels(typeof(TException).FullName).Value
     .Should().Be(1);
 }
        private void ScheduledTasksShouldBeCounted(ThreadPoolSchedulingStatsCollector collector, int taskCount)
        {
            using var assertionManualResetEvent = new AssertionManualResetEvent(() =>
                                                                                collector.ScheduledCount.Value >= taskCount - 1);
            assertionManualResetEvent.Wait(TimeSpan.FromSeconds(10));

            collector.ScheduledCount.Value.Should().BeGreaterOrEqualTo(taskCount - 1);
            collector.ScheduleDelay.Value.Count.Should().BeGreaterOrEqualTo(taskCount - 1);
            collector.ScheduleDelay.Value.Sum.Should().BeGreaterThan(0);
        }
Example #5
0
        public void When_There_Is_Lock_Contention_Then_Contention_Should_BeRecorded()
        {
            const int    threadCount           = 50;
            const int    sleepMs               = 10;
            const double expectedContentionSec = (double)sleepMs * threadCount / 1000;
            var          lockObj               = new object();

            using var collector = CreateStatsCollector();

            void Lock(int sleepTimeout)
            {
                lock (lockObj)
                {
                    Thread.Sleep(sleepTimeout);
                }
            }

            var threads = new List <Thread>();

            for (var i = 0; i < threadCount; i++)
            {
                var thread = new Thread(() => { Lock(sleepMs); });
                thread.Start();
                threads.Add(thread);
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            var manualResetEvent =
                new AssertionManualResetEvent(() => collector.ContentionTotal.Value >= threadCount - 1);

            manualResetEvent.Wait();
            collector.ContentionTotal.Value.Should().Be(threadCount - 1);
            collector.ContentionSecondsTotal.Value.Should().BeGreaterOrEqualTo(expectedContentionSec - 0.25);
        }