Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stopping a user thread conditionally in JMeter

Tags:

jmeter

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.

like image 846
Sandeep Nair Avatar asked Mar 28 '14 18:03

Sandeep Nair


People also ask

How do you stop a thread in JMeter?

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 If Controller in JMeter?

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.

What is specify thread lifetime in JMeter?

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.

How do I run a concurrently thread in JMeter?

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.


2 Answers

There are at least 2 options on how you can conditionally stop test thread or even the whole test:

  1. Use Test Action sampler in combination with If Controller
  2. 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
    }
    
like image 86
Dmitri T Avatar answered Sep 28 '22 02:09

Dmitri T


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.

like image 44
Roberto Mereghetti Avatar answered Sep 28 '22 01:09

Roberto Mereghetti