I have two threads in Jmeter. One the main scripts and the other is handling refreshing the Users Token
This Second one runs every 3 mins and loops forever
The First thread has multi users
this all works great but want to stop the second thread once the first thread has completed the script with all users
Thanks
You can use this element to do that by sending a notification from one thread to the other:
https://jmeter-plugins.org/wiki/InterThreadCommunication/
If you have a possibility to detect the "finish" event from the "main" thread group you can pass it to the "refresh" thread group via __setProperty() function or Inter-Thread Communication Plugin
If you don't have such a possibility you can consider adding an If Controller which will be checking the number of active threads and in case only 1 thread is left it will mean that the test has ended, example __groovy() function you can use as the condition:
${__groovy((org.apache.jmeter.threads.JMeterContextService.getThreadCounts().activeThreads = 1 && vars.getIteration() > 1),)}
Once the condition is met you can use Flow Control Action sampler to stop the current thread:
Related
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
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.
I'm using Jmeter to test multiple microservice.
The basic idea is to test a circuit breaker in a microservice environment.
Right now, I'm using two threadgroups, a master and slave remote concept.
One thread group creates uses 100 iterations and 1000 thread and creates
load against a front-end service, which sends request to a backend service.
The other group probes the backend service with 100 iterations but 1 thread.
If I’m not wrong the second threadgroup finishes way more early than the first one.
Is it somehow possible to sync those two?
And maybe another question.
As I scale the threads with the remotes, also the second thread group scales, is it possible to force the second threadgroup to use only one slave?
In order to execute "probe" thread group until "main" thread group is executing put the "probe" request under the While Controller and use the following __groovy() function as the condition:
${__groovy(org.apache.jmeter.threads.JMeterContextService.getThreadCounts().activeThreads > 1,)}
If you want to execute the "probe" thread group only on one machine of the JMeter cluster - put the whole construction under the If Controller and use the following jexl3() function as the condition:
${__jexl3("${__machineIP()}" == "IP address of the slave",)}
The whole Thread Group should look like:
I have two HTTP requests in a thread: GetOpt and verifyOtp.
User:10,
ramp-up(in sec):1 (As I want all 10 users to request for otp simultaneously),
loop:1.
How can I map particular request for its response?
Each JMeter thread (virtual user) executes samplers upside-down, so something like:
Thread x starts
Thread x executes GetOpt
Thread x executes verifyOtp
Thread x shuts down
So each JMeter thread will first execute GetOpt followed by verifyOtp. You can get individual threads response times looking into .jtl results file
if you look into threadName column you will see something like
Thread Group 1-1
Thread Group 1-2
Thread Group 1-3
etc.
where the second number is the number of thread. You can also get it using threadNum() function
Also 1 second ramp-up time doesn't guarantee that all requests will be simultaneous, better option is using Synchronizing Timer
You can add extra parameter with unique ID
&myuniqueid=${UUID()}
I started getting the desired response by just deselecting Run thread groups consecutively 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