Retry a request with increasing pause

Hello,

I am trying to achieve the following behavior:
Send a request
If failed, pause 500 ms and retry
If failed, pause 1 s and retry
If failed, pause 2 s and retry

If failed 8 times, exit user

I don’ t know if it is a good way to implement that but I tried

val myReq = exec(http(“MyReq”)
.post("/badPath}")
.check(status.is(200)))

.exec(session => session.set(“retryPause” → (0 millisecond)))

.tryMax(8) {
pause(session => session(“retryPause”).asOption[Duration].getOrElse(0 millisecond).success)
.exec(session => session.set(“retryPause”, 2 * session(“retryPause”).asOption[Duration].getOrElse(0 millisecond)))
.exec(myReq) }.exitHereIfFailed

I had some problems with tryMax using gatling-2.0.0-M2 so I tried gatling-2.0.0-SNAPSHOT (master) because I saw some modifications in TryMax history. But with last version I have no retry and even if my request fails with a 501 the user is not stopped by .exitHereIfFailed

Is my code working ? Is there a better way to achieve my goal ?

Thank you

A bug indeed, stay tuned!

Fixed.

There’s a much more simple way:

def computePause(loopIndex: Int): Duration = ???

tryMax(8, “loopIndex”) {

pause(session => computePause(session(“loopIndex”).as[Int]))


}

Got it?

Yes !

Thank you for the example it is easier indeed ! I will try this as soon as possible

I confirm that it works !

Thanks a lot :slight_smile:

Thanks for your feedback and your testing.