How to abort load test when its scenario fails?

By definition a load test is supposed to simulate many users accessing a server at the same time. It consists of series of iterations, which can be either Web tests or unit tests. Each operation is repeated the defined number of times for each virtual user.

A load test completes with status ‘Completed’. If one needs to learn more details on the run, they should open the result file (trx) and read the statistics. Now, in real world something can go wrong with either the infrastructure or one of the system components. Let’s say that one of the element in a long Web test fails for a reason. In such case you would rather not wasting time analyzing the result of the test to find it out only ten, but write it off automatically.

You can implement a load test plugin which will do the whole work. What you need to do is to add a handler for TestFinished event, which occurs every time an iteration (a Web or unit test) finishes. In this event handler you can retrieve the information whether the iteration completed successfully or not. Depending on such information you can continue (i.e. do nothing) or abort the test (possibly returning a meaningful error message). A sample OnTestFinished event handler could look as below (test is an instance of the LoadTest class):

private void OnTestFinished(object sender, TestFinishedEventArgs e)
{
	if (!e.Result.Passed)
	{
		test.Abort(new Exception("One of the load test's iterations failed..."));
	}
}

Please refer to Gabriel Szlechtman description on how to create a plugin for a load test to get more information on the structure of the plugin and how to hook it to the load test.

0 Responses to “How to abort load test when its scenario fails?”


  • No Comments

Leave a Reply