0

Can you please explain me why I get two different result with the same variable?

Code

def sql_req = "select message from messages where message_timestamp like '" + vars.get('todayDate') + "%' and message_content like '" + vars.get('msg_id') + "%'"

log.info('Req 1 : ' + sql_req)

log.info("Req 2 : select message from messages where message_timestamp like '${todayDate}%' and message_content like '${msg_id}%'")

Result

Req 1 : select message from messages where message_timestamp like '16/06/20%' and message_content like '132656787653545454%'
Req 2 : select message from messages where message_timestamp like '16/06/20%' and message_content like '878765654556467677%'

I have several loops setup in the Thread Group. But ${msg_id} keep the value of the first loop. It is not updated ...

So I'm blocked because I want to use this request ( select message from messages where message_timestamp like '${todayDate}%' and message_content like '${msg_id}%' ) in a JDBC Request but as value is never updated same request is executed every loop.

Can you explain me why ? Thank you in advance

Royce
  • 1,557
  • 5
  • 19
  • 44
  • 1
    see https://stackoverflow.com/questions/46418275/jmeter-when-not-to-use-cache-compiled-script-if-available – Ori Marko Jun 16 '20 at 07:01

1 Answers1

0

As per JSR223 Sampler documentation:

The JSR223 test elements have a feature (compilation) that can significantly increase performance.

When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.

So either put your ${msg_id} into "Parameters" section and reference it as Parameters or args[0] where required:

enter image description here

Or use vars shorthand for JMeterVariables class instance which provides read/write access to all JMeter Variables in current thread's scope. See Top 8 JMeter Java Classes You Should Be Using with Groovy article for more details if needed

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