Jmeter: Why doesn't my thread restart after a cycle is completed? - loops

I have the following test plan i Jmeter:
Thread group
User params
Csv DataSource
While controller
Once only controler
http sampler
http sampler
RegEx extractor (Finds the variable that is the condition in the while loop)
If controller
Http sampler
Save response to file
BeanShell Post Processor (Cleans up used variables)
Now, my issue is, when the If controller's condition is met, after the thread is done, it loops as expected.
But, when the If controller's condition is not met, after the thread is done, the run stops, and no loop occurs.
In the thread group settings i have "Loop = 50" and "Action on Error: Start next thread loops"
In the system's log, there are no errors at all.
Any ideas?

If the condition is not met the If Controller's children will not be executed and you will not see them in the jtl results file.
If you add i.e. a Dummy Sampler after the If Controller you will see that the Dummy Sampler will be executed 50x times per each virtual user.
Some more recommendations:
Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting
According to JMeter Scoping Rules your BeanShell Post Processor will be executed after each sampler, I don't know what exactly it is doing but currently it's being executed after each Sampler so might be the case it's cleaning the variable you're using in While or If Controller.

Related

Jmeter Pacing between thread group Iterations

In Jmeter (5.4.1), I have the below thread group with 1 thread. I am controlling the frequency of the transaction using the constant timer. The constant timer_pacing in the image has the required pacing. I see that during execution, the constant timer is applied for each sample request in the particular thread group.
I am expecting all the samples before the contant timer_pacing to be executed one after the other immediately.What am I doing wrong here. Please advice.
alternatively similiar setup seems to works as expected for another thread group.
If you want to add a delay between each iteration of each thread add a Flow Control Action Sampler as the first sampler and set the delay in the controller
If you want to add a random delay consider using JMeter function Random ${__Random(1000,5000,)}
All JMeter timers obey JMeter Scoping Rules so if you have Timers at the same level as Samplers - all the timers will be applied to all the Samplers
As per Timers documentation:
Note that timers are processed before each sampler in the scope in which they are found
So if you want to add a delay between defaultPhotoUrl and Submit requests you need to add a Constant Timer as a child of the "Submit" request

Think time in JMeter per controller

How to user wait time in JMeter Test Plan, so it will wait after every transaction controller?
When adding constant timer/uniform random timer or any other timer, every sampler in the transaction controller are affected.
You can add Flow Control Action with Pause Action instead
I will executed only once for every controller
The Flow Control Action sampler is a sampler that is intended for use in a conditional controller. Rather than generate a sample, the test element either pauses or stops the selected target.

Test Fragment not executing Timers or Sample Timeout

I add in JMeter Test Fragment with Sample Timeout and Timers but without any Samplers.
I add a Module controller using this Test Fragment in Thread Group with Samplers in same hierarchy (before and after, also HTTP samplers).
I expected that the Timers and Sample Timeout will work on every Sample in scope but no timeout/delay is been done,
Also I notice that Sampler can be a child of Module controller but it won't be executed (or Timers).
It seems like a bug, but maybe there are scoping rules I missed?
Other Pre Processor as User Parameters are working so I wonder why timeout is ignored.
Your issue is indeed due to scoping rules.
Your Test Fragment is like a Controller, all elements it contains are applied to its scope.
Since it doesn't contain any sampler here, neither the timer nor the other pre/post processor run.
Note that ability of adding such useless elements will be removed in upcoming 4.0 version:
https://bz.apache.org/bugzilla/show_bug.cgi?id=61965

JMeter - alternatives to using While Controller with JDBC Request Child?

My environment: JMeter v2.11, Oracle 12, JDK 7
System: 8000 XML submissions / hour, writes to the database, then after some internal processing, status value in DB is updated (indicating the submission/application has been approved). I have some beanshell samplers setup to source values from a csv file to emulate the XML submission and I have JDBC Request to check when the database status attribute has been updated.
The JDBC request is contained within a While Controller at the end of my thread so that my JDBC request executes until the application.status column is updated.
My test runs fine for a single instance (1 loop) but for subsequent loops, the JDBC request is NOT executed. That is, if the loop count is greater than 1, for each subsequent loop, the JDBC request is NOT executed.
My current setup:
Thread Group: No. of Users-->1, Loop Count -->3
-CSV Data Config: Recycle on EOF = TRUE, STOP THREAD ON EOF = FALSE
-Beanshell Samplers: (to create and submit the XML, using csv data)
--While Controller: (${__javaScript("${status_1}" != "6")})
---JDBC Request: select status from application where applicationID = (select max(applicationID) from application); VariableName: status
As I stated above - the thread runs fine for Loop=1, but if Loop>1 is set, then subsequent loops do NOT execute the JDBC request because of it's relationship to the While Controller.
I've tried adding a parent Simple Controller to the While Controller, I've tried using multiple Loop Controllers and setting a parent Loop Controller to the While Controller but nothing I do works, and I just don't know how to proceed.
I have spent 3 days (really! 3 days!) searching the web for a way to get the While Controller included in subsequent loops - I've found only 3 instances of this question ever being asked on forums going back to 2006, but each question was never actually answered.
It even crossed my mind to create 8000 Thread Groups with a loop of 1!!. It would be a nightmare but would in fact get done what I need - but obviously I'd be here til next year setting that up and I suspect JMeter would run out of resource trying to execute all those thread groups.
Can anyone advise as to some alternatives to my approach. I'm starting to believe the While Controller not being included in subsequent loops is expected/standard JMeter functionality.
Perhaps I can use some other controllers to do what I need?
As always, any help, advice, hints, tips are gratefully appreciated.
This is how your test goes:
First loop: status_1 variable is blank, While Controller is being executed
Second loop: status_1 variable value is 6, While Controller is NOT executed as condition is false.
Add a Debug Sampler before your While Controller to see it yourself
The solution is as simple as just adding the next line to one of your Beanshell Samplers:
vars.remove("status_1");
ResponseMessage="variablescleared";
ResponseCode=200;
This line will clear "status_1" value of "6" and your While Controller will be executed on next iteration.

Jmeter - Stop All Threads After Specific Duration When Thread Has Loop Controller

My current environment: JMeter v2.11, remote Oracle 12, JDK 7
I have a recorded script for 200 users to login to a web application within 1 thread group but I need to keep this going for several hours so I need to keep the 200 user's sessions live for several hours and if there is no interaction, the http sessions will expire, so I decided to use a Loop Controller to simply resubmit the same http request every 14.5minutes, once the user's session has been established by logging in.
Because I need to stop the script running after a certain duration I specified the Duration on the Thread Group, but I noticed that if the http requests were before the Loop Controller in the script occurred when the Duration value was reached, the script stopped, however - if the http requests that were being exercised when the 'Duration' was reached were in the Loop Controller - the Loop Controller overrode those Duration settings and the script ran until the number of loops had completed.
I found the following posts https://sqa.stackexchange.com/questions/8378/how-to-run-jmeter-test-plan-for-specified-amount-of-time and
https://sqa.stackexchange.com/questions/1660/how-to-stop-thread-in-jmeter
and followed the instructions to create a second separate Thread Group placing a Test Action with a Constant Timer child which will stop ALL Threads.
Again (as when specifying the 'Duration' via the Thread Group property value) the Stop Test Action works when stopping the script in the other Thread Group if the http requests being executed are not in the Loop Controller - If they are, the Stop Test Action does not work - i.e. the Loop Controller overrides the Stop Test Action's Constant Timer Duration value and runs until the Loop Count has completed.
My Workings below:
Thread Group 1 : No. of Threads-->200, Ramp Up-->1, Loop Count-->Forever, Duration-->900 seconds
-HTTP Request Defaults
-Recording Controller
--HTTP Request (GET) - Login Page Launched
--HTTP Request (POST) - Login Details submitted
--HTTP Request (POST) - Home Page displayed
---Loop Controller : Loop Count --> 2
----HTTP Request (POST) - Relaunch Home page
-----Constant Timer : Thread Delay --> 870000 ms
----HTTP Request (POST) - Select 'Yes' to View Home Page Again
Thread Group 2 : No. of Threads-->1, Ramp Up-->1, Loop Count-->Forever, Duration-->900 seconds
-Test Action: Stop, All Threads
--Constant Timer --> 900000 ms
note: I used 15minutes/900 seconds/900000 milliseconds to test my boundaries above.
Can anyone provide any insight into how I can stop the thread running after a certain duration despite the loop controller settings? That is - can anyone describe a way to override the loop controllers settings to stop the thread after a certain Duration, rather than it stopping once the Loop Count has been reached?
Many Thanks!
I have identified what was causing my problem. The Loop Controller value - it needs to be set 'Forever' so that it doesn't override the 'Duration' settings in either the parent Thread Group or the separate Stop Test Action (with child Constant Timer) Thread Group.
Once the Loop Controller is set 'Forever' it appears JMeter then runs up to the 'Duration' settings.
Thanks

Resources