I am facing a situation currently, where I have 2 threads inside 1 thread group. Both the threads use different csv's. For this I've put 1 CSV Data Set Config in each thread. Problem is there is a variable called userId which is common in the Variable Names in csv data set config for both. Due to this when the first thread executes it assigns the userId a value which is then carried forward to another thread.
For example,
Thread1 >> reads values from csv >> assigns userId=1104.
Thread2 >> reads values from csv >> cannot assign userId=1105 but keeps the previous assigned value userId=1104.
I've tried sharing mode as Current Thread but doesn't seems to work in this case.
Please suggest a way out.
If you have two CSV Data Sets, with the same variable names, at the same level in the Test Plan Tree, you will see the behaviour you describe. If they both have a variable called var1, for example, it will have the same value throughout the level.
You can use the Simple Controller element, so that each CSV Data Set Config is on its own level, and the variable values are not shared.
Simple Controller has no logic, other than grouping other elements together, so all you need to do is create two, and move the other elements beneath it.
BROKEN
WORKS
Related
Please tell me, is it possible to read data into Jmeter from a dynamically changing file? I have a file with parameters, which will be appended during the test itself. Is it possible to somehow define a global counter that will allow each thread to read its own line every iteration? User Defined Variables are reset every iteration as i understood.
In theory, I can read a specific line using File.readLines().get(counter) in JSR223 Sampler but problem is how to define correctly this counter.
I believe __counter() function is what you're looking for. If you invoke it like ${__counter(FALSE,)} it will return an incremented value each time it will be called.
Example usage:
More information: How to Use a Counter in a JMeter Test
Using jMeter to set up a soak / load test that needs to run each request with different data. The structure I currently have is
Thread Group (2 Users, 2 Loops)
- Simple controller
-- Java Sampler (Custom Plugin) to convert CSV Formula data into NewThreadData.csv (as variable)
-- Java Sampler (Custom Plugin) to create directory of files created with NewThreadData.csv merged into a template
-- While Controller Condition - js NewThreadData column not = EOF
--- CSV Data Set Config NewThreadData.csv (Recycle False / Stop of EOF False) - filename passed as variable
--- JMS PUblisher with the FileName a variable using the filename column from within NewThreadData.csv
My problem is the on the second loop, the data is updated in NewThreadData.csv, but the CSV in the while loop never runs again.
Appears that the CSV Data Set Config "knows" it has been run, regardless of the actual CSV data.
Questions
How can I get the CSV Data Set Config to be rerun / re executed in this scenario?
Are there undocumented variables or means of getting the config to reprocess?
Is there a way to spawn a new thread on each iteration rather than reusing the existing thread, as the CSV does execute once for each "User"[thread]. I also tried Stop on EOF : True, but that stopped the second loop.
Aim is to eventually ramp up the user count and the number of loops (changing to forever); with there being about about 100 different combinations of data to be inserted on each loop. The formula I am using has time and thread number to give me data uniqueness along with other data that is dynamically created from a formula. Recycle on EOF is not feasible as I need to regenerate the csv contents on each loop. A super-csv I don't think is feasible to cover the load and soak scenarios.
Thanks in anticipation. Andrew
I don't think it's possible to "reset" the CSV Data Set Config, it's a configuration element hence once it reads the file in its current state it will "stick" to its content.
If you're manipulating file content dynamically I would rather recommend going for __CSVRead() function instead which is evaluated in the runtime just where it's placed therefore it doesn't reserve file and it "rewinds" to the beginning of the file when the last line is read.
More information: How to Pick Different CSV Files at JMeter Runtime
CSV Data Set Config element is executed first and only once even though you have placed it within the while controller. Hence CSV Data Set Config element is not suitable for your requirement.
You could use JSSR223 Pre-processor to work with the dynamic CSV files using a supported programming language/script (Java , Groovy)
I currently have a test plan where I use a random variable to submit a post request to a given URL (/app/${app_id}).
I want to also re-use the random variable app_id to poll the status of that app (/app/${app_id}/status). Note there would be multiple requests to the status URL.
My current idea is to:
have one thread group that submits the posts
save a list of the randomly generated app_ids
in another thread group, read the list of app_ids and for each app_id, loop the status request
Is this a sensible approach? If so, how can I go about saving the randomly generated app_ids and then reading them?
Also, if there is a better approach to this situation, I'm all ears :)
You can pass the values from one thread group to another one using __setProperty() function like:
${__setProperty(appid-${__counter(FALSE)},${your_variable_holding_appid},)}
Each time the function will be called it will generate a JMeter Property in form of
appid-1=foo
appid-2=bar
appid-3=baz
etc.
Where numbers like 1, 2, etc. are coming from __counter() function
In another Thread Group you will be able to access the generated values using __P() function like:
${__P(appid-${__counter(FALSE)},)}
Demo:
See Apache JMeter Functions - An Introduction for more information on JMeter Functions concept.
There is more "advanced" way of passing JMeter variables between threads and even thread groups, moreover you will be able to synchronise your threads, i.e. don't start thread in 2nd thread group until variable is not set using Inter-Thread Communication plugin.
Solution with Thread Groups is feasible, although you also can do all that in one thread group, by configuring one of the threads to be "monitor", while remaining threads submit posts. Something like this:
Thread Group
If [${__threadNum} == 1]
Samplers to check status
If [${__threadNum} != 1]
Samplers to submit posts
One reason to use 1 thread group for both types of users is if you need any sort of synchronization between writing and reading app_id list - that is easier to achieve in one thread group. Or if you already have many thread groups.
As for providing app_id to various threads/thread groups, you can use one of the approaches:
To pass IDs from one thread group to the other without a file, you can use one of the methods described here (using properties is the most popular way).
In your case, probably the easiest is to save them in one property with some delimiter, e.g. ID1,ID2,.... The "status" thread then can get this property, split it using either script or __split function to convert property into serialized variables: app_id_1, app_id_2, etc. Those variables are a natural choice for ForEach Controller.
Also first thread group could be saving app_ids into file, while the other reads from the same file with CSV Data Set Config. A bit of caution here though, if they are doing it at the same time.
If app-ids can be pre-generated, a more economical approach would be to have SetUp Thread, which generates them and saves them to CSV file (you will only need one script, e.g. BeanShell to do that, see example here). And then both thread groups read from that file using CSV Data Set Config
I am new to JMeter and it maybe a stupid question but I still find it hard to understand the concept here.
I have a simple test.
Thread Group with a Single thread with loop count of 2
PreProcessor that place two
variables on the vars map
A loop that execute a request twice based
on the PreProcessor parameters
I expected that the preprocessor will initialize the parameter and it will use the same values twice in the request.
It looks like it’s executing the PreProcessor once pair call.
When I switch the PreProcessor with similar User Defined Variables it reuses the same value on every call.
Can anyone explain the logic here?
I am using JMeter 2.11
A PreProcessor is executed each time the HTTP Request is executed so if you have a total of 2 iterations, you should see log twice, you have it 4 times so maybe number of iteration is different than what your write or you have 2 threads.
When you use User Defined Variables, the value is computed once and then reused. Value will be different per thread.
After reading the documentations and with #UBIK LOAD PACK help I used User Variables and it worked
User Variables - are specific to individual threads.
Pre-Processor is attached to a Sampler element (e.g. http request in our case), then it will execute just prior to that sampler element running
So 4 request for different parameters because it runs before every request
User Defined Variables - It is processed at the start of a test, no matter where it is placed. For simplicity, it is suggested that the element is placed only at the start of a Thread Group. This is why I get the same value all the time
Hi merged two thread groups in to single test plan and have two User defined variable element for them
In both User defined variables I have a variable called rubyUrl which has different value in each thread group
when I execute the test plan together I am facing Issues because of the variable name conflict between
two different thread groups
please help me how can I tell Jmeter that It should pick the variable from which thread group
Your finding is correct but the reason behind it is different.
User defined variables (a config element) are initialized and processed as soon as the test is started i.e. if you have three different User defined variables elements with same variable name but different values in three different thread groups then even before the thread groups are executed all the user defined variables are initialized hence the last processed value will only be retained.
On the other hand if you use a user parameters element (a pre-processor) it is initialized and processed just before that thread is executed. So if you have three different User defined variables elements with same variable name but different values in three different thread groups then each time the thread group is executed the value is processed.
!!!!!!!!!!Eureka Found solution for this Problem!!!!!!!!!
we can go for an Pre-processor in Jmeter like User-parameter
since User Parameter is individual to single thread group unlike User defined variable which is common to a test plan
Add variables with the same name in the user defined vaiables and add it in each thread group.
Is there any other better way to do this thing,as always in java one thing better than other comes our way :)