- I am using VS 2010 unit tests to create a load test.
- BeginTimer/EndTimer are used to measure the response time.
- On success, the timer works as expected.
If an error occurs in the application, I don’t want the timer to record the response time. This will throw off the analysis reports. As an example, an OpenOrder method on success may take 30 seconds, but on failure (eg order not found), the OpenOrder might return in 2 seconds. I want the response time metrics to represent only thebactions that were successful.
- Alternatively, is there a way to filter out the timers/transactions
that were not successfull? - Is there another way to do this? Something else besides
BeginTimer/EndTimer?
Code Snippet:
testContextInstance.BeginTimer("trans_01");
OpenOrder("123");// Execute some code
// If the open fails, I want to disregard/kill the timer.
// If I do a 'return' here, never calling EndTimer, the timer
// is still ended and its response time recorded.
testContextInstance.EndTimer("trans_01");
This is a deficiency in the unit testing API. There is a similar lack in the web testing API. I too have wanted a way to disregard timers around failures, but I think we are out of luck here. I believe an enhancement request to Microsoft is needed.
There is (possibly) a (lengthy) workaround: add in your own timer (using Stopwatch class) that you can ignore/terminate at will, and also add the relevant code to insert a result row directly into the transactions table in the load test results database (asynchronously for best performance).
But that’s awful. It would much easier if the API simply offered a ‘KillTimer’ method.