I have a JMeter script running for x number of users. I want to conditionally close a user thread in a while controller. For example, if my while controller exits for a user thread, I need to stop the thread. Is it possible? Sorry if this is duplicate or a dumb question.
JMeter does not provide a way for stopping thread to execute a "shutdown sequence", they have tearDown Thread group instead. You should use it in your case.
What is the JMeter If Controller? The JMeter If Controller allows you to determine whether or not to run a batch of child samplers, according to certain conditions. While the main idea is pretty simple, there are many questions and issues around this controller. Get the answers in this blog.
If the duration is set to 60 secs, JMeter will keep the execution on for 60 secs and ends it once the time is elapsed. It also ignores or override the End Time and All threads has completed its test or not. Startup delay (seconds): This tells JMeter to wait for specified time before starting the test.
1. Setting up Concurrency Thread Group in JMeter — Create Test Plan in File in JMeter and add Concurrency Thread Group to it. For example: In the above case, 100 users need to be maintained on server for steady state of 5 min. Target Concurrency is 100 and Hold Target Rate Time is 5 min.
There are at least 2 options on how you can conditionally stop test thread or even the whole test:
Use Beanshell Sampler or PostProcessor and invoke setStopThread method of SampleResult class. See How to use BeanShell guide for example. For reference:
if (condition){
SampleResult.setStopThread(true); // for Beanshell Sampler
prev.setStopThread(true); // for Beanshell Post Processor
}
ctx.getThread().stop() sets the "stop" flag in the current thread, it works anywhere the JMeterContext ctx is exposed.
I have just done and verified it in a complex test script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With