Due to the nature of our system, we end up doing a lot of pause() in our tests.
Are there any alternatives to wait a fixed time? Like e.g. Spock’s PollingConditions? (http://spockframework.github.io/spock/javadoc/1.0/spock/util/concurrent/PollingConditions.html)
I think you should provide a bit more information to get a proper advice.
Anyways, I wrote a method for one of my loadtests that keeps polling a server until the response contains a given regex (and therefore blocks the scenario execution)
Maybe this is a possible solution for you:
`
/**
- Polls for a given RegExp and saves the result in the session as .
*/
def poll(stepName: String, regExpression: String, saveString: String, intervalMillis: Int, maxTries: Int): ChainBuilder = {
return exec(session => {
session.set(“pollingCounter”, 0)
session.set(“maxTries”, maxTries - 1)
})
//Try with optional polls → Won’t fail the run
.asLongAs(session => {
session.get(“pollingCounter”).as[Int] < session.get(“maxTries”).as[Int] && !session.contains(saveString)
}) {
exec(http(stepName).get(<POLLING_STRING>)
.check(regex(session => {
session.set(“pollingCounter”, session.get(“pollingCounter”).as[Int] + 1)
regExpression
}).optional.saveAs(saveString),
.pause(intervalMillis milliseconds)
}
//Final non-optional poll that fails the current run if it isn’t successful.
.doIf(session => {
session.get(“pollingCounter”).as[Int] >= session.get(“maxTries”).as[Int]
})(exec(http(stepName).get(<POLLING_STRING>)
.check(
regex(regExpression).saveAs(saveString),
.exitHereIfFailed)
}
`