How to synchronize two thread groups in Jmeter - jmeter

using Jmeter, I want to achieve something like this:
Thread Group 1
- Http Request 1
- Set P1 to "true"
- Wait synchronization with Thread Group 2 (parameters P1 and P2 are both "true")
- Http Request 2
Thread Group 2
- Http Request 1
- Set P2 to "true"
- Wait synchronization with Thread Group 1 (parameters P1 and P2 are both "true")
- Http Request 2
This is essentially the same as here and here described: I set P1 and P2 to "true" as follows (HTTP Request / BeanShell both work):
${__setProperty(P1,"true",)}
my problem is how to implement the wait condition. I've tried all the possible combinations for the while controller's exiting condition but couldn't achieve what I want. Strangely, a Debug sampler (or a beanshell with a log.info) placed within the loops shows me the properties P1 and P2 are correctly set (and the exit condition satisfies what I expect), but it doesn't exit anyway. For Example I've tried:
${__property("P1")}!="true"||${__property("P2")}!="true"
${__property(P1)}!="true"||${__property(P2)}!="true"
${__property(P1)}=="true"&&${__property(P2)}=="true"
${__property("P1")}=="true"&&${__property("P2")}=="true"
Can anybody help me? Thanks in advance!

See this component which handles inter thread communication:
http://jmeter-plugins.org/wiki/InterThreadCommunication/

The trick is to use the __BeanShell function for the while condition:
${__BeanShell((${__property(P1)}!="true"||${__property(P2)}!="true"}
furthermore, the While controller cannot be empty (you have to add a sampler or something like this, otherwise it will be skipped).

Related

Jmeter concurrency issue for a Thread of 7 Users

I have 1 thread Group, Within that I have 5 HTTP Request calls. 1st HTTP Request returns a value & that value is used in rest 4 HTTP Requests. The Thread Group Set Up with Number of Thread (Users) : 7 & Ramp-Up period : 5 & Loop Count : infinite. When I run the thread group it breaks due to concurrency.
Example:
When User Thread 1 executes -> Request 1,
Thread 2 executes -> Request 2 (It expects a value from Request 1, Which has not happened for thread 2, Hence it breaks).
Please find the Jmeter SetUp Images below,
Thread
HttpCookieManager
I am new to Jmeter please help me in this.
Each JMeter thread (virtual user) executes Samplers upside down (or according to the Logic Controllers
JMeter Variables are local for the thread (virtual user)
So there is no option that Thread 1 executes Sampler 1 and Thread 2 executes Sampler 2, all users will be executing all Samplers sequentially, it can be checked using __threadNum() function:
So my expectation is that either your extractor fails or Sampler 1 execution by Thread 2 fails somewhere somehow, check the requests and responses using View Results Tree listener, the JMeter Variables using Debug Sampler and jmeter.log file for any suspicious entries.

Randomised JMeter Test plan

I'm trying to do a randomised interleaved. A cut down version is as follows.
If I have:-
Thread Group
HTTP - A
HTTP - B
Random Controller
HTTP - 1
HTTP - 2
HTTP - 3
HTTP - 4
HTTP - 5
HTTP - 6
HTTP - 7
HTTP - B
I get mostly what I'm after i.e.
A,B,[Random from 1-8],A,B,[Random from 1-8] etc..
The problem is that if I set to 8 runs I don't always get each of 1-8 being run.
What I'm after is a blend with what Random Order Controller does (run each child once) but only one.
The problem with
Thread Group
HTTP - A
HTTP - B
Random Order Controller
HTTP - 1
HTTP - 2
HTTP - 3
HTTP - 4
HTTP - 5
HTTP - 6
HTTP - 7
HTTP - B
Is that it does
A,B,[Randomly run each of 1-8 once] then ends.
e.g.
A,B,7,1,6,3,8,5,4,2 then ends.
What I need is the numeric requests are randomly selected but only run once each with A & B always run as interleaved requests.
e.g.
A,B,7,A,B,1,A,B,6,A,B,3,A,B,8,A,B,5,A,B,4,A,B,2
Thoughts?
Put everything under Interleave Controller and tick ignore sub-controller blocks box:
If you want to run the whole A->B->X sequence 8 times you will need to set the number of loops to 24 under the Thread Group
In general using random execution order is not the best idea as tests should (or even must) be repeatable so maybe it worth considering using Switch Controller instead?

Loop threw Thread Group with Jmeter

I got a thread group of 10 users. I want to to connect these 10 users to an URL path mysite.com/1.
Then I want to loop a second time on these thread group and connect them to mysite.com/2.
And I need to repeat this process 10 times (i.e until mysite.com/10)...
I there a simple way of achieving that? I've already tried to use counter but what it does is connecting user1 to /1, user2 to /2 and so on...
Add While Controller to your Thread Group and put the following expression to the "Condition" area:
${__javaScript(${counter} < 11,)}
Add Counter test element as a child of the While Controller and configure it as follows:
In your HTTP Request sampler refer the incrementing value as ${counter} where required.
See How to Use a Counter in a JMeter Test to learn how to properly generate incrementing values in JMeter tests.

Jmeter: Is it possible to run a particular thread group after all the other thread group gets completed

In JMeter, I have a requirement where I want to run a particular thread group after all the other thread groups complete their run, I know the tearDown thread group has the similar behavior but unfortunately, the logic has to be part of my regular thread.
Let's say there are 4 thread groups A,B,C & D in my test plan and I want the thread group D only to be executed after A, B & C will complete their run.
Can we achieve this without using "setup, teardown & Run groups one at a time" ??
Problem ScreenShot:
I can suggest 2 options:
Use Inter-Thread Communication Plugin. See example test plan for details.
If for some reason you are not in position to use JMeter Plugins you can achieve the same using JMeter Properties like:
When Thread Group A finishes set a JMeter Property, i.e. ThreadGroupADone=true using __setProperty() function like
${__setProperty(ThreadGroupADone,true,)}
In Thread Group D:
Add While Controller at the beginning of the Thread Group and use the following condition:
${__javaScript("${__P(ThreadGroupADone,)}"=="false",)}
Add Test Action sampler as a child of the While Controller and configure it to pause for a reasonable amount of seconds, i.e. 5 so each 5 seconds While Controller will check ThreadGroupADone property value and if it is still false - sleep for another 5 seconds. When property value will become true - Thread Group D will proceed.

How to run Multiple HTTP samplers inside the IF controller

I've one scenario where there are two http samplers inside the if controller
When the if condition is true , its only running the first HTTP sampler.Its not executing the HTTP sampler2.
as example:-
if-controller ( condition true, none of the check-box got checked)
++HTTP sampler1
++HTTP sampler2
output :- only HTTP sampler1 runs . It never execute the sampler2 even if the sampler 1 result is pass state
I know I can split it into two if-controllers which would work fine. but I don't want that. Because if I have say 5 HTTP samplers to execute on basis of if-controller then I shouldn't split that to 5 if-controllers each embed with individual HTTP sampler.
if-controller ( condition true, none of the checkbox got checked)
++HTTP sampler1
if-controller ( condition true, none of the checkbox got checked)
++HTTP sampler2
Is there a way I can club all HTTP samplers underneath IF-controller and execute. I tried with simple controller but no luck.
If Controller will run all its children samplers .
Which version of JMeter are you using ? Are you sure they do not run ?
Show you Test Plan, and the 2 samplers configuration.
I have just tested it with 2.9, no problem.
It seems you have an issue in your If Controller condition
${reservationCode} != null && ${serviceId} != null && ${code} != null
Should be:
"${reservationCode}" != "null" && "${serviceId}" != "null" && "${code}" != "null"
It was my silly mistake :-). I've added the if controller insider the for controller to run few http samplers and then exit from for loop . However to exit from for loop I've added BSF post processor which was causing problem as after running the first http sampler inside if condition, then BSF postprocssor was getting invoked and it was exiting from the for loop. So it was not executing the second http sampler inside if loop. I changed the bsf post processor to bsf sampler and it worked fine.
for loop
if condition
http sampler 1
http sampler 2
BSF post processor for exit from for loop
Changed to
for loop
if condition
http sampler 1
http sampler 2
BSF Sampler for exit from for loop

Resources