0

I want to develop JMeter 5 test plan with the following spec:

First call HTTP Rest API A. if the status code from A is not 200, keep repeatedly calling A until status code is 200. After first successful call to A, then proceed to call Rest API B.

There is CSV Data Set Config for API B which reads CSV file, each entry in CSV invokes a call to API B. When EOF is reached, JMeter must automatically exit (stop running).

API A must be called once every 10 minutes while API B is still being called (or JMeter is still running processing CSV file).

How to achieve this goal? 2 Thread groups are required or single thread group can do the job?

Please provide details like what should be the configs for test plan and thread group(s), the sequence of JMeter elements like While Controller, etc.

The purpose of the test plan is load testing API B, so multiple threads may call API B while a single thread is used to call API A.

ace
  • 11,526
  • 39
  • 113
  • 193

1 Answers1

1
  1. You will need 2 Thread Groups in order to run requests against API A and API B with different number of users and concurrency

  2. In order to repeat request to API A until response status code is 200:

    • Add a While Controller and use the following __groovy() function as the condition:

      ${__groovy((vars.get('code') ?: 42) as int != 200,)}
      
    • Add your HTTP Request for API A as a child of the While Controller

    • Add Boundary Extractor as a child of the HTTP Request and configure it like:

      enter image description here

    • Add Flow Control Action sampler and configure it to sleep for 600000 milliseconds either inside the While loop or outside depending on your scenario

  3. With regards to to stopping the test when the end of CSV file is reached it's just a matter of setting the next parameters in the CSV Data Set Config:

    enter image description here

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thank you for answer. What number 42 means in vars.get('code') ?: 42? – ace Nov 21 '22 at 01:45
  • Just default value, during the first iteration the `code` variable will be [null](https://stackoverflow.com/questions/2707322/what-is-null-in-java) so I used Groovy's [elvis operator](https://groovy-lang.org/operators.html#_elvis_operator) to return some magic number instead of null to avoid errors in the [jmeter.log file](https://jmeter.apache.org/usermanual/get-started.html#logging). See [Apache Groovy: What Is Groovy Used For?](https://www.blazemeter.com/blog/apache-groovy) article for more information on Groovy scripting in JMeter – Dmitri T Nov 21 '22 at 09:09
  • There are two major issues. 1. Both thread groups starts in parallel, if API A fails and busy in retrying in while lopp, API B is being called. API B in second thread group should not be invoked until API A is successfully completed. 2. when API B is finished (EOF of csv reached), second thread group is ended but the first thread group keeps running. The requirment is that when API B is finished, the program should terminate. – ace Nov 21 '22 at 14:52
  • Flow Control Action with the delay of 600000 milliseconds and Pause is selected is at the same level as While controller ie it is sibling and not child of While controller. first thread group for API A has Contniue selected and 1 thread and ramp up is 1 and loop count Infinite is selected and Same user on each iteration is selected.. Second thread group has 2 threads, ramp up is 1 and Loop Count is infinite, Same user on each iteration is selected. – ace Nov 21 '22 at 19:36
  • To run API B only when API A is successful you can use [Inter-Thread Communication Plugin](https://jmeter-plugins.org/wiki/InterThreadCommunication/). To stop the test when CSV file is out of values use the [While Controller](https://www.blazemeter.com/blog/while-controller-jmeter) ( see **Reading all Values from the CSV and Continue** chapter). Then use Flow Control Action Sampler with the logical action `Stop` – Dmitri T Nov 22 '22 at 07:10
  • thank you for comment. I added Flow Control Action with logical action stop and target All threads right after the while controller i.e. it should be executed just when while loop is exited. But it does not executed, program keeps running after EOF of csv file. – ace Nov 22 '22 at 18:08