Ehtesham Ahmed
Ehtesham Ahmed

Reputation: 69

If Controller is not working as expected

I am working on a JMeter script and trying to get response time from a sampler, store it into a variable, and then user IF Controller in tear down thread group on the basis of response time i.e. send an email if response time is greater than 300 milliseconds.

I have stored response time as follows using Beanshell post processor

long duration = prev.getTime(); vars.put("duration", String.valueOf(duration));

And trying to trigger email sampler under IF Controller using following condition:

${duration} > '300'

Not sure what I am doing wrong here. Any help will be much appreciated.

Thanks

Upvotes: 0

Views: 458

Answers (3)

Ehtesham Ahmed
Ehtesham Ahmed

Reputation: 69

Issue is resolved by using properties as they can be shared among thread groups.

Thanks all

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168197

You have 2 errors there:

  1. Variables are local to the current Thread Group only, if you need to pass them between Thread Groups you need to convert them into JMeter Properties (see Knit One Pearl Two: How to Use Variables in Different Thread Groups for details) or use bsh.shared namespace for the same, example code:

    long duration = prev.getTime();
    bsh.shared.duration = duration
    
  2. Surrounding number with quotation marks is wrong as JavaScript will treat it as a String, you don't need quotation marks there. Also you can use __Beanshell() function as the If Controller clause like:

    ${__BeanShell(bsh.shared.duration > 300)}
    

Also be aware that duration is in milliseconds so maybe your 300 ms threshold might be a little bit low.

Upvotes: 0

Iske
Iske

Reputation: 1200

Variables cannot be shared between threads. Use property to store duration, and you will be able to use it in tearDown Thread Group.

long duration = prev.getTime();
props.put("duration", String.valueOf(duration));

After that you can use:

${__P(duration,0)}

"Zero" is place for default value in case property with given name is not found.


Btw, you could also use Beanshell/Groovy to get property:

vars.put("durationVariable", props.get(duration));

Upvotes: 1

Related Questions