Back to FAQs

How do I make a v-user stop playing a script if an error occurs?

There are different types of errors that can happen when you’re playing a Loadster script.

Socket errors include anything that prevents a valid TCP connection from being made or maintained. This includes connection timeouts, socket timeouts, and connections being closed prematurely.

Protocol errors such as HTTP 500, HTTP 401, etc mean that the server has received your request, but is declining or unable to handle it.

Validation errors happen when one of your custom validators fails in Loadster. For example, you might have created a validator to make sure the word “Welcome” occurs in the response body. If it isn’t found, the validator will throw an error.

Loadster’s default behavior when an error is encountered is to report the error and continue playing the script. This is desirable when errors are intermittent or outside your control, and where the requests are stateless and the later steps in your script don’t have any dependency on them.

However, the default behavior is undesirable for steps that the rest of your script depends on, such as a login step or a step that creates a resource on the server that you’ll reference later in the same script. In these situations it’s better to abandon that iteration of the script as soon as such an error occurs.

To change Loadster’s error handling behavior, go to Settings and check Halt script execution on any error. When this is checked, any error will cause the v-user to stop their current iteration of the script. If a load test is in progress, and time is remaining, the v-user will then start a brand new iteration of the script instead of continuing.

However, there are times when you might want to run a certain number of iterations and then stop. For example, maybe you are testing a shipping application, and just want to process 10,000 shipments in as little time as possible. Once that number of iterations has been reached, the v-users should exit, even if there is time remaining in the test.

To set an iteration limit, open your test scenario and click the wrench for the v-user group(s).

Getting to the advanced v-user group settings
Getting to the advanced v-user group settings

Click to expand the iteration limit. While it’s unlimited by default, adding a limit here will make your v-users stop once the limit has been reached.

Limiting the number of iterations
Limiting the number of iterations

Keep in mind, if the test is too short, your v-users may still exit before the number of iterations has been reached. They exit after the iteration limit has been reached or the time runs out, whichever happens first.

Read more about this and other advanced configuration options in Running Load Tests.