I'm new to Scala, and trying to write few scripts for Load testing using Gatling. I'm trying to define a re-usable method to send the load, hence I created below method:
def startLoad(scenario: Array[ScenarioBuilder]) = {
setUp(
scnGetAuthorizationToken.inject(
atOnceUsers(1)
),
for (i <- 0 until scenario.length) {
scenario(i).inject(
nothingFor(5 seconds),
atOnceUsers(atOnceUserCount)
).throttle(
reachRps(maxRps/2) in (testDuration/4 seconds),
reachRps(maxRps/2) in (testDuration/4 seconds),
reachRps(maxRps) in (testDuration/2 seconds)),
}
).protocols(httpConf.inferHtmlResources())
.maxDuration(testDuration seconds)
.assertions(
global.responseTime.max.lt(maxResponseTime),
global.successfulRequests.percent.gt(successfulRequests)
)
}
But, compiler is throwing below error for the for
statement. I got same error when I used "foreach" also:
type mismatch; found : Unit required: io.gatling.core.structure.PopulationBuilder
Can someone please help me how to get rid off this error?
In general, I would like to have this code in the following format (few lines of code is called on different variables of ScenarioBuilder type), and hence trying to come up with a re-usable method as defined above:
def startLoad(scenario: Array[ScenarioBuilder]) = {
setUp(
scnGetAuthorizationToken.inject(
atOnceUsers(1)
),
scenario1.inject(
nothingFor(5 seconds),
atOnceUsers(atOnceUserCount)
).throttle(
reachRps(maxRps/2) in (testDuration/4 seconds),
reachRps(maxRps/2) in (testDuration/4 seconds),
reachRps(maxRps) in (testDuration/2 seconds)),
scenario2.inject(
nothingFor(5 seconds),
atOnceUsers(atOnceUserCount)
).throttle(
reachRps(maxRps/2) in (testDuration/4 seconds),
reachRps(maxRps/2) in (testDuration/4 seconds),
reachRps(maxRps) in (testDuration/2 seconds)),
scenario3.inject(
nothingFor(5 seconds),
atOnceUsers(atOnceUserCount)
).throttle(
reachRps(maxRps/2) in (testDuration/4 seconds),
reachRps(maxRps/2) in (testDuration/4 seconds),
reachRps(maxRps) in (testDuration/2 seconds)),
------
).protocols(httpConf.inferHtmlResources())
.maxDuration(testDuration seconds)
.assertions(
global.responseTime.max.lt(maxResponseTime),
global.successfulRequests.percent.gt(successfulRequests)
)
}
So, basically, I would like to repeat below lines of code for every element of the array that is passed as an argument to the method.
inject(
nothingFor(5 seconds),
atOnceUsers(atOnceUserCount)
).throttle(
reachRps(maxRps/2) in (testDuration/4 seconds),
reachRps(maxRps/2) in (testDuration/4 seconds),
reachRps(maxRps) in (testDuration/2 seconds)),