Home > other >  Gatling session variable gets overwritten for multiple users. How to fix this?
Gatling session variable gets overwritten for multiple users. How to fix this?

Time:10-07

So i am an absolute newbie to gatling and the documentation on their site is pretty meh. My scenario is that i have different users which execute one scenario each and during these scenarios they make requests and save the answer in a session variable which they need as a parameter for a following request during the same scenario. My problem is that i have multiple users running at the same time and these overwrite the session variable so that a user which started earlier refers to the wrong value in the session variable. my idea was to set up a global counter which increments as soon as a new user is initialized and starts with his scenario and to append this counter to the session variable. is this possible and if so how do i do it? i bet there is a way better way to fix this behaviour but as i said i have zero experience with gatling and how its working.

my users look like this

user("singleUpload")
    .behavior {
      feed(applicationCredentials)
    .exec(USingleUpload.singleUpload)

the scenarios like this

val singleUpload = exec(RUpload.post)
                    .exec(RShare.get)
                    .exec(RDownload.get)
                    .doIfEquals("${attachmentSingleUpload}", "attachment.jpg") {
                      exec(RThumbnailDownload.get)
                    }
                    .doIfEquals("${attachmentSingleUpload}", "attachment.png") {
                      exec(RThumbnailDownload.get)
                    }
                    .exec(RDelete.delete)

and the request like this:

val attachment = ("attachment", "${attachmentSingleUpload}")

  val post = http("RUpload")
    .post("/attachment/upload/")
    .queryParam("share", "true")
    .formUpload("attachment", s"attachments/${attachment._2}")
    .header("x-api-key", "${apiKey}")
    .header("x-app-id", "${appId}")
    .check(status.is(200))
    .check(jsonPath("$..pkey").exists.saveAs("pkey"))
val get = http("RShare")
    .get("/attachment/share")
    .queryParam("pkey", "${pkey}")
    .header("x-api-key", "${apiKey}")
    .header("x-app-id", "${appId}")
    .check(status.is(200))
    .check(jsonPath("$..skey").exists.saveAs("skey"))

for example: i make an upload and save the pkey which i then use in the request to get an skey. if user #2 is fast enough with his upload to overwritter the pkey variable in the session then user #1 uses a wrong pkey in his request.

CodePudding user response:

user("singleUpload")
    .behavior {

There's neither user nor behavior methods in Gatling's API. If you really have this in your code, these are private customizations. Can't say what they do or if they're correct.

My problem is that i have multiple users running at the same time and these overwrite the session variable so that a user which started earlier refers to the wrong value in the session variable.

if user #2 is fast enough with his upload to overwritter the pkey variable in the session then user #1 uses a wrong pkey in his request.

This is absolutely impossible. Each virtual user has its own Session, isolated from the others'. You cannot store something in a given virtual user's Session and have another virtual user overwrite it. And there's absolutely zero chance of a bug in there.

I recommend that you reconsider how you came to this erroneous conclusion and investigate other possible explanations. This small piece you provided looks correct. Maybe you've simply uncovered a bug in your application and Gatling is just the messenger.

"the documentation on their site is pretty meh"

That's neither nice nor constructive. Maybe explaining what you think is lacking in the documentation? Have you gone through all of it? Have you checked the online courses?

CodePudding user response:

Gatling sessions are isolated so overwritting is not really possible. I am using saveAs in many simulations without any problems. The issue is somewhere else.

  • Related