Polling an URL until certain value is set in JSON response

Hi all,

I’ve been trying for a while how to write in Gatling 2.0 API a chain that continuously poll a resource until the JSON response contain a specific value. The only example that came up, in this group, seems to be from Gatling 1.0 which uses loop.

It seems to me, I need to use group() because I want to measure the whole poll period instead of the individual calls, and asLongAs() but I can’t seem how to construct that.

This is how I’m trying to build it. My apologies if the code is not idiomatic, I’m still not that experienced with Scala, and Gatling.

`
asLongAs(/* Repeat if volumeStatus != available */) {
group(“Volume Creation”) {
exec(http(“volume_status”)
.get("${volumeURL}/volumes/${volumeId}")
.header(“X-Auth-Token”, “${authToken}”)
.check(jsonPath("$.volume.status").is(“available”).saveAs(“volumeStatus”))
.pause(5)
}
}

`

Thanks in advance

You could check that session contains the value you expect as asLongAs condition.
BTW, if you don’t want to end up with a lot of errors because your check fails, you may want to add dontValidate.
But If the jsonPath query always succeed, e.g. there is always a status, even not the one you want, it is not needed.

asLongAs(session => session(“volumeStatus”).as[String] != “available”) {
group(“Volume Creation”) {
exec(http(“volume_status”)
.get("${volumeURL}/volumes/${volumeId}")
.header(“X-Auth-Token”, “${authToken}”)
.check(jsonPath("$.volume.status").dontValidate.saveAs(“volumeStatus”))
.pause(5)
}
}

Hope this helps !

Cheers,

Pierre

Awesome! It worked!

Thank you

You’re welcome :slight_smile:

Have fun with Gatling !

Pierre