简体   繁体   中英

How do I make Gatling capture request while reading from the session?

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)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM