JMeter - Stop thread after error, but allow retries - jmeter

I have a JMeter script which makes requests to 5 different endpoints. If there's an error, that thread should be stopped.
However, I would like to retry the request to the 3rd endpoint 3 times before stopping the thread.
Here is what my script looks like:
Thread Group (with Stop thread selected)
HTTP Request (1st endpoint)
HTTP Request (2nd endpoint)
Transaction Controller
While Controller
HTTP Request (3rd endpoint)
JSR223 PostProcessor (to save the response code in a variable for the while controller to check)
Counter (to keep track of the retry count)
JSR223 Assertion (to set the result as successful, so the first failed retries don't count)
HTTP Request (4th endpoint)
HTTP Request (5th endpoint)
Since I checked option Stop thread under Thread Group, if the first request to the 3rd endpoint fails, the thread stops and no retries are made.
If I check Continue, then the retries to the 3rd endpoint work as intended, but the thread doesn't stop if the requests to the other endpoints fail.
I also tried to add the following Groovy script to the JSR223 PostProcessor, but it didn't work:
if (prev.isStopThread()) {
prev.setStopThread(false)
}
I'd appreciate any help I can get.
Thank you!

Just set "Action to be taken after a Sampler error" to Continue in the Thread Group to prevent threads from stopping.
If you decide to stop the thread you can do it in 2 ways:
Via Flow Control Action Sampler (in conjunction with the If Controller)
Via any of your JSR223 Test Elements as
prev.setStopThread(true)
You don't even need a counter, since JMeter 5.0 While Controller exposes current iteration via __jm__While Controller__idx pre-defined variable

Related

JMeter - How to handle Long polling transport request method

In my Jmeter script request which contains the 'LongPolling' transport method and it takes a high load time or response time
Also, the response message content value is used for the next consecutive request. How can I handle that scenario?
I don't want this my wait time for the server response
JMeter thread model assumes that a thread (virtual user) always waits for the previous sampler to fully complete before starting the new one.
The easiest solution is moving your "long-polling" requests into a separate thread group and if you need to pass data between thread groups either use __setProperty() and __P() functions combination or go for Inter-Thread Communication Plugin
If you need to have everything within the single Thread Group - you can consider using Parallel Controller, however it might not be fully suitable for your needs as it is still a Sampler hence it waits for all its children completion prior to proceeding
Depending on your use case you can find jmeter-asynchronous-http plugin useful, see How to Load Test Async Requests with JMeter article for more details if needed.

Synchronization Timer not behaving as expected

I posted a question previously about how to delay all the threads in a thread group until the last one had ramped up completely. It was suggested I use a Synchronization Timer and it seemed like the right timer to use. However I have subsequently found that the Synchronization Timer is not only delaying all threads, like I want it to, my test is now only executing the next request after the previous one completely finishes for all requests.
My test is set up like this:
Test (20 threads)
Login (Transaction Controller)
Do Something (Transaction Controller)
Synchro Timer (to wait until all users have logged in)
HTTP Request 1
HTTP Request 2
...
So for above example:
All 20 users ramp up and are logged in
Once all users are logged in 20 HTTP Request 1s are executed simultaneously
Only after all 20 HTTP Request 1s have received a response then 20 HTTP Request 2s are executed
While I'm after the first lot of 20 HTTP Request 1s to be fired off at the same time, I want the following HTTP Request 2s to be executed progressively as the HTTP Request 1s responses return. I don't want the wait here.
How can I do this?
According to the documentation on timers:
Note that timers are processed before each sampler in the scope in which they are found; if there are several timers in the same scope, all the timers will be processed before each sampler.
Timers are only processed in conjunction with a sampler. A timer which is not in the same scope as a sampler will not be processed at all.
To apply a timer to a single sampler, add the timer as a child element of the sampler. The timer will be applied before the sampler is executed. To apply a timer after a sampler, either add it to the next sampler, or add it as the child of a Flow Control Action Sampler.
Please be informed about JMeter Scoping Rules, according to your setup the Synchronizing Timer is applied to all HTTP Request samplers under the Transaction Controller while according to your description you need to apply it only to the HTTP Request 1
Make the Synchronizing Timer a child of the HTTP Request 1 and it should resolve your issue.

Jmeter Threads not executing independently

I am using jmeter 4.0 to simulate android app.
the app generate data upload to server.
jmeter script is like.
Thread Group -> 13500 threads rampup : 20min
|->once only controller
|->Simple controller
|->HTTP Request(get number of uploads)
|->JSR223 Sampler (parse response,set up loop var)
|->Loop Controller
|->JSR223 Sampler (generate data)
|->HTTP Request (send data)
|->Take Action Sampler
|->Constant Timer
When script is executed. At first it execute all the once only controller of all the threads then HTTP request for all the threads. So on.
Jmeter is executing each sampler for all the threads then procedding to the sampler.Threads execution is not independent.
I am printing the logs to the console from JSR223 Sampler.
No that’s not what is happening.
You think it is most probably because you start all threads at same time.
In Jmeter all threads run independently.
Add a slight delay using rampup field so that threads gradually start and you’ll see.

JMeter - How to handle Longpolling transport method

One of the Jmeter requests which I captured contains the 'LongPolling' transport method. So it takes high load time/latency.
I don't want to have this much of high latency in the request.
How can I handle this situation in JMeter. I have already tried 'bzm-Parallel Controller' and it was not success.
You can Insert Parent (Right Click) a Runtime Controller with 1 second, it'll execute your long request, but will wait only 1 second and continue to next requests
Notice that it'll be marked as failed due to java.net.ConnectException
If you want you can add a child JSR223 PostProcessor with the following code to mark it successful
prev.setSuccessful(true);
setSuccessful method can override results status

JMeter: Stop Thread Group after first HTTP request fails

I am testing a mobile app, and I have a Thread Group with about 40 HTTP requests, with the first being an access token request. What I want to do is if the access token fails, skip that current thread iteration.
There are at least 3 options:
You can define what action to take on sampler error on Thread Group level
If you need to limit this behavior to one sample add a Result Status Action Handler as a child of the request
If you need to skip current iteration based on certain condition use Test Action sampler in combination with If Controller

Resources