unexpected behavior of Gatling : method in a scenario called only once whatever the number of vUsers ?

Hello everybody

I am a pure newbie in gatling.
I am using is to test an API for which I want to provide an randomized body (a list of elements extracted from a file)

I got the following scenario

val myScenario = scenario(“my scenario”)

And myMethod() looks as follow

def myMethod() = {

// lets a random set of references
var refList = dataGen.getRandomListOfReferences(“C:/TEMP/references.csv”, 10)

http("get prices for multiple references for price list " + PriceListId)
.post(PricingUrl + “pricesForReferences/” +PriceListId)
.header(“Content-Type”, “application/json”)
.header(“Accept”, “application/json”)
.check(status is 200)

This works “well” but I discovered than when I set my simulation with multiple user (lets say 10) => 10 requests are fired but always with the same body !
in fact the myMethod() seems to be call only once => so the getRandomListOfReferences also that explains why I generate 10x the same request

Could you explain me this behavior and how can I overcome it ?

Thanks for your help !


The method myMethod() is called once, while Gatling is “building the scenario recipe”. Once built, all it has is a bunch of execs to evaluate.

I really don’t know how to explain well (I’m not an expert), but given this piece of code, it’s expected behaviour.

You should try to evaluate refList inside StringBody.

El divendres, 15 novembre de 2019 17:37:14 UTC+1, Nicolas Delucinge va escriure:



Thanks for your quick feedback.

Well I tried something like this

http("get prices for multiple references for price list " + ${getRandomRef()})
.post(PricingUrl + “pricesForReferences/” +PriceListId)
.header(“Content-Type”, “application/json”)
.header(“Accept”, “application/json”)
.check(status is 200)

where getRandomRef() is a function but I got the same behavior => all requests are crafted with same value

Is it the way I shall pass a function as you suggested ? (sorry but I dont understand your remark regarding “Gatling EL string boil down to”).

Your solution is to write a function that puts the value in the session, and then reference the session variables in EL strings.

For example, if you had a hypothetical service that you want to post a new value to, you might do something like this:

exec( session =>
.set( “NAME”, randomName() )
.set( “VALUE”, randomValue() )
.set( “ID”, randomId() )
http( “request that creates a new record” )
.post( serviceUrl )
.body( “”"{“id”:"${ID}",“name”:"${NAME}",“value”:"${VALUE}"}""" )

NOTE: Syntax not guaranteed to be right, just trying to convey the concept

Thanks a lot to everybody for your returns I managed doing what I wanted !