Search code examples
scalagatlingscala-gatling

Gatling session variable is returning same value in a loop


I'm having the below code, here the variable "${Cookie}" is always returning the same value (first one). The second API is being called with same ${Cookie} value in all iterations. How to set the session variable for each iteration?

val loginScenario = scenario("SignIn")
.repeat(100) {
  feed(csv(dataPath + "user_list_2.csv").circular)
  .exec(
    http("Sign In")
      .post("/members/sign_in")
      .queryParam("user[email]", "${email}")
      .queryParam("user[password]", "${password}")
      .check(status.is(200))
      .check(header("Set-Cookie").saveAs("Cookie"))
  )
  .exec(
    http("Current user Info")
      .get("/users/current_user_info")
      .header("cookie",  "${Cookie}")
      .check(status.is(200))
  )
}

Solution

  • Gatling comes with Cookie support enabled, so unless you're explicitly flushing the CookieJar on each iteration:

    1. "Sign In" request will send a cookie after the first iteration, probably making it noop
    2. The .check(header("Set-Cookie").saveAs("Cookie") is pretty useless, Gatling will handle cookies for you

    Don't design your test this way, it's very wrong. Don't recycle virtual users or you will recycle connections and SSL Sessions and get better numbers than you should.

    Just inject new users.