Problem with session.set

Hello,

I discovered a strange behavior when I set a boolean value in a session. With the following Simulation:

class TestSimulation extends Simulation {

val endSim = new Date().getTime() + (1 minute).toMillis;

val httpConf = http
.baseURL(“http://www.test.com:8080”)
.acceptHeader("/")
.acceptCharsetHeader(“ISO-8859-1,utf-8;q=0.7,*;q=0.3”)
.acceptEncodingHeader(“gzip,deflate,sdch”)
.acceptLanguageHeader(“en-US,en;q=0.8”)
.userAgentHeader(“Test/1.0.0”)

val scn = scenario(“Test”)
.exec(session => {
session.set(“continue”, true);
})
.asLongAs(session => (session(“continue”).asOption[Boolean].getOrElse(false) && new Date().getTime() < endSim).success) {
exec(session => {
println(“Set continue to false”)
session.set(“continue”, false)
})
.exec(session => {
println(“test”)
session
})
}

setUp(scn.inject(ramp(10).over(10))).protocols(httpConf)
}

I have the following output:
Set error to false
Set error to false

But I never reach the “test” println

If I change session.set(“error”, false) by session.set(“error”, true) then it works. I also tried with an Int instead of a Boolean and I get the same behavior when the value becomes 0

I am using last commit from gatling master

Thanks

Woops, forgot to document that: https://github.com/excilys/gatling/issues/1105

Loops now have an exitASAP parameter (defaulting to true) that causes the exit condition to be evaluated on every element inside the loop:
asLongAs(condition = session => session(“continue”).asOption[Boolean].getOrElse(false) && new Date().getTime() < endSim, exitASAP = false)

Also note that:

  • there’s an implicit that converts values into Validations, so in most cases, you don’t have to add .success
  • since you’re using latest master, you can use the new maxDuration built-in that exactly do what you’re doing with your endSim test: https://github.com/excilys/gatling/issues/1307

Cheers,

Stéphane

Thank for the reply and tips :slight_smile: