missing items in jmeter result tree - jmeter

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.

Related

How to loop a sampler in a thread group in Jmeter until a specific response value is returned

I have to performance test an application which does a PDF to PNG image conversion. For that, I have 3 requests to be sent, ie, 1 POST and 2 GET requests. My requirement is to measure the performance of one the GET request which does the conversion part and downloads the converted PNG file. Note that this GET request that download the image is dependent on the other POST and the GET request which checks the status of the job. The full work flow in a nutshell is as follows:
Send a POST request to trigger a job to generate a unique identifier string.
Using the string value generated in step 1 above, the GET request checks the status of creation of a PDF document. Since this process has dependencies, the GET request polls until a status of 'Complete' is returned in its response. If the response status is not 'Complete', then we have to retry this GET request.
And finally, once the response from step 2 is returned as 'Complete', the GET request to convert the generated PDF to PNG image has to be triggered.
So 3 requests above are dependent to each other and has to run sequentially as the input for one is the output of the previous request. So we have to run this in the same order (1__> 2 --> 3) for the entire duration of the performance test.
I have tried using the While controller, however, the issue I am facing is, the sampler inside the While controller (ie GET request in step 2 which checks the status) is getting executed only for a limited number of times and not for the entire test duration.
The jmx file I have created is as follows:
Test Plan{
Thread Group{
POST Request sampler{ //step 1
//stores unique string response to variable
}
User Defined variable (initialize a Status variable to null string, initialize a counter variable)
While Controller(condition '${__javaScript("${Status}" == "" && (${counter} < 4),)}')
{
GET Request Sampler { //step 2
Regular expression extractor to get the status from response and store to variable
}
JSR223 Post processor { //to check if the status value = 'Complete', otherwise set status back to null string
/*
String status = vars.get("labelStatus")
if(status.equals("Complete")){
log.info("Label Status is Complete");
}
else{
vars.put("labelStatus","")
}
*/
}//end of JSR223 post processor
}//end of while loop
GET Request sampler to download the PNG image //step 3
} // end of Thread Group
}//end of Test Plan
screenshot of my Jmeter script:
Ideally for each POST request I make (step 1), there should be a corresponding GET request (step 2) which checks for a particular status in response. If the response contains the matching text, then have to exit the while loop and continue with the next sampler (ie GET request in step 3 above) in the thread group. This needs to be repeated in each iteration.
As per your While Controller condition its children will be executed while ${Status} variable is empty or 4 times, whatever comes the first.
I fail to see where do you update the value of the ${Status} variable, it might be the case you made a typo and need to change it to ${labelStatus}?
I would recommend using Debug Sampler and View Results Tree listener combination in order to check the values of ${labelStatus} and ${counter} variables for each While Controller's iteration
Also pay attention to JMeter Scoping Rules as your last JSR223 PostProcessor is being executed after every sampler in the Thread Group and this is something you might want to change.

Jmeter- how to break while controller after getting successful repsonse

I am seeking help on how to break while controller loop when I got successful response.
Steps:-
1. I have a while controller where I kept below logic
${__javaScript((${controller} < 5),)}
2. And inside while controller I have created http request which return response.
This request takes some time to give result.if this request is still
running it will return status code 202.. and if this request is completed it will give 200.(I have another API to check this)
So here I dont know when it will get success.
for that after each request I have kept waiting time.
So when I call first time after while loop.. its giving 202(because its still running)
and I will continue this process till 5 times..
So here there is chance I can get 200 success code at 3rd request.
So what I want here is I would like to break the loop after that..I dont want to run till 5 times.
I am using below code to read the response.
if (status_code == "200"){
AssertionResult.setFailure(false);
}
So when I get the 200 from response it should stop and get success
and if I dont get 200 from response in all 5 attempts, it should get failed.
Add Regular Expression Extractor as a child of the API request and configure it as follows:
this will extract the API HTTP Status code and store it into ${responseCode} variable
Amend your While Controller's Condition to use the following __jexl3() function
${__jexl3(${__jm__While Controller__idx} < 5 && "${responseCode}" != "200",)}
That's it, assuming above setup your While Controller will break in 2 cases:
Response code is 200
API request is executed 5 times
More information: Using the While Controller in JMeter

Loop delays for http request in 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

How do I resend a sampler upon a failed assertion on JMeter?

I am designing a load test in JMeter.
With the current application that we have whenever a HTTP request is sent, the web server will very occasionally send back a page with a message. To get around this we just have to reload the page. This page could come up for literally any HTTP request.
Is there any way to design a test in JMeter where when a sampler fails, the sampler simply retries?
I'm not sure how I can get a Beanshell sampler to resend a HTTP request.
It is possible via additional Beanshell Assertion
You can re-run arbitrary sampler from the Beanshell Assertion as simple as
ctx.getCurrentSampler().sample(null);
Add a Beanshell Assertion after all other assertions. It matters as assertions are being executed upside-down.
Put the following code into Beanshell Assertion's "Script" area (just change "message" to what your server returns on error.
import org.apache.jmeter.samplers.SampleResult;
if (new String(ResponseData).equals("message")) {
SampleResult result = ctx.getCurrentSampler().sample(null);
if (result.getResponseDataAsString().equals("message")) {
Failure = true;
} else {
SampleResult.setSuccessful(true);
}
}
You'll have only one result recorded.
If assertion passes 1st time - it'll be successful
If assertion fails 1st time and passes 2nd time - it'll be successful
If assertion fails 2 times - it'll be recorded as failed.
For extended information on Beanshell scripting check out How to use BeanShell: JMeter's favorite built-in component guide.
Create such hierarchy:
Thread Group (1 user, 1 second ramp-up, forever)
-While Controller (empty condition = forever)
--Counter (start – 1, increment – 1, reference name – counter)
--HTTP request
---Timer (I prefer constant Timer, responseble for pause betwee retrying)
---BeanShell Post Processor
BeanShell Post Processor should contains(pseudo code):
if(Integer.parseInt(vars.get("counter")>5)
{
prev.setSuccessful(false);
prev.setStopTestNow(true);
}
if(successCondition)
{
prev.setStopTest(true);
}
There is no direct way to achieve it, but I think you can use While controller in conjuction with Regex extractor to resend the failed requests.
Logical flow could be,
1. HTTP request
2. Regex extractor post processor - check response contains failure extract value in msg variable, default is success
3. While controller - run till msg=failure, default value of msg is success
Example screenshot,
Let me know if this works.

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