James Martineau
James Martineau

Reputation: 951

Best practice for making some failed requests stop a thread, allowing others to continue

I have what I assume is a common scenario, and while I believe I have a working solution, it feels like there's probably a better way.

The issue is that I need finer granularity than the Thread Group-level Action to be taken after a Sampler error behavior. Some of my samplers represent requests that would prevent further execution of a workflow on failure. In these cases, rather than barreling ahead with subsequent requests that a real user could not make and that would fail anyway, I want the thread to move on to the next iteration loop, starting from scratch, as it were. Other samplers represent requests that would continue to be made even if some of them failed. In these cases, I want the thread to keep going.

The method I'm using now, which is clunky but seems to work, is as follows: at the Thread-Group level I have set the Action to be taken after a Sampler error to be Continue. I assume this means that by default, if a Sampler fails, the thread will continue with the next instructions until it reaches the end.

This leaves requests that I want to block/halt/restart the workflow on a failure. The solution I have found is to follow each of these Critical Actions with an If Controller:

Tree View

If Controller

The condition !${JMeterThread.last_sample_ok} should resolve to true if the previous Sample failed. Within the If Controller, I have a Test Action to stop execution and start the next loop iteration of the thread:

Test Action

I assume Go to next loop iteration means to start the thread over, assuming the Thread Group is set up with a loop count.

This set up seems to work, in that the thread starts over at the top of the tree each time a Sampler fails and is followed by this If/Action combo. Samplers that are not followed by this block do not halt execution on a failure.

This set up also seems very clunky, and annoying, since I'm copy-pasting this failure conditional all over the place. Is there a more elegant way of getting this behavior, or have I hit upon the more-or-less right way of doing this? Thanks!

Upvotes: 4

Views: 1614

Answers (1)

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34526

Your solution is fine except for copy/paste as you say, so the solution is to use:

enter image description here

enter image description here

Upvotes: 4

Related Questions