Performance Counter Interfering With Others

67 views Asked by At

I need to define performance counters for an application. I wrote couple of unit tests to assure they are working as expected. I have a test class for each different counter type like AverageCounterTest (AverageCount64) or InstantaneousCounterTest (NumberOfItems64) or RateCounterTest (RateOfCountsPerSecond64). When I run them separately they pass. If I run them together, most of them fail due to counters reporting 0 values.

Tests are as simple as the following for NumberOfItems64:

counter.NextValue(); // sample first and reset the counter
int someValue = random.Next(int.MaxValue);
counter.IncrementBy(someValue);
float expected = someValue;
Assert.AreEqual(expected, counter.NextValue());

Another example could be for RateOfCountsPerSecond64:

counter.NextValue(); // sample first and reset the counter
counter.IncrementBy(1);
Thread.Sleep(2000);
float expected = 1 / (float)2;
Assert.IsTrue(expected, counter.NextValue());

What might be causing counters report 0s? I use different performance counter categories per test (random Guid) to isolate them.

0

There are 0 answers