Search code examples
gatlingscala-gatling

Gatling for loop inside inject


I am new to Scala and Gatling so bear with me! I want to have a for loop inside inject where I can set how many times I want atOnceUsers()instead of just repeating the code x times, but this code is giving me an error so I was wondering if this way is not supported.

val numTimes = 3
val scn = scenario("Some scenario").exec(someScenario)

setUp(
    scn.inject(
        for (i <- 1 to numTimes) atOnceUsers(10)
    ).protocols(httpProtocol)
)

Solution

  • you're close...

    .inject takes an array of steps (which a straight 'for' doesn't produce without a 'yield')

    what you can do is...

    scn.inject(
        (1 to numTimes).map(i => atOnceUsers(10))
    ).protocols(httpProtocol)