关于在 Gatling 中构建自定义 RequestAction 的问题

Question about building custom RequestAction in Gatling

我遵循了本教程(https://blog.codecentric.de/en/2017/07/gatling-load-testing-part-2-extending-gatling/) which teaches you to extend Gatling and essentially led to building this plugin(https://github.com/rbraeunlich/gatling-jdbc)。我正在寻找构建自己的自定义操作并遇到一个小问题。这是我操作中代码的简化版本(扩展 RequestAction):

override def sendRequest(requestName: String, session: Session): Validation[Unit] = {
  val start = clock.nowMillis
  if (requestName.toString().equals("abc")) {
    statsEngine.logResponse(session.scenario, session.groups, requestName.toString(), start, clock.nowMillis, OK, None, None)
    Success("success")
  } else {
    statsEngine.logResponse(session.scenario, session.groups, requestName.toString(), start, clock.nowMillis, KO, None, None)
    Failure("fail")
  }
}

出于某种原因,当从 exec 调用此操作时,如果结果正常,测试将保持活动状态。有什么建议么? (如果这不是正确的论坛,请提前致歉)

ActionBuilder#build

def build(ctx: ScenarioContext, next: Action): Action

您将获得下一个 Action(将其视为回调)。


RequestAction#sendRequest

def sendRequest(requestName: String, session: Session): Validation[Unit]

如果你return一个Failure, 加特林将考虑该请求 "Failed to build" 并自动将执行传递给 next.

如果您return一个Success,则表示请求已发送。然后由您决定,当请求完成时,记录响应时间并将执行传递给 next.


因为你从不这样做,Gatling 认为虚拟用户仍然“活跃”。