Gatling - Pause inside of loop

984 views Asked by At

I'm trying to use a pause inside of a loop with gatling and after a single run I would expect the loop to only execute ~3 times but it's executing about 1/sec.

I'm using bzt as the runner with:

hold-for: 30s
concurrency: 1
iterations: 1
throughput: 1
private val scn = scenario("Post, Poll, and Delete")
      .forever {
          exec(http("Post").post(url + path)
            .check(status.is(201))
            .check(jsonPath("$..id").saveAs("id"))
          )
            .doWhile(session => session("status").as[String] == "STARTED", "index") {
              pause(10.seconds)
              exec(http("Poll")
                .get(url + path)
                .queryParam(id, session => session("id").as[String])
                .check(jsonPath("$..status").saveAs("status"))
                .check(jsonPath("$..status").not("ERROR"))
              )
          }.exec(http("Delete")
                  .delete(url + path)
                  .check(status.is(200))
            )
      }

Edit: With help from [Stéphane] I used the below:

.doWhile(condition) {
  pace(???)
  .exec(???)
}
2

There are 2 answers

3
Stéphane LANDELLE On BEST ANSWER

In Scala, the result of the last operation is what the block returns. So what you've written is basically:

.doWhile(condition) {
  pause(???)

  return exec(???)
}

You can see the problem: what's passed as doWhile second parameter is only the exec without the preceding pause.

This happens because you've forgotten to attach them with a dot.

So what you have to do is:

.doWhile(condition) {
  pause(???)
  .exec(???)
}

I also see that you're using a third party launcher (sad). Not sure what it does, in particular throughput: 1 whose wording doesn't match anything in Gatling. If it actually sets up throttling, this disables pauses, as explained in the documentation.

0
圆滚滚 On

you should use

pace(duration)

to pause inside the loop

and use

pause(duration)

outside the loop

check this