JMeter timers not waits the time configured in sampler - groovy

I try to create a scenario that I put a user defined delay in my test.
In the start of the test I created JSR sampler and created a variable called
vertica_results_delay and put in it the value of 400000.
Than I crated a timer and put ${vertica_results_delay}, since I want the delay will be configured in the start of the test, the problem is that Jmeter ignores my value, and not wait.
If I used Use defined field and put vertica_results_delay = 4000 it worked, but than all the tests will get the same delay, I do not want to create hard coded delay. I want to enter all properties of the test in the start of the test using JSR.
String vertica_results_delay = "400000";
vars.put("vertica_results_delay", vertica_results_delay);
log.error("vertica_results_delay " + vertica_results_delay);

Check JMeter order of execution
Configuration elements
Pre-Processors
Timers
Sampler
Your sampler executed after Timer, you need to set it before,
Add JSR223 PreProcessor outside Thread Group with your code and the delay value will be set before Timer is executed.

Timer is a scoped element which is executed before each sampler so what happens in your case is that :
JSR223 Sampler is executed after Timer
See:
http://jmeter.apache.org/usermanual/test_plan.html#scoping_rules
http://jmeter.apache.org/usermanual/test_plan.html#executionorder
To fix your issue, set your timers in a setup Thread Group, or if you only want to set it from outside of JMeter, just use function __P
and pass values on command-line:
-Jkey=value

Related

Why Until loop ends earlier?

I am performing an until loop in logic app. In this loop I'm using a delay function to do the next loop. But if we manage the delay unit to hour, the loop will end in the second time. That means the loop will only executed twice!(Escalation variable is 72 and LoopCounter increments from 0) I want to know if it is a bug from logic app or I did some wrong settings.
Please see the settings as below.
This issue seems to be with 'Until Loop' timeout. To resolve this you can try the following ways:
It looks like this is due to a bug in the way we evaluate the timeout limit value in the until scope.
Remove the triggerBody{} from the limit.timeout property – i.e. make a it a static value
If you really need to make the timeout computation dependent on the payload of the trigger request, you may want to add the “triggerBody()” into the “expression” property of the “until” (this is because we parse the expression when loading dependencies before the action is run)
For example:
You can refer to Configure Logic App 'Until Loop' timeout dynamically, Iteration in Logic Apps terminates prematurely, Until Loop Dynamic Count Limit and Add the Delay-until action

How to capture start and end time of each sampler into variable, ans pass it as input to sampler request?

My requirement is, for each Jmeter Http sampler I need pass the current sampler start time and previous sampler end time along with the input Http parameters. Please share me the example to achieve this using "preprocessors" and variabbles.
Thanks in advance
current sampler start time - you cannot get it in a PreProcessor because Sampler hasn't yet been started, consider getting the current timestamp using __time() function instead directly in the HTTP Request sampler body. If you still want to do this in Groovy - use System.currentTimeMillis() like:
vars.put('currentTime', System.currentTimeMillis() as String)
previous sampler end time - can be obtained using prev shorthand to SampleResult class instance
vars.put('previousSamplerEndTime', prev.getEndTime() as String)
In the HTTP Request sampler you can refer the values using ${currentTime} and ${previousSamplerEndTime} JMeter Variables references correspondingly
More information: Top 8 JMeter Java Classes You Should Be Using with Groovy

How do i iterate through CSV in jmeter creating new thread

I am trying to come up with jmeter setup in which i want to read entire csv file that has 200000 rows and i want iterate through each rows creating new thread since i am using JSR223 pre-processor that requires new thread for removing empty parameters from the request body. For some reason when i use while loop then only first test passes and rest of the tests fails as JSR223 pre-processor keeps on reading previous thread. I have also un-checked cached compiled script if available but still no luck. I also want to add that when i explicitly specify the number of threads as 100 out of 200000 then all of my 100 test passes as it reads new thread each time. Below is the screenshot of my set up:
This Fails -
This Passes -
JSR223 Pre-Processor Script that i am using:
def request = new groovy.json.JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue())
def newRequest = evaluate(request.inspect())
request.body.each { entry ->
if (entry.getValue().equals('')) {
newRequest.body.remove(entry.getKey())
}
}
sampler.getArguments().removeAllArguments()
sampler.addNonEncodedArgument('', new groovy.json.JsonBuilder(newRequest).toPrettyString(), '')
sampler.setPostBodyRaw(true)
Console log when using while controller
Replace this :
sampler.getArguments().removeAllArguments()
By:
def arguments = new org.apache.jmeter.config.Arguments();
sampler.setArguments(arguments);
If you're looking to learn jmeter correctly, this book will help you.
It is not possible to provide a comprehensive answer without seeing:
Your While Controller condition stanza
First 3 lines of your CSV file
Your CSV Data Set Config setup
Your HTTP Request sampler parameters or body
Double check the following:
Compare HTTP Request sampler body for 1st and 2nd requests under the While Controller
JMeter Variables originating from the CSV Data Set Config (you can inspect them using Debug Sampler and View Results Tree listener combination)
Enable debug logging for the While Controller, it might be the case it is not doing what you expect, it can be done by adding the next line to log4j2.xml file:
<Logger name="org.apache.jmeter.control.WhileController" level="debug" />

Invoking Transaction controller or HTTP sampler from Bean shell/JSR223

Problem statement.
Set of transactions(1000+) and need to call or reuse(without duplicating in different if/switch controllers) by invoking from the Beanshell or JSR233.
In SoapUI we have groovy script option to break sequential execution and divert control to any request using the below command.
if( Math.random() > 0.5 )
testRunner.runTestStepByName( "Request 1")
else
testRunner.runTestStepByName( "Request 2")
// do something else
....
Same functionality available in Loadrunner(Run time setting with different action) and neoload too.
Do we have any built-in objects or function to execute by transaction or Sampler name from JSR223/BeanShell without using if/while/switch controller ?
For Example:
In script 10 transactions are there and to use same script for different scenario by setting a JMeter property during execution through Jenkins or command prompt .
__P(Flow,RoomBooking)
Then from JSR233 /beanshell sampler
if(Flow=="RoomBooking"){
invoke Login
invoke BookRoom
invoke Logout
} else if(Flow=="RoomBookingNBookItinerary")
invoke Login
invoke BookRoom
invoke BookItinerary
invoke Logout
}else if(Flow=="RoomBookingNcancel")
invoke Login
invoke BookRoom
Invoke ParkTicket
invoke CancelRoom
invoke Logout
}Like different flows with different thread and throughput
In this case I can mix and match different flows and and reuse same script for different flow.
This would help to reduce script rework effort during application changes.
You are right, JMeter doesn't have JSR 223 Logic Controller at all,
I think that it can help changing also the if controller,
I suggest you open an enhancement to JMeter product (choose Severity: enhancement)
EDIT
There's a new Bug 61711 - Add JSR223 Logic Controller you can vote on.
If you are looking for a way to execute a previous sampler one more time from the JSR223 Script it would be something like:
ctx.getPreviousSampler().sample(null)
where ctx stands for JMeterContext for all available methods and fields.
Demo:
However a better idea would be using JMeter's Module Controller which allows executing a part of JMeter test plan somewhere else, this way you can implement a form of goto statement in JMeter
You can possibly do it with Switch Controller
Any step will be a Transaction Controller
And in a JSR223 Sampler you'll set which step you want:

Jmeter : While controller counter does not allow threads to exit if condition not met

I have put a condition in While controller: ${__javaScript("${status5}" != "SUCCESS" && parseInt("${counter}") < 5,)} and put the counter in while controller. Also enabled the track the counter independently for each user and reset the counter for each thread group iteration.
Once HTTP sampler is called, i have added Beanshell postprocessor to capture the response value in a file.
While running test for 100 threads and 10 iteration, some of the threads fails and retries till 5 times for a iteration but then does progress further. Looks like it is checking only for 1st iteration and then not able to move to next iteration. I dont see any error on the jemter.log or outofmemory but it just hangs there.
Can you please help me why threads are not progressing? Is something wrong in my validation? or in while controller?
You don't need the parseInt() function here, JavaScript is type agnostic so I would recommend changing your condition line to the following:
${__javaScript(("${status5}" != "SUCCESS" && ${counter} < 5),)}
See Using the While Controller in JMeter article for more information on conditional looping in JMeter tests.

Resources