include in jmeter - jmeter

How we can include a thread group in JMeter in the same test plan
I have two thread groups in the same test plan
thread group 1
thread group 2
I want to include the thread group 1 to the thread group 2
is it possible?

You can't actually make one THREADGROUP a child to another THREADGROUP. This is because each threadgroup specifies the number of threads and duration. Jmeter doesn't support nested threadgroups.
You have two options. Either way, do the following
Select all elements in THREADGROUP 2, RIGHT CLICK and add a parent controller of "Simple Controller" named "master simple controller" (for clarity)
Option 1. In threadgroup 2, move the master simple controller into threadgroup 1
Option 2. Create a MODULE CONTROLLER in threadgroup 1 and point it to the master simple controller

Related

Delay the Threadgroup in jmeter test

I have 4 thread groups in my test. I have requirement as below:
I want first 3 thread groups to work sequentially. Hence, I have checked the chekcbox "Run Thread groups consecutively". But, i want my fourth thread group to start 30 mins after the third thread group while the third thread group is still not complete. Can this be achieved on Jmeter. Any help on this is highly appreciated.
If you tick Run Thread groups consecutively box you won't be able to have more than 1 thread group running at any moment of time.
So you need to untick that box on test plan level and start all Thread Groups in parallel.
The fact that the thread group has started doesn't necessarily mean that it will start executing Samplers, you can delay the execution until the previous Thread Group is done.
For example you can use Inter-Thread Communication Plugin for this purpose, in 1st thread group and put something into a FIFO queue and then try to read the value using jp#gc - Inter-Thread Communication PreProcessor in the 2nd Thread Group (add it to the first sampler). The 2nd Thread Group will start executing samplers only when the value will be available in the queue.
See SynchronizationExample.jmx test plan for example implementation
The same approach should be applied for thread groups 3 and 4, when 3rd thread group starts - put something to the FIFO queue so 4th thread group would be aware that the 3rd one has started, then you can "sleep" for 30 minutes using Flow Control Action sampler

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.

How to run two thread groups consecutively in a loop

Is there any way to run two ThreadGroup consecutively in a loop for a certain amount of time? I am writing a test scenario in which I have to create a task for multiple users and then fulfill this task by them. Therefore, I decided to divide the scenario into two thread groups, because it needs one user to create a task and many users to complete it. Everything works fine, but the problem arises when I try to run the test in several iterations.
I tried to check Run Test Group consecutively check-box, but tests instead of performing alternately, e.g.
ThreadGroup 1
ThreadGroup 2
ThreadGroup 1
ThreadGroup 2
perform as follows
ThreadGroup 1
ThreadGroup 1
ThreadGroup 2
ThreadGroup 2
Is it possible to somehow make thread groups execute alternately? I would be very grateful for any advice.
If you want to run multiple iterations you need to let thread group 2 know that the task is ready and let thread group 1 know that the task is compete and it's ok to generate a new task.
There are 2 approaches of passing data between Thread Groups:
__setProperty() function to create/update a value in one Thread Group and __P() function to read the value in another Thread Group
Inter-Thread Communication Plugin, see SynchronizationExample.jmx for reference implementation

Does JMeter support to select a sampler in Thread Group randomly?

In my Test Plan, I have Thread Group with 5 Samplers. Is there a way with JMeter that I want to select one among the 5 samplers in Thread Group Randomly and do performance testing to only that particular sampler ?
Add User Defined Variables to your Test Plan and create i.e. randomSampler variable with the value of ${__Random(0,4,)} (use __Random() function to generate a random number between 0 and 4 inclusively)
Add Switch Controller to your Thread Group and use ${randomSampler} as the "Switch Value"
Put your Samplers under the Switch Controller
That's it, each time you run the test the random Sampler will be chosen and executed:

Introducing a delay between two thread groups in jmeter

I want to introduce some delay between two thread groups.
My test plan is-
Thread Group 1 -
a. Thread 1
b. Thread 2
c. Thread 3 (loop controller is added as a parent to thread 3. Loop controller is designed to run Forever)
Thread Group 2
My plan is to start thread group 1 and then start thread group 2 after some delay. Once both thread group have started they should keep on running. I need to introduce a delay between thread group 1 and 2.
I have tried 2 methods below, but they did not serve my purpose.
I selected Run Thread Groups consecutively from test plan, and introduced a test Action Sampler at the end of thread group 1 with
Target: All Threads
Action: Pause
Duration: 5000
and added Synchronizing Timer as a child of the Test Action sampler and set Number of Simultaneous Users to Group by to the number of threads (virtual users) in the Thread Group 1.
Simply added a Constant Timer before start of Thread Group 2.
What is a good solution for this?
Your solution 1 is very good however you need to add a Test Action sampler to the very beginning of the Thread Group 2 as your current setup assumes it running in the end of Thread Group 1 like:
Thread Group 1
Wait 5 seconds
Thread Group 2
Adding a Constant Timer between thread groups is absolutely not something you want to do as given you have the constant timer at the same level as Thread Groups it means the delay will be applied to each and every sampler. You need to move the timer to be a child of the first request of Thread Group 2. Timer will execute before the request which seems to be something you're looking for. See Advanced Load Testing Part 3 - Top 4 Timers article to learn more about timers use cases and best practices
And finally probably the fastest and the easiest solution would be setting a Startup delay for 2nd Thread Group. It can be done under "Scheduler" section:
as per the documentation:
If the scheduler checkbox is selected, one can choose a relative startup delay. JMeter will use this to calculate the Start Time, and ignore the Start Time value.

Resources