0

I currently have a test plan where I use a random variable to submit a post request to a given URL (/app/${app_id}).

I want to also re-use the random variable app_id to poll the status of that app (/app/${app_id}/status). Note there would be multiple requests to the status URL.

My current idea is to:

  1. have one thread group that submits the posts
  2. save a list of the randomly generated app_ids
  3. in another thread group, read the list of app_ids and for each app_id, loop the status request

Is this a sensible approach? If so, how can I go about saving the randomly generated app_ids and then reading them?

Also, if there is a better approach to this situation, I'm all ears :)

timbre timbre
  • 12,648
  • 10
  • 46
  • 77
Jaime Tur
  • 15
  • 3

2 Answers2

0

Solution with Thread Groups is feasible, although you also can do all that in one thread group, by configuring one of the threads to be "monitor", while remaining threads submit posts. Something like this:

    Thread Group
        If [${__threadNum} == 1]
            Samplers to check status
        If [${__threadNum} != 1]
            Samplers to submit posts

One reason to use 1 thread group for both types of users is if you need any sort of synchronization between writing and reading app_id list - that is easier to achieve in one thread group. Or if you already have many thread groups.

As for providing app_id to various threads/thread groups, you can use one of the approaches:

  1. To pass IDs from one thread group to the other without a file, you can use one of the methods described here (using properties is the most popular way).

    In your case, probably the easiest is to save them in one property with some delimiter, e.g. ID1,ID2,.... The "status" thread then can get this property, split it using either script or __split function to convert property into serialized variables: app_id_1, app_id_2, etc. Those variables are a natural choice for ForEach Controller.

  2. Also first thread group could be saving app_ids into file, while the other reads from the same file with CSV Data Set Config. A bit of caution here though, if they are doing it at the same time.

  3. If app-ids can be pre-generated, a more economical approach would be to have SetUp Thread, which generates them and saves them to CSV file (you will only need one script, e.g. BeanShell to do that, see example here). And then both thread groups read from that file using CSV Data Set Config

Community
  • 1
  • 1
timbre timbre
  • 12,648
  • 10
  • 46
  • 77
0

You can pass the values from one thread group to another one using __setProperty() function like:

${__setProperty(appid-${__counter(FALSE)},${your_variable_holding_appid},)}

Each time the function will be called it will generate a JMeter Property in form of

appid-1=foo
appid-2=bar
appid-3=baz
etc. 

Where numbers like 1, 2, etc. are coming from __counter() function

In another Thread Group you will be able to access the generated values using __P() function like:

${__P(appid-${__counter(FALSE)},)}

Demo:

Sharing Variables between Thread Groups

See Apache JMeter Functions - An Introduction for more information on JMeter Functions concept.


There is more "advanced" way of passing JMeter variables between threads and even thread groups, moreover you will be able to synchronise your threads, i.e. don't start thread in 2nd thread group until variable is not set using Inter-Thread Communication plugin.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133