4

I'm a newcomer to Jmeter and want to be able to run some setup requests once only, in which some variables are setup, before I then run a set of further requests for as many users as I set in the Number of Users Thread Group. These users are passed the variables created in the Once Only Controller.

I've inherited a script as follows, using a Once Only Controller:

Script

If I set the Number of Threads as 10 to ramp up to 10 in one second and run for one minute, I expect the number of Samples (requests) made in the Once Only Controller to show as 1. I only want these requests to run once then subsequent requests to use the setup data.

Why then, when I run, do I see the samples as 10 in the requests that are set in the Once Only Controller:

aggregate report

Bear in mind there may be some fundamental misunderstandings given my I'm a newcomer to Jmeter.

Thanks

1
  • Ff anyone else has the same issue: apparently the "agregate graph" needs to be cleared, or it will contain the sum of all the runs Commented Feb 17, 2020 at 9:48

2 Answers 2

6

As per Once Only Controller documentation:

The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once per Thread, and pass over any requests under it during further iterations through the test plan.

So each your Thread will execute Once Only Controller's children only once, no matter how many loops your thread group will have.

As you have 10 threads each of 10 threads will execute the requests once.

If you want to execute the request by only one thread - I would recommend going for If Controller instead

  1. Substitute Once Only Controller with an If Controller
  2. Use the following condition:

    ${__groovy(ctx.getThreadNum() == 0 &&  vars.getIteration() == 1,)}
    
1
  • thanks Dimitri. I understand a little better. Using your script, it appears now that the If Controller and its child requests do not get executed at all, using the same Thread number, ramp up and timeout. I just need it to run once as a setup job. Then all the subsequent requests to use the variables set in the If Controller
    – Steerpike
    Commented Oct 10, 2018 at 11:48
4

Please use setupThread group to prepare the test environment say test data configuration or like wise that needs to be executed only once before the testing actually begins.

https://www.blazemeter.com/blog/how-use-setup-thread-group-jmeter-when-preparing-load-test/

1
  • I believe this is the correct answer by following JMeter architecture.
    – Dudi Boy
    Commented Jan 29, 2020 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.