My apologies for the redundancy, this is a continuation of my previous question here Gatling for loop inside inject. I realize I did not phrase my question correctly, resulting in a different answer.
I want to have a for loop inside an injection like this, where I can set how many times I want multiple commands to be run.
scn.inject(
for (i <- 1 to numTimes){
atOnceUsers(10),
nothingFor(10 seconds)
}
).protocols(httpProtocol)
I was provided the following answer, which works great if I only have one command I want to run.
scn.inject(
(1 to numTimes).map(i => atOnceUsers(10))
).protocols(httpProtocol)
However, I want to have multiple commands run, and I am unsure of how to do this. I tried something like this, and got an error saying Too many arguments for method map(A => B)
.
scn.inject(
(1 to numTimes).map(i => atOnceUsers(10), nothingFor(10 seconds))
).protocols(httpProtocol)
I also tried this, and got the error No implicits found for parameter evidence
def commands() {
atOnceUsers(10)
nothingFor(10 seconds)
}
setUp(
scn.inject(
(1 to numTimes).map(i => commands())
).protocols(httpProtocol)
)
You can group your commands in the loop using List or Seq, but then you need to return an Iterable to inject
method. flatMap
helps to merge all intermediate Seqs to one Sequence and thus it becomes Iterable as well.
scn.inject(
(1 to numTimes).flatMap(i => Seq(atOnceUsers(10), nothingFor(10 seconds)))
)
this is what will be constructed as object.
res13: io.gatling.core.structure.PopulationBuilder = PopulationBuilder(
ScenarioBuilder("BasicSimulation", List(io.gatling.core.action.builder.PauseBuilder@60a07d77, io.gatling.http.action.sync.HttpRequestActionBuilder@76795a95)),
InjectionProfile(
Vector(
AtOnceInjection(10),
NothingForInjection(10 seconds),
AtOnceInjection(10),
NothingForInjection(10 seconds),
AtOnceInjection(10),
NothingForInjection(10 seconds),
AtOnceInjection(10),
NothingForInjection(10 seconds),
AtOnceInjection(10),
NothingForInjection(10 seconds)
)
),
Protocols(Map()),
List(),
None
)