Reducing Timer with While Loop

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Reducing Timer with While Loop

pratik thorve
Hello Team

I need to achieve the below scenario , and i am not able to figure out how
to achieve the combination of while loop with the timer.
Any guidance on the same / or way using which i can achieve the same ?

-- Set callAPIVariable to True
-- Set Timer to 0 Seconds
while(callAPIVariable and Timer is less than 30 seconds)
-- call the API
-- extract the response
-- If  --> the response is "Still waiting to finish" then do nothing , this
will repeat the loop
-- Else --> Validate the response  ---> set callAPIVariable to false


Thanks
Pratik
Reply | Threaded
Open this post in threaded view
|

Re: Reducing Timer with While Loop

glinius@live.com
You need to obtain the current timestamp prior to entering the loop and save
it into a  JMeter Variable
<https://jmeter.apache.org/usermanual/functions.html>  .  It can be done
using the following  __groovy() function
<https://jmeter.apache.org/usermanual/functions.html#__groovy>  
> ${__groovy(vars.putObject('start'\, System.currentTimeMillis()),)}

Now you have loop start time hence you can introduce 2  clauses for the
while loop, it can be done using the aforementioned __groovy() function
which needs to be put into the  While Controller's
<https://jmeter.apache.org/usermanual/component_reference.html#While_Controller>  
"Condition" input field:
> ${__groovy((vars.get('callAPIVariable').equals('true') &&
> (System.currentTimeMillis() - (vars.getObject('start') as long) <
> 30000)),)}

Assuming the above setup the While Controller will loop over until
*callAPIVariable* value is *true* or 30 seconds pass, whatever happens the
first. See  The Groovy Templates Cheat Sheet for JMeter
<https://www.blazemeter.com/blog/the-groovy-templates-cheat-sheet-for-jmeter/>  
article to learn what else can be done using Groovy scripting in JMeter
tests.



--
Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html