How to perform teardown for a specific Thread Group - jmeter

is there a way to create a teardown for a specific Thread Group in Jmeter? That is, the object "tearDown Thread Group" seems to be executed at the end of each Thread Group in the test. It's possible to bind a tearDown only with a single Thread Group? If not, is there an other object to insert in the Thread Group to achieve that?

JMeter executes Samplers upside down (or according to Logic Controllers) so it's sufficient to put your "teardown" logic to the "bottom" of the Thread Group and the relevant Samplers will be executed "last".
Few more hints:
If you need to run your main logic for several iterations - put it under the Loop Controller
If you need to run your main logic for specific time - put it under the Runtime Controller
If you need to pass some data between Thread Groups you can use Inter-Thread Communication Plugin

Related

How to stop a thread group execution if the request from previous thread group fails in JMETER test plan?

In a JMeter test plan, I have 4 thread groups which will be executed consecutively, however there is a dependency of certain variables from one thread group to another and hence, in case of any sampler failure in previous thread group, the execution of subsequent thread groups should stop.
Test Plan:
Each thread group is a simple thread group [not setUp or tearDown thread group]
How to control or decide the thread groups execution flow/order in JMeter?
The fastest and the easiest way is to stop the test when an error occurs on Thread Group level
If you want more flexibility you can check whether this HTTP Request B2 was successful or not by using ${JMeterThread.last_sample_ok} pre-defined variable in the If Controller, then you can add Flow Control Action as a child of this If Controller and decide what do you want to do there.
This is pretty much similar to point 2, if your Thread Groups C and D rely on a variable from the Thread Group B you can put all the Samplers under the If Controller
You can set number of threads in Thread Groups C and D using __P() function like ${__P(threads,)} and in case of value you can use __setProperty() function to set this threads property to 0 - thread groups with 0 threads are not being "started"
You need to pass the status (flag) from the previous thread group(s) to the subsequent thread groups. Status should be evaluated before executing the requests in the subsequent thread groups.
You can pass the values between the thread groups with JMeter properties.
Use props.put('canContinue',true) from the JSR223 element with the status
or
Set the property through JMeter function ${__P(canContinue,true)}
In the subsequent thread groups you can check the status with a If controller
${__groovy(!props.get("canContinue"),)}
Add a Flow Control Action sampler to the If Controller and set what you want to do.

JMeter - if controllers on thread group

Is it anyway I can have an if controller above a thread group, like:
TestPlan
-> If controller
----> Thread Group
I.e I just want to execute the if controller once so I can avoid unnecessary execution in the Thread Group?
You can add to Thread group in Number of Threads field get value from property, as:
${__P(GroupANumberOfThreads,0)}
So if you don't have property, for example don't send -JGroupANumberOfThreads=1 in CLI mode Thread group won't get executed
There are following options:
Put everything inside the Thread Group under the If Controller, this way no Samplers will be executed if the condition is not met, but the Thread Group will be still started and all threads will kick off
Set number of threads in the Thread Group to 0, it can be done using __if() function (member of JMeter Custom Functions plugin bundle, can be installed using JMeter Plugins Manager)
You can also consider running your JMeter test using Taurus tool as the wrapper, Taurus provides possibility to completely disable arbitrary test element (including thread groups) using simple declarative YAML syntax

How to handle multi user and single user in the JMeter same Thread group

I have a scenario where multi users and single users should be there in the same thread group. Multi users should execute concurrently and single users should execute sequentially. How to handle this in the same thread group?
If you want certain Samplers to be executed sequentially, i.e. only one request of that kind should be executed at any given moment - put the relevant Sampler under the Critical Section Controller
If you want certain Samplers to be executed in parallel - put them under the Parallel Controller

JMeter handle "test-completed" event

I calculate some statistics (e.g. average request duration) while my tests are running using code similar to this:
https://stackoverflow.com/a/27446405/2173353
However, I want to know when the test is done running (all the samplers have executed), so that I act upon the statistics then, and not before that. Essentially, I want to assert on the average duration of the requests when all requests are done.
Is there a way to execute code when the test is about to finish?
You must probably be looking for the tearDown Thread Group. It is some form of "special" thread group, the difference from "normal" Thread Groups is that the tearDown Thread Group is being executed after all other Thread Groups therefore you will be able to perform your "near the end" actions there.
More information: How to Use the SetUp Thread Group in JMeter When Preparing a Load Test

jmeter: How to repeat two thread groups in test plan?

I have two thread groups:
setUp Thread Group - executed only once
Thread Group - executed for number of users defined in CSV file.
The first thread group prepares data once, which will be used by all users in the second thread group.
After finish of the second thread group, I want to repeat the whole process again. This seems not possible, since there is no Forever check box for the test plan itself? Using jmeter 2.9
This is not possible using this way.
You would need to find some hack to do the same thing.
It could be something like:
While controller that tests a stop condition And has 2 If Controller children
- if controller (tests if first thread and does the setup job, when done sets while controller condition to false
- if controller ( tests if other threads and if not wait 10s)
While controller that contains test code

Resources