Reputation: 3108
According to the Gatling documentation, I can work with session attributes when executing a scenario.
However, every time I use function literals to access the session in a scenario, I end up with the following exception:
[error] java.lang.UnsupportedOperationException: There were no requests sent during the simulation, reports won't be generated
[error] at io.gatling.charts.report.ReportsGenerator$.generateFor(ReportsGenerator.scala:45)
[error] at io.gatling.app.Gatling.generateReports(Gatling.scala:198)
[error] at io.gatling.app.Gatling.start(Gatling.scala:82)
[error] at io.gatling.app.Gatling$.fromArgs(Gatling.scala:59)
[error] at io.gatling.sbt.GatlingTask.liftedTree1$1(GatlingTask.scala:49)
[error] at io.gatling.sbt.GatlingTask.execute(GatlingTask.scala:48)
[error] at sbt.ForkMain$Run$2.call(ForkMain.java:296)
[error] at sbt.ForkMain$Run$2.call(ForkMain.java:286)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error] at java.lang.Thread.run(Thread.java:745)
[error] Simulation FooBarSimulation failed.
[info] Simulation(s) execution ended.
More specifically, while this notation gives me correct results:
val scn = scenario("Foobar").feed(feeder).exec {
http("foo").httpRequest("GET", "http://example.org")
}.pause(5)
this fails with the aforementioned exception:
val scn = scenario("Foobar").feed(feeder).exec { session =>
http("foo").httpRequest("GET", "http://example.org")
session
}.pause(5)
Upvotes: 5
Views: 1719
Reputation: 12565
A scenario is a plan for a simulation. So when you say val scn = ...
you are not executing the simulation, but building an AST that is later executed by gatling.
So when you say
val scn = scenario("Foobar").feed(feeder).exec { session =>
http("foo").httpRequest("GET", "http://example.org")
session
}.pause(5)
The part http("foo").httpRequest("GET", "http://example.org")
is a statement which does not have a side effect and the value of which is never used. So it might as well not be there. As far as gatling is concerned, your scenario is
val scn = scenario("Foobar").feed(feeder).exec { session =>
session
}.pause(5)
Which does absolutely nothing, and therefore produces an error when generating a report.
To achieve what you want, the session manipulation has to be a separate exec statement. Like this:
val scn = scenario("Foobar").feed(feeder)
.exec ( session => session.set("foo", "bar") )
.exec (
http("foo").httpRequest("GET", "http://example.org")
)
}.pause(5)
Upvotes: 6