问题
I would like to perform a certain action per thread, so, I assume that tearDown Thread Group will not work.
Is there any alternative to run Once Only Controller only if it is the last iteration of a thread?
Thanks.
回答1:
- Add If Controller to your Test Plan.
Use the following Expression as the If Controller's Condition (assumes __groovy() function):
${__groovy(ctx.getThreadGroup().getSamplerController().getProperty('LoopController.loops').toString() as int == (vars.get('__jm__Thread Group__idx') as int) + 1,)}
Put Sampler(s) you would like to execute at the end as a child(ren) of the If Controller
回答2:
Add If Controller and check the following condition that current iteration is last. For example if therer are 10 iterations (loop count):
${__groovy(10 == vars.getIteration())}
If you have a variable holding number of iteration, check against variable as myIteration
${__groovy(vars.get("myIteration").toInteger() == vars.getIteration())}
来源:https://stackoverflow.com/questions/50023824/jmeter-once-only-controller-at-the-end