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

2,980 views
Skip to first unread message

Hartmut König

unread,
Mar 31, 2014, 9:59:57 AM3/31/14
to gat...@googlegroups.com
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

Stéphane Landelle

unread,
Mar 31, 2014, 10:08:12 AM3/31/14
to gat...@googlegroups.com
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



--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hartmut König

unread,
Apr 1, 2014, 8:35:13 AM4/1/14
to gat...@googlegroups.com
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 ;-)

i am also following the discussion about the distributed testing ;-)

Hartmut

Stéphane Landelle

unread,
Apr 1, 2014, 8:40:51 AM4/1/14
to gat...@googlegroups.com

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 ;-)

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

sha

unread,
Aug 21, 2019, 3:22:39 PM8/21/19
to Gatling User Group
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)
)
)
}

John Arrowwood

unread,
Sep 17, 2019, 10:15:00 AM9/17/19
to Gatling User Group
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 )
  )
)
Reply all
Reply to author
Forward
0 new messages