Problem statement:
I’m trying to run multiple simulations in parallel by injecting them in a single simulation and triggering this simulation from command-line. It has been observed that Gatling tries to run a given simulation twice for the same user which is not intended. It is intended that Gatling should run different concurrent threads with different users and not the same users from a given queue feeder. I could point of this issue because the print Logging in with userId 1
was logged twice in console logs.
This issue is intermittent, not replicated in every test run.
Code (imports removed):
// AllSimulations.scala
class AllSimulations extends Simulation {
setUp(
new Simlation1().myScenario.inject(rampUsers(3) during (10))
.protocols(new Simulation1().httpProtocol),
new Simlation2().myScenario.inject(rampUsers(3) during (10))
.protocols(new Simulation2().httpProtocol)
)
.assertions(global.responseTime.max.lte(1000),
forAll.failedRequests.count.lte(1))
}
// Simulation1.scala
class Simulation1 extends Simulation {
val httpProtocol = http
.warmUp("https://myapp.com")
.baseUrl("https://myapp.com" + "/external")
.acceptHeader("application/json, text/plain, */*")
.acceptEncodingHeader("gzip, deflate, br")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
object Simulation1 {
var credentialsForToken = ""
var cId = ""
var cPass = ""
val feeder = csv("users.csv").queue
val random =
exec(
http("Step 1 : random")
.get("/auth-service/v1/customer/random")
.check(status.is(200))
.check(jsonPath("$.random").saveAs("Random"))
)
.feed(feeder)
.exec { session =>
cId = session("customerId").as[String]
println("Logging in with userId " + cId)
cPass = session("customerPassword").as[String]
credentialsForToken = CredentialManagment.GenerateCreds.generateCredentialsFeeder(s"""{"customerId":"""" + cId + """","password":"""" + cPass + """","timeStamp":""" + session("Random").as[String] + """}""")
session.set("credentials", credentialsForToken)
}
.exec(
http("Step 2 : login")
.post("/auth-service/v1/customer/login")
.header("Content-Type", "application/json")
.body(StringBody("""{"credential":"${credentials}"}"""))
.check(status.is(200))
.check(jsonPath("$.customerId").saveAs("CustomerId"))
.check(jsonPath("$.otpRequired").saveAs("OtpRequired"))
.check(jsonPath("$.token").saveAs("Token")
))
val myScenario = scenario("myScenario").exec(Scenario1.random)
setUp(
myScenario.inject(
rampUsers(3) during (10)
)
)
.assertions(
global.responseTime.max.lte(1000),
forAll.failedRequests.count.lte(1)
)
.protocols(httpProtocol)
}
Am I missing something or doing something wrong?