Gatling 2: Execute a scenario multiple times (during) and using a random var inside

Hi folks,
i just want to execute a scenario multiple times:

private val RNG = new Random
private def randInt(a:Int, b:Int) = RNG.nextInt(b-a) + a

val scn =
during (6000 seconds) {
.exec(http(“REQUEST-0_justStagingUpdatelayer”)

.post("""/ndx/rpc/ypslayouteditor/updateLayer?t=${secret}""")
.headers(headers_0_selectlayout)
.body(StringBody("""{“method”:“updateLayer”}""")))
.pause(randInt(1,999) milliseconds)
}
}

i want to use a random number for the pause-value, but i just get a random number once compiled.
I also know that this is just a “builder” and will be compiled/run just once, but how could i achieve my goal?

Thanks.

hartmut

You have to pass a function:
.pause(session => randInt(1,999) milliseconds)

As you don’t care about the session input parameter here, you can use the wildcard as well:
.pause(_ => randInt(1,999) milliseconds)

But then, Gatling already has built in support for uniformly distributed pauses:
.pause(1 millisecond, 999 millisecond)

Cheers,

Stéphane

Thanks Stéphane,

didn’t know the builtin-method - nice.

To be honest i think it would be better to split up the 1.5 and the 2 version Documentation, to have them separated. Maby i am the only one who likely mix the both accidentely and run on the wrong path.
In consequence i am checking the source, but the splitting up would be a time saver :wink:

i am also following the discussion about the distributed testing :wink:

Hartmut

To be honest i think it would be better to split up the 1.5 and the 2
version Documentation, to have them separated. Maby i am the only one who
likely mix the both accidentely and run on the wrong path.
In consequence i am checking the source, but the splitting up would be a
time saver :wink:

Exactly the reason why we're moving the documentation out of Github wiki.

I am running into a similar situation where I want to run a http call certain no. of times in a particular timeframe to test its rate limiting.
I’m trying to use duration() and repeat () to achieve this but getting an error when injecting 1 user to run this

val scn1 =
  during (6000) {
    scenario("Setup ")
      .repeat(200)(
        exec(
        http("Get http call")
          .get(**"**https://hello.com/list")
          .header("Authorization", "${auth}")
      ))
    setUp(
      scn1.inject(
        atOnceUsers(1)
      )
    )
  }

setUp is not a method you call on a scenario, it is a method called within a simulation.

If what you are trying to do is make a request N times in X seconds, that’s what injection profiles are for.

setUp(

scn1.inject(
constantUsersPerSec( N / X ) during ( X seconds )
)
)