Jmeter-While controller is not exiting from loop - jmeter

I have JDBC request which has modified_date which will populate with value depends on payload size. For small payload it will populate the date and time value immediately, for large size it will take from 10 to 30 minutes.
I have added JSSR223 post processor for JDBC request and i am capturing the modified_date and saving in variable "modified". I have added while controller with ${__javaScript(vars.get("Modified"))=="null"} and added same JDBC request with constant timer.
So the while controller keeps looping and it is not stopping or exiting after the value is populated for modified_date. Can you please help.

As per documentation
Variables, functions (and properties) are all case-sensitive.
So Modified and modified are different beasts, you need to mind the case and change the While Controller's condition to ${__javaScript(vars.get("Modified"))=="null"}
Also you don't need any scripting in order to save JDBC Request sampler result into a variable, just define it under "Variable names" section:
and given your query returns a single result you will have it in ${modified_1} JMeter Variable.
More information: Debugging JDBC Sampler Results in JMeter

Related

How to update the array values from existing based on the condition and again pass same array with updated array element

We are using for each control to iterate an array based on matchNr count. First time My application is sending all reports call to server together , next time after 10 sec delay again my application sending the same reports calls which are not get completed in first time and so on.
Ex. suppose application is having 10 reports then first time 10 requests goes, then again same request goes by eliminating the completed one (this request count should be less or equal to earlier one)
Note:
Application is having different report count for each users. we can not put fix reports to all users.
Request is same here, only application is adding report name in the body part of the request.
We are trying to simulate chrome behavior with Jmeter during load test.
Array is having the total report count[image1]
request is same only parameter is getting change for each request[image2]
ForEach Controller doesn't execute its children "together"
We are not telepathic enough to guess how does you "array" look like and how exactly you want to "update" it
If you have JMeter Variables in form of:
foo_1=something
foo_2=something else
....
foo_matchNr=number of matches
and want to update the variables with some "new" values there are 2 options:
Set Variables Action sampler (can be installed using JMeter Plugins Manager)
Or any suitable JSR223 Test Element, any of them has vars shorthand for JMeterVariables class instance providing read/write capabilities for JMeter Variables in current thread's scope.

Jmeter - How to stop While Controller once getting the expected values from Data Base?

I am trying to run the performance script which has API which takes the payload as file from S3 and submit to target system. After the request is completed I need to login to db and verify the status of the transaction. Here there is delay in getting inserted to db which is fast for payload with small file size. As I started submitting large files 1 GB to 15 GB, there will be delay in inserting a table.
So the JDBC request which has modified_date will be "null" and Status will be "null" for large payload when request is new. I have used constant timer but not sure how long it takes to insert in table. Is there any way I can make jdbc request to wait till i get result for modified_date will be "2021-02-10 18:17:44.538" and status will be "message deliver" for message table.
1)How to make loop keep on running till both the values inserting in the message table ?
2)How to stop while controller once I getting the expected values for modified_date and status ?
While Controller is being executed until the condition is met
You can combine more than one condition if the function allows it, the most powerful is probably __groovy()
Example condition:
${__groovy((vars.get('Status') != 'message deliver' || vars.get('modified_date') == 'null'),)}
Demo:
In the above example vars stands for JMeterVariables class intance which provides read/write access to all JMeter Variables in current context. See the JavaDoc for all available functions. You might also be interested in Top 8 JMeter Java Classes You Should Be Using with Groovy article which provides more information on JMeter API shortcuts available to JSR223 Test Elements and __groovy() function

Need to add unique value every time when run the POST api request in jmeter

Need to add unique value every time/always when run the POST api request in jmeter. I have API which is POST request, this request added 'roleId' which should be unique every time (should not use the id which was already created). I have tried below options but response says duplicate id.
1. Add http request with POST body> add 'Counter' to this request with min: 25 and max: 50 with increment:1
When run the request it always starts with '25' and it fails from the second run as it says duplicate value because in the first run this id has been inserted in table
2. User defined variables: used __Random function but for this also same issue.
3. CSV data set config: same issue.
Please suggest what would be the best approach to solve the issue.
__UUID function can generate a GUID structure which is pretty much unique, something like: 9e73f1a6-c1dc-44f7-b73a-508871f98b83
__time() function can generate current timestamp in milliseconds from the start of the Unix epoch, something like 1492417676453 (it won't help if you have > 1 request in millisecond)
__threadNum() function returns current virtual user number
__iterationNum() function (available via JMeter Plugins) returns current loop number (thread group level)
__counter() function which generates an incremented value each time it's being called
You can use any combination of the above in order to generate your roleId, if you have doubts let us know the criteria so we could come up with the best solution. In the meantime check out Apache JMeter Functions - An Introduction article series to get the overall idea about using Functions in JMeter tests.

How to attach labels (from user defined variables) to jmeter response data?

I want to compare results of two sql queries of the following type
select count(*) from X where userid='${userid}'
where X is some subquery (different in both actual queries).
I want to check whether both of these queries return the same resultset using jmeter.
Hence, I created two jdbc requests in the thread group, and I supply the userids through a set of 50 userids stored in a csv file. All this works fine.
The core problem is that I have two samplers in a thread group, and I want to compare their results. I came across a similar question, which suggests to use a post-processor to store the response into a file.
However, being a newbie in JMeter, I could only manage to create 2 post-processors (1 for each request ) which write "prev.getResponseDataAsString()" to different files.
I get the following output, in one of the files
1
0
1
0
1
93583
1
42456
1
37033
1
37033
1
93583
It is clear from this result, that I have no idea which thread produced which result in the file, which brings me to my question.
How do I attach labels to jmeter response data?
There is a sampler called a "Debug Sampler"
And a counter config in your threads, so for each thread the count is incremented
If you add that debug sampler and change the title to "Debug printout Thread ${counterThread}"
Then that will show up in your view results tree
You can store result sets into a JMeter Variables and use i.e. Response Assertion or Beanshell Assertion to compare two variable values. Depending on response data type the approaches may differ.
Check out Debugging JDBC Sampler Results in JMeter article to learn how to work with JDBC test elements results, if anything remains unclear update your question with more details.

JMeter - Why is my variable being re-evaluated midway through my test?

I posted this question originally in a much more complicated way, but I've reproduced the issue more simply now so I'm extensively editing my post.
I have a simple Test Plan to exercise an API.
The first thing it does is create a session with a simple HTTP POST. We then extract the session ID from the response using the JSON Path Extractor plugin:
This reads the newly created session's ID into a variable called id_JSON, and subsequent PUT requests use the session ID in their path, i.e. /api/sessions/${id_JSON}/account.
This generally works well, but I have noticed that intermittently, id_JSON will suddenly have the default value NOT_FOUND. Samples will fail and when I look at the request, I can see that it was trying to hit /api/sessions/NOT_FOUND/account instead of a valid ID. What's really confusing me right now is that this will happen after requests have already successfully referenced ${id_JSON} and generated a valid path. It seems like this should be impossible, unless the value of id_JSON was being dynamically checked or looked up repeatedly - otherwise how is it coming up with a different value from one request to the next?
It seems that if any Sample fails, for any reason, subsequent requests in the same thread iteration all fail with id_JSON having the default value NOT_FOUND.
Do I need to declare or manage the variable id_JSON in any special way to ensure that it will get the value of the session ID and retain it throughout the thread iteration, until the next iteration overwrites it with the next session ID?
The Extractor is a Post Processor, meaning it is applied after each sampler. So in you case it will run on the First Get and the 4 Puts.
So what you are noticing is absolutely regular, and if a Sampler fails, the extractor will fail to extract the ID and put NOT_FOUND in value.
If you are sure it does not change, then just put the Post Processor as a child of the first HTTP Request called "Create Session", it will then only run for it and the variable will not change anymore.
You can read more on this at:
http://jmeter.apache.org/usermanual/test_plan.html#scoping_rules
"Go to next loop iteration" operates on Thread Group level.
Using any nested loop controllers doesn't increment global iteration counter. You can test it with either:
${__BeanShell(vars.getIteration();)} function - if you use vanilla JMeter
iterationNum function - if you use JMeter Plugins
So if you move your "looping" on Thread Group level and remove nester Loop Controller(s) (or set their loop count to 1) your approach should work as you expect it to do.

Resources