从会话中读取内容时,如何发出加特林捕获请求? [英] How do I make Gatling capture request while reading from the session?

查看:68
本文介绍了从会话中读取内容时,如何发出加特林捕获请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据加特林文档,我可以使用会话属性在执行方案时.

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)

由于上述异常而失败:

  val scn = scenario("Foobar").feed(feeder).exec { session =>
    http("foo").httpRequest("GET", "http://example.org")
    session
  }.pause(5)

推荐答案

方案是模拟的计划.因此,当您说val scn = ...时,您不是执行仿真,而是构建一个AST,稍后通过加特林来执行.

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.

所以当你说

val scn = scenario("Foobar").feed(feeder).exec { session =>
  http("foo").httpRequest("GET", "http://example.org")
  session
}.pause(5)

http("foo").httpRequest("GET", "http://example.org")部分是没有副作用的语句,并且其值从不使用. 所以它可能不存在.就加特林而言,您的情况是

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.

要实现您想要的目标,会话操作必须是单独的exec语句.像这样:

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)

这篇关于从会话中读取内容时,如何发出加特林捕获请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆