Looping in Gatling

Hey Folks,

I am really new at Gatling so please don’t crucify me. I am tried to read thorough the wiki docs. I am using gatling 2.

I am just trying to test and application that sends 3 posts after I do a get. After each post more and more data is returned. I can’t tell that if once the application is under a lot of load if the application will only send 3 posts. I assume it will keep sending them as long as it need to collect the data.

I am trying to run a report and there is an ajax call that happens. So I noticed that every 30 seconds there is a new post that is returned.
Therefore, what I want to do is keep executing the post until I find the word “test” in the body of the post.

Is something like this possible with Gatling?
.doWhile("${myvalue}" does not contain “test”) {
once I find “test” exit loop

I am really new at Gatling so please don't crucify me.

Never, we don't do that here :slight_smile:

Assuming you want to continue looping if myvalue doesn't exist:

.asLongAs(session => session("myvalue").asOption[String].map(myValue =>
!myValue.contains("test")).getOrElse(true)) {

Yes. Crucifiction is simply too slow and inefficiënt. We are much more modern: Guillotines are more the gatling style.


French touch!

Nice one :slight_smile:

Thank you so much for your help. I had to make a small change.
Instead of:
.asLongAs(session => session(“myvalue”).asOption[String].map(myValue => !myValue.contains(“test”)).getOrElse(true)) {
I had to use:
.asLongAs(session => session(“myvalue”).asOption[String].map(myValue => !myValue.contains(“test”)).getOrElseBoolean) {
I was getting a compilation error.
It works as expected.
Nice one indeed! :slight_smile:


We’re reaching the limits of the Scala compiler type inference here.

The reason is that asLongAs actually expects a Session => Validation[Boolean], not a Session => Boolean.

There’s an implicit converting from Foo to Validation[Foo], but the compiler doesn’t seem to be able to revolve this implicit AND infer the getOrElse type parameter.

With current snapshot, you could write:
.asLongAs(session => session(“myvalue”).validate[String].map(myvalue => !myvalue.contains(“test”)).recover(true)) {


is it possible to add multiple string validations inside the asLongAs ?

  1. call the api, read the result -
    if the result is either of (abc) or (xyz) then exit if not keep calling the api ?