asLongAs timeout

626 views
Skip to first unread message

Cedric Cazin

unread,
Aug 23, 2017, 12:05:55 PM8/23/17
to Gatling User Group
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 ;)

Cheers




Nige

unread,
Aug 24, 2017, 10:00:20 PM8/24/17
to Gatling User Group

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

Cedric Cazin

unread,
Aug 29, 2017, 10:33:36 AM8/29/17
to Gatling User Group
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 :)

  .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

Nige

unread,
Aug 29, 2017, 9:42:08 PM8/29/17
to Gatling User Group
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.
Message has been deleted

Cedric Cazin

unread,
Aug 30, 2017, 5:32:41 AM8/30/17
to Gatling User Group
Thanks Nige

But what I cannot find in the Doc, Group, google...
is how handleError can stop the current scenario session with KO 
:S
Reply all
Reply to author
Forward
0 new messages