kmancusi
kmancusi

Reputation: 571

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

I'm looking to create a scenario where it does the following rate limiting test:

  1. Makes a request every second
  2. Checks the status
  3. If the status is 200, nothing further
  4. If the status is 429, then assert that a new response header appears (X-Ratelimited)

This is how my scenario is set up so far:

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)
  }

Currently this gives me an error:

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"))

Should I be using checkIf in this case, or something else?

Upvotes: 1

Views: 2104

Answers (1)

St&#233;phane LANDELLE
St&#233;phane LANDELLE

Reputation: 6608

You're not using the current checkIf correctly. There's no version of checkIf that takes a check as the first parameter, see doc.

As of Gatling 3.5, you have to craft the condition yourself:

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

Your idea is interesting though. Maybe we could leverage what we do with matching for WebSockets in a future version.

Upvotes: 2

Related Questions