Failed thread should not pick same data from CSV file, already read by thread in queue - jmeter

Precondition:
Threads: 5, Loop Count:5
CSV config file contains: IP address and Mac address
Scenario:
When Thread execution starts, 5 threads reads values of IP address and Mac address from CSV file.
T3 fails in execution and looping of threads starts, it picks Ist ip and ist mac address from CSV and that is already picked by ist threads and is in queue(Completing end to end flow).
How to handle like all the threads in queue should have picked unique row from CSV file?

As of JMeter 5.1 none of the test elements and JMeter Functions suitable for parameterization provides the behavior you're looking for.
You can use __groovy() function to script the CSV file reading in the way you want, for example you cat configure 1st virtual user to read 1st row, 2nd user - 2nd row, etc.
The relevant Groovy code would be something like:
${__groovy(new File('test.csv').readLines().get(ctx.getThreadNum()).split('\,')[0],)} - gets the value from 1st column
${__groovy(new File('test.csv').readLines().get(ctx.getThreadNum()).split('\,')[1],)} - gets the value from 2nd column
Demo:

Related

Forcing thread to take a particular value from CSV and does not change till the test is completed

I have CSV file which contains Mobile Number, for e.g. number.csv
1276543281
1276543282
1276543283
1276543284
1276543285
Configured CSV Data Set Config with following options
Recycle on EOF? : True
Stop Thread on EOF? : False
Sharing Mode: All Threads
Thread Group settings are given below:
Number of Threads: 5
Ramp-up: 1
Loop Count: 10
Now, when I execute it, threads take any number from CSV and on next iterations based on the thread completion takes the value from CSV.
I want to force Thread1 to take 1st row, Thread2 to take 2nd row and so on... till the loop count is reached or the duration is reached.
You won't be able to achieve the described behaviour using CSV Data Set Config, with the above configuration each thread will pick up the next value on each iteration.
There is no guarantee that 1st thread will pick 1st line and 2nd thread 2nd line.
If you want to "stick" each thread to the respective line from CSV you should use __groovy() function instead like:
${__groovy(new File('/path/to/your/number.csv').readLines().get(ctx.getThreadNum()),)}
where ctx stands for JMeterContext class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information.
you can achieve this solution by two ways
You can achieve by keeping the CSV dataset config only once in the controller
You can achieve by using Baolu CSV Data Set Config, in your scenario, set block size for each threads as 1
In these two scenarios, the value picked in first iteration those same values would be picking in next iterations.

JMeter - How to execute multiple CSV Data Sets

I have two CSV files, test1.csv and test2.csv. These two tests are slightly different, but I want to test them through the same test plan and report on them together. Therefore, I thought I would create two test fragments.
I have a thread group called 10 Concurrent Users because it's a thread group that will have 10 threads. I want this thread group to first run the Test 1 Test Fragment and then Test 2 Test Fragment. I want each test fragment to end after the corresponding CSV file reaches EOF.
I understand I can set Stop thread on EOF to true, but I don't want to stop the thread. I just want to "end" this test fragment. How do I do this?
This is what my Thread Group looks like. I don't want it to run infinitely, and I don't want to hard code the number of iterations.
One way I found was to just have two separate thread groups. One thread group for the first CSV file and one thread group for the second CSV file. Set the Thread Groups to "Infinite" and have "Stop Thread on EOF" set to true for each Data Set Module. However, it would be nice to not have to have separate thread groups as they are just duplicates of each other
In same thread group define a While Controller per CSV Data Set Config
Define in While's condition the value you get from CSV
Define an while controller with the Condition as ${url}
And don't recycle list on EOF:
To stop execution after the end of the CSV file is reached: within the CSV Data Set Config set Recycle on EOF? = False and Stop thread on EOF? = True.
If you want to iterate all the values in the CSV file and then continue you can configure the CSV Data Set Config like:
and put your Sampler(s) under the While Controller using the following __jexl3() function as the condition:
${__jexl3("${myVar}" != "<EOF>",)}
Another option is putting the logic under the Loop Controller, the number of lines in the CSV file can be determined dynamically using the following __groovy() function
${__groovy(new File('/path/to/your/file.csv').readLines().size(),)}

JMETER nested while loop is stopping at first line of the CSV data file

I have to make a GET call on IDs stored in a CSV while and I have to retry on GET call till it returns 200 response code.
This is what my current structure looks like ..
GET thread group
Once only controller to grab authentication for each thread
While Controller with condition "${__javaScript("${index}"!="<"EOF">")}" to check for end of the CSV
file
CSV data config file (Each file is unique for each thread) , variable name is "index", Recycle on
EOF - False, Stop thread on EOF - True,
sharing mode - current thread
While Controller with condition "${__javaScript(parseInt(vars.get("Response_code"))!=201)}"
User defined variables - Response_code
Http GET request
JSR233 post processor - "vars.put("Response_code",prev.getResponseCode());"
JSR223 post-processor - To write ID returned in successful call to another CSV file
Now I am not getting error or anything .. but I was expecting first while controller to loop through CSV file for each id, then make a GET request for each id and then second while loop would wait for success code but for some reason, GET call is only executing for the first entry in the csv and then exit out of it. What am I missing here?
CSV data config file (Each file is unique for each thread)
this is not how it works, the CSV Data Set Config is being initialized once with the filename resolved at the time of its execution, it doesn't load the new CSV file for each virtual user.
If you're looking for an option of supplying the CSV file name(s) dynamically in the runtime - consider switching to __CSVRead() function. See How to Pick Different CSV Files at JMeter Runtime article for more details.

Execute csv rows, one by one, on all threads

My Test plan has a csv dataset config element, a thread group with a http sampler.
I would like to read first element from csv, run it using 20 threads for 50 iterations, then repeat this sequential process for all the 30 rows of my csv.
I have set the toggle for stop on eof to true.
Most solutions,I have gone through on Stack Overflow, andother blogs, for a suitable solution, suggest adding a loop controller or a while loop, reading the rows using a preprocessor and looping, however, in these cases, I am not able to achieve my objective.
TestPlan
-- User Defined Variables
-- HTTP Request Defaults
-- HTTP Header Manager
-- JSR223 PreProcessor (To get the CSV line count)
-- CSV Data Set Config (Recycle on EOF - False, Stop on EOF - True)
-- Thread Group
-- HTTP Sampler (GET,pass each of the csv dataset element as part of path)
-- View Result Tree
With the above setup, I see that the whole csv is iterated, I inlcuded a loop controller, with loop count, moved the HTTP sampler, under it.
However, when I do this, I was unable to get the usage of Iterations in thread-group.
Article References:
Use same row per thread from a CSV data set in JMeter
How to read each and every row of csv by single user in JMeter?
How to loop each thread with unique data from CSV Data Config file
JMeter - multiple user taking unique row from CSV file
Your requirement is too "exotic", I would recommend creating a new CSV file out of your existing one with:
1st line repeated 100 times (20 threads x 50 iterations)
2nd line repeated 100 times
3rd line repeated 100 times
...
30th line repeated 100 times
If you have problems generating the file you can do this in the runtime, like:
Add setUp Thread Group with 1 thread and 1 loop to your test plan
Add JSR223 Sampler to the Thread Group
Put the following code into "Script" area:
SampleResult.setIgnore()
def generated = new File('/path/to/new/csv/file')
generated.delete()
new File('/path/to/old/csv/file').readLines().each { line ->
1.upto(100, {
generated << line << System.getProperty('line.separator')
})
}
In main Thread Group use CSV Data Set Config "normally", just point it to use the /path/to/new/csv/file
See The Groovy Templates Cheat Sheet for JMeter for more examples of useful Groovy code snippets which you can use to enhance your JMeter tests.

how to use separate csv file for each thread

My scenario is like,
1. Login by multiple users (100 users)
2. Select 50 items by id's specific to user
I have placed id's for each user in separate csv file say user1.csv, user2.csv, user3.csv and so on.
My result should be like Thread 1 should take user1.csv and process all 50 id's in loop controller.
Thread 2 should take user2.csv and so on.
I tried with below example, but still couldn't find the solution.
Eg. I used file path as C:\abc\user${_threadNum}.csv
Or
C:\abc\user${_threadNum}.csv
Variable name in csv file is user_id
Requeat will look like /home/abc/${user_id}
I want thread 1 to use the user1.csv file and substitiue the value of user_id in the request and thread 2 should use user2.csv and so on.
If I execute my above plan, I am getting error as /home/abc/EOF
How is this possible in JMeter? Or any other approach?
Please provide solution with an example, since I am new to JMeter.
Create your files like comman_name_1,comman_name_2,comman_name_3
etc. & select current thread option from dropdown list present in csv data config set.This will allow threads to use different files per thread or put values in a single file and select current thread option.
It's easy, just add CSV Data Set Config to each thread (user1.csv for thread1 and so forth). Configure CSV Data Set config, and select one of this values in Sharing mode field:
Current thread group - each file is opened once for each thread group
in which the element appears
Current thread - each file is opened separately for each thread
UPD: I have done it right now, it works
Script looks like this:
I selected 'Current thread' in each CSV Data Set Config
I was making the mistake of using single underscore in fetching the count of thread.
We need to use double - underscore like this : ${__threadNum}
Note :

Resources