Dynamic Thread/Loop Variables

861 views
Skip to first unread message

Peter Boling

unread,
Jan 19, 2017, 2:25:37 AM1/19/17
to codename-taurus
I need to get a variable reference to a username which I can reuse in subsequent requests.
I need it to increment on the counter for each user in each thread.
Ideally also reference the time of the test run, but utilize the same time value for all requests in a single thread loop of a scenario.

I'd like something a bit like this:
"smoke-test-${project-name}.${__time()}.${__counter(TRUE, 'uniq_user_counter')}.${__threadNum}@example.com"

To be evaluated to something like this: 
"smoke-test-api...@example.com"

No matter where I define this type of string (as a variable on the scenario, as a property on the scenario, as the value of a body sent in a POST) it always comes out in JMeter as the literal string: "smoke-test-${project-name}.${__time()}.${__counter(TRUE, 'uniq_user_counter')}.${__threadNum}@example.com", rather than the evaluated version.

I can't find any docs for Taurus on how to get the ${__counter()}, ${__time()}, or ${__threadNum} to evaluate, or where I should place them in the .yml file.

Andrey Pokhilko

unread,
Jan 19, 2017, 2:40:54 AM1/19/17
to codenam...@googlegroups.com

Hi,

Evaluation of these strings is made by JMeter, not by Taurus.

It's difficult to troubleshoot in theory. Can you compose config file demonstrating your problem and post it here? Then I'll be able to understand what exactly you do and how to solve it.


Andrey Pohilko
Chief Scientist
P: +7 (909) 631-21-69
BlazeMeter Inc.
--
You received this message because you are subscribed to the Google Groups "codename-taurus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codename-taur...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codename-taurus/945a487f-1545-400a-80c9-6f73c6fe7b3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter Boling

unread,
Jan 20, 2017, 5:00:34 AM1/20/17
to codename-taurus, andrey....@contractor.ca.com
I am sure that there is nothing in this example that can help over what my initial message already said, but I have attached it anyways.  I have tried placing the functions in properties, body params, and user defined variables, but have yet to find a spot where they get evaluated.  I am trying to use the JMeter functions within the .yml file such that JMeter will evaluate them.

I do not want an email address sent in a request to literally be "test${__counter(TRUE, 'uniq_user_counter')} at example.com".  I want the email address to be evaluated via a JMeter function so that in subsequent loops the email addresses sent in requests are like:

"test1 at example.com"
"test2 at example.com"
"test3 at example.com"

I have all this working in ruby-jmeter, which is similar to taurus in that it allows you to create JMeter scripts using a DSL that is easier than the native .jmx.  But rather than have my whole team learn ruby to use ruby-jmeter I'd like to be able to use .yml, and perhaps eventually blazemeter to run the tests.

Has anyone ever successfully used JMeter functions with taurus?  Can some documentation be added that shows how this is done?  So far it does not seem possible, but I am sure it is simply something I have overlooked.

On Thursday, January 19, 2017 at 6:40:54 PM UTC+11, Andrey Pokhilko wrote:

Hi,

Evaluation of these strings is made by JMeter, not by Taurus.

It's difficult to troubleshoot in theory. Can you compose config file demonstrating your problem and post it here? Then I'll be able to understand what exactly you do and how to solve it.


Andrey Pohilko
Chief Scientist
P: +7 (909) 631-21-69
BlazeMeter Inc.
On 19.01.2017 10:25, Peter Boling wrote:
I need to get a variable reference to a username which I can reuse in subsequent requests.
I need it to increment on the counter for each user in each thread.
Ideally also reference the time of the test run, but utilize the same time value for all requests in a single thread loop of a scenario.

I'd like something a bit like this:
"smoke-test-${project-name}.${__time()}.${__counter(TRUE, 'uniq_user_counter')}.${__threadNum}@example.com"

To be evaluated to something like this: 

No matter where I define this type of string (as a variable on the scenario, as a property on the scenario, as the value of a body sent in a POST) it always comes out in JMeter as the literal string: "smoke-test-${project-name}.${__time()}.${__counter(TRUE, 'uniq_user_counter')}.${__threadNum}@example.com", rather than the evaluated version.

I can't find any docs for Taurus on how to get the ${__counter()}, ${__time()}, or ${__threadNum} to evaluate, or where I should place them in the .yml file.
example.yml

Andrey Pokhilko

unread,
Jan 20, 2017, 6:09:50 AM1/20/17
to Peter Boling, codename-taurus

Hi,

I actually took your config and ran it without modifications like this "bzt example.yml -gui". This brought up the JMeter UI for me to review the resulting test plan.

I reviewed body of "register" sampler and saw there the explected JSON template: '{"username": "smoke-test-${project-name}.${__time()}.${__counter(TRUE, 'uniq_user_counter')}.${__threadNum}@example.com", "password": "some-password"}'

Then I enabled View Results Tree component (it is always added by Taurus to be ready for debugging) and ran the script. It produced two samples with POST bodies:

{"username": "smoke-test-api_smoke_...@example.com", "password": "some-password"}
{"username": "smoke-test-api_smoke_...@example.com", "password": "some-password"}

Which looks like expected evaluation for me... So I don't understand what is wrong with the config. Can you clarify it for me? Where to look to see the non-evaluated functions.


Andrey Pohilko
Chief Scientist
P: +7 (909) 631-21-69
BlazeMeter Inc.

Peter Boling

unread,
Jan 20, 2017, 2:24:22 PM1/20/17
to codename-taurus, peter....@gmail.com, andrey....@contractor.ca.com
I am not sure how I confused things, maybe I was only seeing the unevaluated strings in errors.jtl and was thinking those values were being sent in the request.

One more question I am hoping you can answer.  Is there a way to *not* have the functions directly in the body param values?  I would like to set the ${__time()} for example, after evaluation, to a variable that I can reference such that is does not get re-evaluated on each loop through the thread.  In other words, where do I use the time() function to get a result like:

{"username": "smoke-test-api_smoke_test.14849070...@example.com", "password": "some-password"}
{"username": "smoke-test-api_smoke_test.14849070...@example.com", "password": "some-password"}

Note time stamp is the same, but user counter is incremented, and thread number is the same.


On Friday, January 20, 2017 at 3:09:50 AM UTC-8, Andrey Pokhilko wrote:

Hi,

I actually took your config and ran it without modifications like this "bzt example.yml -gui". This brought up the JMeter UI for me to review the resulting test plan.

I reviewed body of "register" sampler and saw there the explected JSON template: '{"username": "smoke-test-${project-name}.${__time()}.${__counter(TRUE, 'uniq_user_counter')}.${__threadNum}@example.com", "password": "some-password"}'

Then I enabled View Results Tree component (it is always added by Taurus to be ready for debugging) and ran the script. It produced two samples with POST bodies:

{"username": "smoke-test-api_smoke_test.14849070...@example.com", "password": "some-password"}
{"username": "smoke-test-api_smoke_test.14849070...@example.com", "password": "some-password"}

Andrey Pokhilko

unread,
Jan 20, 2017, 3:04:37 PM1/20/17
to codenam...@googlegroups.com

I'd put it under "variables" and assign to variable, then use the variable.. Like this:

variables:

  timestamp: ${__time()}


In JMeter, global variables are evaluated once and very early in the execution.


Andrey Pohilko
Chief Scientist
P: +7 (909) 631-21-69
BlazeMeter Inc.
Reply all
Reply to author
Forward
0 new messages