asLongAs timeout

Hello all

I have done something like that

.exec { session => session.set(“status”, “In progress”) }
.asLongAs(session => session(“status”).as[String].equals(“In progress”)) {
exec(
_GetStuff // call http to a webservice to get a json
.check(jsonPath("""$.finalStatus""").ofType[String].saveAs(“status”))
.check(jsonPath("""$.finalStatus""").ofType[String].not(“Error”))
)
.pause(4 seconds)
}

I did not anticipate is that sometime the backend will never update a status, so always “In progress”

Is there a way to have a max try on this or another method ?
I checked poll but not sure how to have a timeout too…

And yes I will fix the backend too :wink:

Cheers

Have you tried tryMax ? Ref. http://gatling.io/docs/current/general/scenario/

``

Hi
Thanks for the answer

I tried but I have some condition to failed the scenario, and I cannot figure out how to do it.
here is an example, THE CHECK ARE NOT REAL CODE, but rather a way to explains my different conditions :slight_smile:

.exec(http.post(publishsomething)) // publish something

.check(jsonPath("""$.taskId""").ofType[String].saveAs(“taskId”)) // get the task id of the backend background task

.tryMax(300) { // try max 5 minutes
exec(
http.get(get taskId status) // call http to a webservice to get a json
.check(jsonPath("""$.finalStatus""").ofType[String].is(“Done”)) >> should exit the tryMax block and continue the
.check(jsonPath("""$.finalStatus""").ofType[String].is(“Error”)) >> should exit the tryMax block and failed the scenario
.check(jsonPath("""$.finalStatus""").ofType[String].is(“In progress”)) >> should continue the tryMax block

)
.pause(1 seconds)
}

any ideas ?

Thanks

I don’t want to muddy the waters further, but one untested idea might be something like:

`
.exec { session => session.set(“counter”, 0) }
.asLongAs(session => session(“counter”).as[Int] < 300) {

.exec(http.get(get taskId status)

.doSwitch("${status}") (
“Error” → handleError,
“Done” → publishingComplete
/* “In progress” is not matched, so the switch is bypassed */
)

.pause(1 second)
.exec { /* increment the counter */ }
}
`

where you’d need to create handleError and publishingComplete elsewhere to handle those conditions. Good luck.

Thanks Nige

But what I cannot find in the Doc, Group, google…
is how handleError can stop the current scenario session with KO
:S