Gatling 场景检查状态,然后响应 header。使用 `checkIf`?

Gatling scenario to check status, then response header. Use `checkIf`?

我希望创建一个场景,在其中执行以下速率限制测试:

  1. 每秒请求一次
  2. 检查状态
  3. 如果状态是 200,没有进一步的
  4. 如果状态为429,则断言出现新的响应header (X-Ratelimited)

到目前为止我的场景是这样设置的:

val throttleTest = scenario("Throttle access-code").during(60 seconds) {
    exec(http("put")
      .put("/auth/code")
      .check(
        checkIf(status.is(429))(header("X-Ratelimited"))
      )
      .body(StringBody(s"""{"foo": "$bar"}""")))
      .pause(1)
  }

目前这给我一个错误:

overloaded method value checkIf with alternatives:
  [R, C <: io.gatling.core.check.Check[R]](condition: (R, io.gatling.core.session.Session) => io.gatling.commons.validation.Validation[Boolean])(thenCheck: C)(implicit cw: io.gatling.core.check.TypedConditionalCheckWrapper[R,C])C <and>
  [C <: io.gatling.core.check.Check[_]](condition: io.gatling.core.session.Expression[Boolean])(thenCheck: C)(implicit cw: io.gatling.core.check.UntypedConditionalCheckWrapper[C])C
 cannot be applied to (io.gatling.core.check.CheckBuilder[io.gatling.http.check.status.HttpStatusCheckType,io.gatling.http.response.Response,Int])
        checkIf(status.is(429))(header("X-Ratelimited"))

在这种情况下我应该使用 checkIf 还是其他?

您没有正确使用当前 checkIfcheckIf 没有将检查作为第一个参数的版本,请参阅 doc

从 Gatling 3.5 开始,您必须自己制作条件:

checkIf((response: Response, _: Session) => response.status.code == 429) {
  header("X-Ratelimited")
}

不过你的想法很有趣。也许我们可以在未来的版本中利用我们对 matching 所做的 WebSockets。