In my Test Plan , i have multiple transactions(not related). Is there a way to stop just the current transaction only on a sampler error. If I use the setting to stop thread/ continue next thread , it just drops the thread for each transactions, which is not very helpful for what i want to achieve. Any help please. Thanks
What do you mean by "transaction"?
"Sample error" can be caught by If Controller using ${JMeterThread.last_sample_ok} pre-defined variable as the condition and from there you can:
Add Flow Control Action sampler and use one of below 3 actions:
Or add a Module Controller pointing to a Test Fragment holding the actions which you would like to execute on Sampler's error. See Easily Write a GOTO Statement in JMeter article for more details.
Related
I have a scenario in JMeter like if the transaction enters into the if loop controller, then the execution should get stop when the all the requests in the if controller gets completed.
It should not execute the calls which are outside the controller.
How to achieve this case? can somebody suggest an idea?
There are 2 options:
Add Flow Control Action sampler as the last request in the If Controller and configure it like:
Or add JSR223 Sampler as the last request in the If Controller and put the following code into "Script" area
ctx.getThread().stop()
SampleResult.setIgnore()
See Top 8 JMeter Java Classes You Should Be Using with Groovy article to learn what do these ctx and SampleResult guys mean.
That's it, if thread enters the If Controller it will execute Sampler1, Sampler 2 and Sampler 3 and then stop. If thread doesn't enter the If Controller it will execute Sampler 1 and Sampler 4.
Guys I need to manually set the end time for the transaction controller in the jsr223 post processor
I tried the following:
prev.getParent().setEndTime()
SampleResult.getParent().setEndTime()
And it didn't help, getParent always returns null. Could you please help me? Maybe there are other ways to do it?
I use jmeter 5.4.1
enter image description here
In order to be able to set the time for the Transaction Controller you need to meet the following criteria:
Transaction Controller should have Generate parent sample box ticked
otherwise you will override response time only for the last child sub-sample. See Using JMeter's Transaction Controller article for more details.
I believe it's better to do it from JSR223 Sampler which should be placed after the Transaction Controller and the code in its turn should be something like:
ctx.getPreviousResult().getParent().elapsedTime=1234
I have a test plan in jMeter that requires some parameters that needs to be calculated before running the test. In order to calculate these parameters, I created a JSR223 PreProcessor directly under test plan as seen below.
My problem is PreProcessor seems to run before every request which is not what I want. I need to calculate these parameters only once and use them in testing.
Is there a way to run the JSR223 PreProcessor only once, or should I use another method?
Thanks in advance.
Edit:
As #ubik-load-pack suggested, I tried "setUp Thread Group" as following but variables created in the code was not available under "Thread Group". They were also present neither in the logs (logging is used in the code) nor in the View Results Tree (via Debug PostProcessor)
I also tried "Once Only Controller" which also didn't work, same as above.
For more information here is content of my JSR223 PreProcessor. (Not the whole code, there will be more variables here so using date functions is not a solution for me by the way.)
By design a PreProcessor runs before any Sampler runs.
So if you want to run something only once per user, you can do the following:
Use a Once Only Controller and put in it a JSR223 Sampler that will contain your code.
If you want to do it once for all users, then use a setupThreadGroup
that will contain your JSR223 Sampler and configure it with 1 thread. It will run once before the regular Thread Groups are started.
EDIT after you updated your question:
As I wrote, you cannot use the setupThreadGroup approach if you want to reuse variables in Thread Groups so stick to OnceOnlyController approach for your request
With the Once Only Controller it is not working because you misread my answer, I am suggesting to use a JSR223 Sampler not PreProcessor as a preprocessor will run only if there is a sampler that runs.
If you use a Sampler, and you have multiple ThreadGroups, then you'll have to copy that sampler into each ThreadGroup, since you can't put Samplers outside of ThreadGroups.
you can use jsr223 PreProcessor with:
if(vars.get("init")=="OK") return;
vars.put("init","OK")
//your code
I'm doing a slightly dirty workaround at the top of the preprocessor:
log.info("in PreProcessor. Sampler name: " + sampler.getName())
if (sampler.getName() != "HTTP Request") {
log.info("not running again")
return
}
In my case I cannot add another sampler because it will mess up my timer calculations.
I have a JMeter script running for x number of users. I want to conditionally close a user thread in a while controller. For example, if my while controller exits for a user thread, I need to stop the thread. Is it possible? Sorry if this is duplicate or a dumb question.
There are at least 2 options on how you can conditionally stop test thread or even the whole test:
Use Test Action sampler in combination with If Controller
Use Beanshell Sampler or PostProcessor and invoke setStopThread method of SampleResult class. See How to use BeanShell guide for example. For reference:
if (condition){
SampleResult.setStopThread(true); // for Beanshell Sampler
prev.setStopThread(true); // for Beanshell Post Processor
}
ctx.getThread().stop() sets the "stop" flag in the current thread, it works anywhere the JMeterContext ctx is exposed.
I have just done and verified it in a complex test script.
I'm using JMeter to run a functional test to update the password of a lot of users (22K). I've separated the users in 2 scripts and used a Ultimate Thread Group with Start Threads Count = 100, which is the value with which I got less errors, however I still got 1.5% transactions failed, and I need to rerun only this failed threads, because all users need to have the same password.
I've tried to get answers to this specific problems, but I have only found ways to prevent this from happening, like using a While controller with a timer, or logging the full response for failure, but I haven't found if there is a way to specifically rerun the failed threads.
Does anyone know if this is possible?
You will have to do following.
Use JSR223 sampler to set the rescode=0
While controller with (if rescode!=200)
HTTP Sampler
JSR223 post processor as javascript as the scripting language.
Store response code using prev.getResponseCode()
e.g. vars.put("rescode", prev.getResponseCode());
You might have to add some more intelligence to the script to avoid infinite loop.
Another approach to solving the problem would be to anticipate errors on some of the password update calls and build a data file upon failure with the information you need.
For Example:
Create a regular expression post processor that has default value of false, and template value of true. Make the expression match the expected response, and fail if the sample fails.
Then, after that sampler, you can add an if statement based on the new true/false variable. If it is false, you know the previous password update failed. Inside the if statement, add a dummy sampler with response data containing all the information you need to know which accounts you must retry.
Then, add a simple file writer to this dummy sampler, and log the dummy sampler response data to a file. At the end of a test run this data file would contain all the information you need to re-try all failed accounts.
Sadly this is a slightly manual process, but I'm sure with a little creativity you could automate recursive test runs until the re-try file is empty. Beanshell file IO might let you handle it all inside a single test run.
-Addled