JMeter - When not to use Once Only controller - jmeter

Once Only controller component finish with a strange warning:
Once Only controller under anything other than the Thread Group or a Loop Controller is not currently defined. Odd things may happen.
I check and it works in setup/tearDown Thread Group and other Controllers and it works fine and in other components (as Pre/Post processor/Config...) it can't be added.
What is the use case for this disturbing warning?

OnceOnlyController reacts to its parent loop and runs only if it's the first iteration.
It expects its parent to be a LoopController or a Thread Group which contains a Loop Controller but it now handles also other elements.
There used to be a bug which has been fixed:
https://bz.apache.org/bugzilla/show_bug.cgi?id=39509
I suspect the comment is now outdated, but if you can test more and possibly provide some Test plan testing all combinations it would help the project strengthen this part.
Note removed by:
http://svn.apache.org/viewvc?view=revision&revision=1813138

Related

Different between Critical Section Controller and Simple Controller in JMeter

Could you tell me the different between Critical Section Controller and Simple Controller in JMeter?
I don't understand about them clearly.
I created example but their results are same.
Simple Controller does nothing but group the samplers below it
lets you organize your Samplers and other Logic Controllers. Unlike other Logic Controllers, this controller provides no functionality beyond that of a storage device
While Critical Section Controller used to block threads executing in parallel
ensures that its children elements (samplers/controllers, etc.) will be executed by only one thread as a named lock will be taken before executing children of controller.
Note that it doesn't work on distributed testing
Critical Section Controller takes locks only within one JVM, so if using Distributed testing ensure your use case does not rely on all threads of all JVMs blocking.
If you work with one thread you won't notice the difference between controllers
Simple Controller is just a container, you can put Samplers as a child of it. It doesn't do anything at all, the only valid use case is using it in combination with Test Fragment and Module Controller when you want to avoid code duplication
Critical Section Controller ensures that its children are executed by only one thread at a time, it can be used a a global lock to avoid race conditions (for example concurrent writing to the same file by several threads or something like this)

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.

What is purpose to use setup threadgroup and teardown threagroup in Jmeter? Please explain same with example

What is purpose to use setup threadgroup and teardown threagroup in Jmeter? Please explain same with example.
I know why we use thread groups and also aware of fact that setup is for pre activities like creating user and monitoring purpose but not sure with an incident where can i use it. same with tear down.
It sounds like you have pretty much figured it out already, but let me give you a few examples of when I've used it.
setup:
Get a large data set from a database into a jmeter variable for use during the test.
Get and log the version number from the system under test:s version number.
Run a javascript to set jmeter properties based on more simple input parameters/properties. Lets say you want to configure the selection of target host a simple true/false value, but in your test you need to expand it to different strings, and you dont want to have logic spread out all over your test plan.
teardown:
Never used it, but I guess it is mainly useful for cleaning up your system (e.g. deleting users that were created during the test)
correct me as i'm probably wrong, but a setUp thread cannot be used to store variables for use on the test threads (that i can see). any variables that i use in the setUp are never available. however, i found that if i use a beanshell and convert the variable in the setUp thread to a property like this
${__setProperty(userToken, ${userToken})};
then on each test thread i either use the property directly like:
${__property(userToken)}
or at the top of my thread i convert the property back into a variable like:
vars.put("userToken","${__property(userToken)}")
however, this seems a bit long winded and it would be great if there was a way to set up variables in the setUP to be used on every thread.
A special type of ThreadGroup that can be utilized to perform Pre-Test/ Post-Test Actions.The behavior of these threads is exactly like a normal Thread Group element.
The difference is that these type of threads execute before/after the test has finished executing its regular Thread Groups.enter image description here

Call function in user parameter definition

I'm running a set of thread groups (consecutively) and I need to reset a number of parameters at the start of each thread group so that they have a unique value.
Presently I'm referencing a User Paramaters node using a test fragment, and setting the value to value-${__time()}. Unfortunately, this results in the value being used verbatim (without resolving the time).
Is there a better way to achieve per-thread group variables that include function calls?
Works fine for me (Jmeter 2.5.1), as per below example.
Sample params set to ${__time(HMS,)} and value-${__time()} successfully resolved, generated and updated (once per iteration) for each thread (in this case:3 Thread Groups, 5 threads # 3 loops).
Can you please answer why are you using User Parameters via Test Fragment (as per your post)?
...And several articles, just fyi:
Parametrization in JMeter with user parameter
JMeter Variables vs. Properties. vs. Parameters
UPDATED:
Please find below results for example with both User Params and test logic put into Test Fragment and called from Module Controllers.
Works the same way as in sample above: successfully resolved, preserved between samplers in separate loop and updated (once per iteration) between loops for each thread (well, I 've commented in screen the rest of thread groups to get output for the first only; works fine with all TGs enabled too).
I think you could also try to put User Params config from Test Fragment to each thread group and leave in Test Fragment only test logic - if the above schema will still not work for you:
It's not very nice but both the Module Controller and Include Controller are still quite "buggy" and sometimes unpredictable.
You could also try to debug problem controllers in your scenario: select controller > click Help in jmeter's main menu > click Enable Debug > look into jmeter.log for details after execution.
You could also look onto custom Parameterized Controller - maybe it will work better.

Interleave controller Issue - JMeter

I am trying to simulate a sequential call to couple of webservices by putting them under Interleave controller. Although I have unchecked "ignore sub-controller blocks", jmeter still runs only one of the controllers living under interleave controller and alternates it for each iteration. What I need is a sequential call to all .
Any help is appreciated. Cheers
The Interleave Controller is running as it should do. It will alternate through one web service for each iteration
If you want a Sequential call to both web services on each request, then just put them directly under the Thread Group - without any logic controller or keep a Simple Controller
Unless I'm misunderstanding your question, why do you need the Interleave Controller?
Jose
Thanks for the answer. Keeping them directly under thread group did not call them sequentially. You can try it. I currently have about 10 webservices (let us call them 1..10) some are heavy and some are light there by resulting in different response times. However, I would like to run these in order that is from 1 to 10.
Directly placing them under thread group did not call them sequentially, so I used interleave controller with "ignore sub-controller blocks" unchecked.

Resources