JMeter: thread switching between variables for preset time periods throughout a test run - jmeter

I have a script with a once only loop where a thread uses reg expression extractor to get a variable into an array. After the once only loop, the thread selects a random instance of that variable and then continues with that instance of the variable for the entire test run.
It would be more realistic for the script to do the following:
Jmeter thread uses variable_1 for x seconds, switch to variable_2 for x seconds, switch to variable_3 for x seconds
Variables_1,2,3,x coming from the reg ex array should be selected randomly
x seconds could be 300, 600, 1200 and selected randomly
Is this something that can be accomplished with JMeter controllers/functions or would it require something along the lines of custom beanshell code?

It can be done using ForEach Controller & Runtime Controller.
For Each controller is to iterate the variables one by one.
Under Runtime controller, you keep all your samplers to be executed for the duration.
Test Plan:
For Each Controller config:
Runtime Controller config:

I would recommend reconsidering your approach as this way you test won't be repeatable. The whole idea of testing is that when you run the test 2 or more times - you should get the same results, elsewise if you discover a product issue you won't be able to reproduce it to ensure that it is fixed.
Coming back to your question: yes it can be done via JMeter Test Elements without having to go into scripting. Take a look at __chooseRandom() function available via JMeter Plugins project. The easiest way of installing JMeter Plugins and keeping them up-to-date is using JMeter Plugins Manager

Related

JMeter override timers / reduce timer for certain step in larger scope

I am running a JMeter scenario which has a certain think time applied for the entire scenario.
During one small loop in this scenario, I wish to decrease the think time between each sampler. E.g., if the default scenario think time, for all samplers, is 500ms, I wish to make this one small loop have a think time of only 100ms.
It does not seem like this is possible, but I also don't see any other questions asking this. Does anyone know of a workaround to accomplish what I am trying for?
This line in the JMeter docs suggests that this is not possible:
Note that timers are processed before each sampler in the scope in which they are found; if there are several timers in the same scope, all the timers will be processed before each sampler.
https://jmeter.apache.org/usermanual/component_reference.html#timers
You can do the following:
Declare a JMeter Variable to hold the default think time somewhere in User Defined Variables
In all Constant Timers (or in the one if it's applied to all the Samplers) set it to use the JMeter Variable from the step 1:
Before entering your "small loop" add a JSR223 PostProcessor to the last Sampler and put the following code into "Script" area:
vars.put('think-time', '100')
In the above code vars stands for JMeterVariables class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information if needed.
Before exiting the "small-loop" do the reverse thing and restore the original value of the think time

JMeter Thread Groups - Is it possible to make the same instance of one behave as a time based or an iteration based element dynamically at runtime?

I am creating a JMeter Test Harness that will be run from Jenkins using "Build with Parameters' to set runtime parameters that are passed into JMeter as Properties using -J attributes.
End users will be given the choice of running tests either based on the number of iterations or a period of time.
I can easily interrogate a passed in property value to determine if an 'iteration' or 'time' based test type and in order to try this I have added variables (which may or may not be have values depending) for ALL of the Thread Group 'Thread Properties' fields as can be seen below. Each variable will have a value of either 0 or 1+ depending upon the Jenkins parameters passed in at runtime.
enter image description here
As I do not want to create 2 Thread Groups (one for iteration based, and the other time based) then use logic controllers or similar to control what way to test, is there a dynamic way to switch the Thread Group 'Thread Properties" behaviour at run time using the singular Thread Group?
enter image description here
Any help in making 1 thing do 2 things in my little world of JMeter will be greatly appreciate!!
Not really, with "vanilla" JMeter you can:
Set number of iterations to -1 for "duration" based test
Set duration to a very long value (a couple of years) for the "iteration" based test
Other options are in:
JMeter .jmx scripts are basically XML files and XML is a subset of text so you can use a text editor like sed to substitute values directly in the .jmx file
Taurus automation framework has a nice feature of modifying an existing JMeter test before launching, it allows overriding absolutely any property of absolutely any element.

How to perform Manual step in JMeter and resume test

Can I perform a test that will stop in some step, and after I perform something manually in my system I will tell Jmeter to resume running the test?
is it possible in JMeter to pause a test in the middle and then to resume it?
I don't know about out of the box solution in JMeter, so you need to add such logic yourself.
For example you can do a While controller with a variable set to true at start, inside loop read from file until it's value is false and then exit loop and resume test. You can even use StringFromFile function as ${__StringFromFile(flagResume.txt,,,)}
In your manual operations add to file the value false, and then the JMeter test will resume.
What is the nature of the task you need to do manually? I'm pretty much sure that it is doable via JMeter itself, JMeter Plugins or Groovy Scripting.
If I'm wrong or you have a very specific scenario one of possible solutions would be adding Constant Throughput Timer to your Test Plan and define desired Requests per Minute rate using JMeter Property via __P() function
Whenever you need to "stop" the test you can set the "throughput" property to 0 using i.e. Beanshell Server

How can I test the limit of the number of threads with Jmeter

Is it possible to automate the load tests in Jmeter and increase the number of threads until the first error is observed?
For example I start with testing 16 threads for every seconds and increase the number until i receive an error. But instead of doing this manually can I let this run automatically?
Looking into Pre-defined Properties section of JMeter's User Manual on Functions there is a JMeterThread.last_sample_ok variable holding result of the last sampler execution.
So if you build your test plan as follows:
Sampler which does test action
If Controller checking whether previous sampler was successful
If not - relevant actions (stop test, send email, stop ramping up virtual users, etc.)
The value you need to put in "Condition" input of If Controller should look like
"${JMeterThread.last_sample_ok}"=="false"
See How to use JMeter's 'IF' Controller and get Pie for more information on JMeter's If Controller.
Regarding threads in jmeter You may find those 2 links interesting:
What is the highest number of threads that is reasonable to simultaneously run in Jmeter?
JMeter max. thread limit
Regarding your methodology, why not use slow rampup and see the limit using what Dmitri T has provided ?

Is it possible to create a User Defined Variable in JMeter using an expression?

I've been trying to use JMeter to create some automated Performance Tests and I'm setting up a job in Jenkins so that people can run it and view the results there.
I'm trying to add a few parameters to the job that correspond to the options available in the Thread Group. They are:
Number of Users
Ramp-up Period
Loop count
Some people don't quite understand the concept of the 'Ramp-up Period' so instead I wanted to make refer to it as 'Delay' and use it to control how long each thread will wait before starting the test. This would mean that the 'Ramp-up Period' should be equal to (The Number of Users x Delay).
The command I'm using to run the test is below:
jmeter -n -t <myscript>.jmx -l results.jtl -j jmeter.log -JUSERS=10 -JDELAY=1 -JLOOPS=1
and the variables look like this:
USERS = ${__P(USERS)}
RAMPUP = ${USERS}*${__P(DELAY)}
LOOPS = ${__P(LOOPS)}
But unfortunately the value of the RAMPUP variable was not what I expected. It ended up being "${USERS}*1"
Is there a way to do this in JMeter?
JMeter variables and properties are Strings, you can not apply arithmetic operations to them. The behavior you're getting is absolutely expected. Also there is no possibility to dynamically change properties during runtime, you'll have to calculate ramp-up prior to passing it to JMeter.
You can add BSF PreProcessor before you test plan, calculate there values for user defined variables and put values into variables using putObject(String key,Object value)

Resources