Bug: Goal Based load test generates a LoadTestGoalCounterNotFoundException
I’m in the scalability labs with a customer this week and we’ve encountered an exception when setting up a goal based load test.
We have a bunch of machines, and my customer has created a set of custom performance counters that report appropriate data. The goal based test was setup to utilise a custom counter on a remote machine, but when we ran the test we got the following exception…
A goal based load pattern can not be applied because it specifies a performance counter (UKGC08\Availability Searches\Operations Executed / sec\) that could not be read: Category does not exist.
Here UKGC08 is the machine name that the counter was defined upon, “Availability Searches” was the category and “Operations Executed / sec” was the counter name. There was no instance specified.
In addition to the above error I also received a stack trace…
at Microsoft.VisualStudio.TestTools.WebStress.LoadTestResultsCollector.AddOrReplaceGoalProfile(LoadTestGoalBasedLoadProfile goalProfile)
at Microsoft.VisualStudio.TestTools.WebStress.LoadTestResultsCollector.AddGoalProfilesFromLoadTest(WebTestSuite suite)
at Microsoft.VisualStudio.TestTools.WebStress.LoadTestResultsCollector.Start(LoadTestRigInfo rigInfo, TestRun testRun)
Looking into the code in AddOrReplaceGoalProfile I found the error – internally this creates an instance of the PerformanceCounter class in order to read the data from this counter. The problem is that the code is currently written as follows (and thanks again to the most excellent Reflector for decompiling this for me)…
PerformanceCounter counter; if (string.IsNullOrEmpty(goalProfile.InstanceName) || string.Equals(goalProfile.InstanceName, SINGLE_INSTANCE_NAME, StringComparison.OrdinalIgnoreCase)) counter = new PerformanceCounter(goalProfile.CategoryName, goalProfile.CounterName); else counter = new PerformanceCounter(goalProfile.CategoryName, goalProfile.CounterName, goalProfile.InstanceName); counter.MachineName = goalProfile.MachineName;
The issue is that the machine name is not defined on the constructor of PerformanceCounter, and hence an exception is thrown as this code is not running on the machine that the counters are defined upon which will be the local machine or the load test controller.
I’ve raised this with the product team and they’re raising a bug internally, but in the meantime is there a workaround?
Well yes, as it happens. The code above is looking for the custom counter on the wrong machine – so the workaround is to install the counters everywhere, not just the machine under test. All I did was take the customers counters, install these locally (and on the controller, as to be fair I’m not sure which machine is running this code and didn’t test each machine individually) and voila, it all works. In the absence of a formal fix this workaround will get you running. Hope this helps!
Originally posted by Morgan Skinner on 25th August 2010 here https://blogs.msdn.com/b/morgan/archive/2010/08/25/bug-goal-based-load-test-generates-a-loadtestgoalcounternotfoundexception.aspx