Is there an inbuilt way in Gatling to do one time call and then go into the scenario?

For example, if I want to a login call only once and after that it gets into the scenario?

I can do it by doing a loop, curious if there is something already available that I am not utilizing.

Thanks

Same question here.

I would like to separate out an authentication call, save the auth session token I get from that in the session and then do the actual load testing separately. I am not trying to test the auth server, but need to authenticate first to keep the test real.

Basically, in this gist: https://gist.github.com/chillenious/57220a17be99aeeffce4 separate out the first call so that it isn’t part of what is measured - also possibly with a different ramp up etc - and reuse the token throughout the rest of the test.

Thanks!

Eelco

There is no built-in way of doing exactly what you asked for. There is a way of doing start-up code, but it doesn’t support using the http().get() (and related) behavior. You would have to do your acquisition of an auth-token via direct scala/java code. I’m hoping some day they decide to support the full request chains in the startup block, but until then you are stuck.

Alternatively, you can use something else, like wget, or perl, or anything you want, to get the auth token, and pass it in to Gatling via an environment variable, conf file, or a feeder.

OR, you can do thread-safe code that only lets the first user do the auth portion of the process, and all the rest wait for the auth token to be available before continuing.

Or you could even have two scenarios, where the second injection profile waits for a time before injecting any users, to give the first one time to obtain a token.

Or, you can generate the token, then go into the database and tweak the expiration date so it is good for the next 12 months, and then just save the token to a feeder. That is, if that is an option for you. That was my preferred solution, as it saves me from having to generate tokens for every run.

Bottom line: there’s more than one way to do it. Pick one that works for you.

Gotcha. Thanks for answering!

Eelco

I guess the best solution would be to see this as part of the feed, and implement a custom feed that makes the auth tokens available in the sessions.

Eelco

The problem with that solution is that if you inject one hundred users, your feeder will be expected to provide 100 auth tokens. If the feeder is smart and only requests one if it does not already have one, great. But be aware, it will likely need to be thread-safe code. And you still won’t be able to use the http().get() and related syntaxes to perform the requests, you will need to use straight scala syntax.

Not to dissuade you. It’s a good solution. Just giving you warnings to help you avoid problems. :slight_smile:

Hi all.

I see that this is an old-ish thread, so wondering if anything has changed in the last 3 years or so…

Anyone know if any solution to this (pretty standard NFT automation tool feature) has been implemented?

Cheers,

Ian

I don’t think so, however this is easily done by creating a scenario for your call, running it once and then start the long scenario you want to loadtest.

in code this would be:

`
//define scenarios
def firstScenario = scenario(“first”).exec(“do your thing”).pause(5 seconds)

def secondScenario = scenario(“second”).exec(“do your other thing”)

//run the test
setUp(
firstScenario.inject(
constantconcurrentUsers(1) during (1)
),
secondScenario.inject(
constantConcurrentUsers(0) during (5), //we added a pause of 5 so we can wait 5 before starting to make sure the first call is complete
constantConcurrentUsers(whatever amount you want) during (however long you want)
)
`

I hope that helped you out.

Hi Martijn,

Can we pass a result of first scenarios to the second one ?
I have a requirement, where I need to get the OAuth token (valid for 2 hours) and use it in second scenario. Then again I need to renew that OAuth token, and repeat the second scenario. Bcoz, my testing is kind of endurance testing for 8 hours. I need to repeat this for 4 times. I would like to know is there any better way to achieve this ?

Thanks and Regards,
Karthikaiselvan R

Use ConcurrentLinkedQueue[String] for sharing the data between 2 concurrent users in the scenario.