Loop delays for http request in Jmeter - jmeter

I'm the newbie in Jmeter.I have the next task: X thread groups which send 2 different http request and the same http request with delaying 6sec. X> 50 000, Y> 100. I can`t find the solution for delaying Y http requests. Now, my test plan has the next look:
    
Thread Group (X)
     HTTP Request (1)
     HTTP Request (2)
     Loop Controller (Y times)
      -> Http Request
How can I solve my task? I would be grateful to everyone who can direct me to right way

Add a Constant Timer as a child of the last HTTP Request like:
Thread Group
HTTP Request (1)
HTTP Request (2)
Loop Controller
HTTP Request
Constant Timer
and set "Thread Delay" to 6000.
Be aware that you will not be able to see the "delay" anywhere as by default duration of PreProcessors, PostProcessors and Timers is not included into "Elapsed" time of the Sample Result (unless you use Transaction Controller in "Generate Parent Sample" mode and "Include duration of timer and pre-post processors in generated sample").
Constant Timer will pause each thread for 6 seconds before each Y HTTP Request.
If you need the pause to be after the request - add Test Action sampler after the Y HTTP Request
Thread Group
HTTP Request (1)
HTTP Request (2)
Loop Controller
HTTP Request
Test Action
and configure it to pause Current Thread for 6000 milliseconds

Anton,
The most appropriate solution would be to use Test Action element of JMeter with pause option set to 6000 ms.
This element needs to be placed before the 'HTTP Request' in your loop controller as mentioned below:
HTTP Request (1)
HTTP Request (2)
Loop Controller (Y times)
Test Action
Http Request
Here are few tips that can help you to optimize the JMeter test plan

Related

pass http request response to use in others http requests in same thread group

I'm new using JMeter and I have this case:
Test Plan
Test Group1
Http Request 1
Json Extractor1
BeanShell Assertion1
Http Request 2
Http Request 3
And I want to use the response of HTTP req 1(extracted in JSON extractor) in both HTTP request 2 and 3. For request 2 is working fine I just use ${response} and works fine but when I try to user the same variable in request 3 is like is empty is not showing anything.
So I tried to put the BeanShell Assertion and do a var.set or even a set property, but is still not working. It is like the var or property is being set, and I can see them in HTTP req 2 but in HTTP req 3 they are empty.
Is there another way to set the variable or the response of the request 1 to be use in any other requests of the same thread?
Thanks
You need to amend your test design and make the JSON Extractor a child of the Http Request 1
Test Plan
Test Group1
HTTP Request 1
JSON Extractor
HTTP Request 2
HTTP Request 3
If you have JSON Extractor at the same level as HTTP Requests 1-3 it's being executed after every of them so it tries to extract the value from HTTP Request 2 response, doesn't find it and the variable gets empty or default value.
The same applies to the Beanshell Assertion.
More information: JMeter Scoping Rules
With regards to using Beanshell in general it's not very recommended, since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language

missing items in jmeter result tree

here is structure of my test.
recording controller
transaction controller
homepage (transaction controller)
HTTP Request 1
Response Assertion (response code = 200)
HTTP Request 2
Response Assertion (response code = 200)
HTTP Request 3
Response Assertion (response code = 200)
....
login (transaction controller)
HTTP Request 1
Response Assertion (response code = 200)
....
logout (transaction controller)
HTTP Request 1
Response Assertion (response code = 200)
....
View Results Tree
Test is placed inside Ultimate Thread Group (up to 20 threads at once). I placed into each HTTP Request Response Assertion.
When run the the test and after that look in the result tree everything is green, so OK.
But when I clicked through result tree I recognised, that sometimes some items are
missing, but not every time.
see: for example:
transaction controller
homepage
login
(logout is missing !!!)
Question is why?
With Ultimate Thread Group you don't have fixed number of loops/iterations, so if you specify some "Hold load for" time span and a thread (virtual user) will be shut down "in the middle" of test execution, i.e. somewhere at homepage transaction - it will simply not be able to finish all the remaining requests.
Like
if you set Hold Load For to 1 second - only 1 request will be executed
if you set Hold Load For to 5 seconds - a couple of requests will be executed
if you set it to 5 minutes - most probably all the requests will be executed at least once, but the number of the requests will mostly depend on your application response time
So if you want the whole sequence to be executed - switch to "normal" Thread Group and specify the desired number of iterations
Also using JMeter GUI mode and View Results Tree listener for executing load tests is not the best idea, you should be running your JMeter tests in command-line non-GUI mode and use HTML Reporting Dashboard for results analysis.

Handling Asynchronous API Call in Jmeter

I am using Jmeter for functional Testing, below is a problem that I am facing and need some help/suggestion on how to overcome that.
I have a thread-group that consists of 2 requests, 1st is API call and 2nd is sending message to Active MQ.
Now the flow is that I need to do first the API call (this will wait for response), then send the message to a particular Active MQ queue and then only I will get the response for the API.
But since jmeter does sequential execution of requests, its get stuck at the API call waiting for the reply and never executes the second part.
I worked on the below solution but even that did not help.
1 Use a parallel controller and put both the API and ACtive MQ call under the same.
2 Add a Timer to the Active MQ call, so that it just did after the API call (2 Sec)
But when I checked in details I see that both the requests are sent at the same time and the timer does not come into effect anywhere.
Any way I can handle this scenario?
Please note I will get a response to the API only when I send message to the particular Active MQ Queue, else it will timeout in a minute.
Your Parallel Controller approach will work, however you need to amend the configuration a little bit, something like:
You could put your ActiveMQ Request under a different Thread Group and use Inter-Thread Communication Plugin for synchronization between threads
You can keep the current setup but replace the JMS Sampler with the JSR223 Sampler and send the message to ActiveMQ programmatically:
Textual code representation for your convenicence:
sleep(2000)
def connectionFactory = new org.apache.activemq.ActiveMQConnectionFactory('your activemq URL')
def connection = connectionFactory.createConnection()
connection.start()
def session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
def destination = session.createQueue('your queue name')
def producer = session.createProducer(destination)
def message = session.createTextMessage('your message body')
producer.send(message)
connection.close()
For your Problem statement, following design will work.
Use 2 Thread Groups, add API call to first Thread group and Message to Active MQ call to second Thread Group
Add a delay to second Thread Group so that it should not run before first Thread Group
Run Test Plan
Use while controller. It will keep on executing till the desired outcome then the next request will be executed.
Hope this helps.
Update:-
While Loop controller execute its samplers until the condition specified is not set to False. The condition can be any variable or function that eventually evaluates to the string 'false'.
So, you need to specify a variable or function in While Loop, that has value 'true' and becomes 'false' somewhere else in the script. Once it changes to 'false', JMeter will exit the While loop.
For example if you are using a X-Path extractor in your script which have a variable named Status and its value changes from 'Start' to 'Finish' during the execution and you want to execute your script till 'Finish' has not been met, then you can use the expression ${__javaScript("'${imp_Status}'!='finish'",)} in your While loop and it will execute the samplers under While controller till the status = finish is met.
It is sort of polling based on certain condition. In your first API reponse, consider one value to be appear as the condition upon which first api call is successful.
It sounds that you just need to define timeout for HTTP Request,
If you define Response Timeout as 60000 (milliseconds), and it will only wait for a minute and then continue to next request
Connect Timeout Connection Timeout. Number of milliseconds to wait for a connection to open. No
Response Timeout Response Timeout. Number of milliseconds to wait for a response. Note that this applies to each wait for a response. If the server response is sent in several chunks, the overall elapsed time may be longer than the timeout.

JMeter: Polling for a simple HTTP request

please could you give me an example on how to use a while loop to keep checking (polling) if my HTTP GET request (REST api call) has returned the successful response or not. Say for example, third attempt brings the successful response and I come out of the loop, How do I measure the time it has taken?
Please use While controller:
1) init counter JSR223 Sampler --> vars.put("counter","1");
2) while controller
3) inside while controller put your HTTP get
4) put a regex to retrieve what you are looking for (or JSON extractor)
5) Another JSR223 Assertion to check the result of what you retreived
if(!detail.equals("REGEX_FAILED")){
......
}
7) timer so you wait
8) increment counter

Is it possible execute some action on thread failure in Jmeter?

Let's say I have a Jmeter test which emulate some user login and several more actions. I also have 'start new thread on error' turned on. So in case some user fail - it will just get another user and keep processing the test for specified amount of time.
But I have some periodic calls for authorized user and to emulate them I'll need to use "Inter-Thread Communication" and additional thread group(-s). Basically this works fine in following way - in main thread I do login and fill some FIFO queue with required cookies, and obtain that cookie in another thread group. In that another thread group I do also check one more FIFO queue (that is filled on user logout), and stop that thread if get what I need.
The problem here is when main thread is fail after login. In that case child thread will be executed 'forever', since that periodic call keeps session active.
And the question - is there some possibility in Jmeter to execute some action on thread failure (smth like finally block). Basically I need fill that second FIFO queue either on logout or on thread failure
Add a Beanshell Assertion at the same level as all your requests go. It'll apply to each of the requests and in case of failure you'll be able to do what your need.
Something like:
Thread Group
Login Sampler
Some other Sampler
Some else Sampler
Beanshell Assertion
The example assertion code:
if (!SampleResult.isSuccessful()){
log.info("Test " + SampleResult.getSampleLabel() + " has failed");
// handle the error
}
See How to Use JMeter Assertions in 3 Easy Steps guide for more information on JMeter Assertions.
I also had to logout on sample error which needs something like try-catch-finally. An IF Controller with condition ${JMeterThread.last_sample_ok} and checked Evaluate for all children? as below, satisfied my need in a clean way:
TestPlan
HTTP Cookie Manager
HTTP Request Defaults
ThreadGroup - (continue on error)
HTTP Request - login
IfController - (Evaluate ${JMeterThread.last_sample_ok} for all children)
HTTP Request 1
HTTP Request 2
....
HTTP Request n
HTTP Request - logout (after and outside of IF)

Resources