hi,
until now i thought that my scenario is running x users with random user for each thread.
after debugging it, i see that it random just one time and use it for whole the test
i don’t know what i am doing wrong!!!
here is my script:
val scn = scenario("FullCycle")
.during(duration) {
randomNumber = ThreadLocalRandom.current().nextInt(1000)
userNumber = 1000000 + randomNumber
randomUser = "P" + userNumber.toString
println(randomUser)
exec(flushSessionCookies)
.pause(pauseTime)
.exec(RequestToSpJavaUi)
.pause(pauseTime)
.exec(DisplayLogin)
.pause(pauseTime)
.exec(AuthenticateUser)
}
setUp(
scn.inject(
atOnceUsers(users)
).protocols(httpConf)
)
I’m not sure what you mean, but the code you placed in the during loop before the exec chain will only be executed once, when the simulation is loaded.
Then, you seem to be using global mutable variables, which is probably not threadsafe.
If randomUser and the likes are per virtual user, those should be stored in the Session, and computed in an exec(function).
Sorry this is my script before the debug change and also updated the randomuser parameter to be local and not global as you are mention right.
but i still see that the AuthenticateUser happen just once. why?
every execute not go to the section again and run it?
val AuthenticateUser = {
var randomNumber = ThreadLocalRandom.current().nextInt(1000)
var userNumber = 1000000 + randomNumber
var randomUser = "P" + userNumber.toString
println(randomUser)
http("AuthenticateUser").post("${redirectURL}")
.queryParam("j_username",randomUser)
.queryParam("j_password","xxxx")
.check(regex("You have now been authenticated").exists)
}
val scn = scenario("FullCycle")
.during(duration) {
exec(flushSessionCookies)
.pause(pauseTime)
.exec(RequestToSpJavaUi)
.pause(pauseTime)
.exec(DisplayLogin)
.pause(pauseTime)
.exec(AuthenticateUser)
}
setUp(
scn.inject(
atOnceUsers(users)
).protocols(httpConf)
)
You just moved code around, but didn’t change anything to the logic.
http://gatling.io/docs/2.1.4/general/scenario.html#exec
hi,
i really don’t know how to do it from the documentation.
why is not so simple? i didn’t understand the session issue and how to use it.
i just want simple random for each virtual user.
can you give me an example?
okay, finally i solved it by myself:
setting the random at the exec step with session
.exec(session => session.set("randomUser","XXX")
and in order to use it:
Ugly.
.queryParam("j_username",**session => **"P" + (1000000 + ThreadLocalRandom.current().nextInt(1000)))