Trouble Updating Session In If block

So, I want to update a session variable if this scala function returns true.  I set it to always return true to debug this
part of the code.  However, when I run and I print out the session variables at the end of the run the session variable "testNewSeg" is
never updated even though i know that it reaches the code inside the 'if' block. If anyone knows the solution to this problem
please let me know. Thanks! 

.exec{session =>
  if (newSegmentTest(session,"activity_server_id","isNewSeg"))
    {exec(session => session
            .set("testNewSeg","true")
    )}
  session
}

Hi Jason,

Ref the session API documentation: http://gatling.io/docs/current/session/session_api/

Example:

.exec{session =>
if (newSegmentTest(session,“activity_server_id”,“isNewSeg”)) {
session.set(“testNewSeg”,“true”)
} else {
session
}
}

When I remove the last session I get a compile errors:

"Missing parameter type {exec(session => session "

“type mismatch;
found : Unit
required: io.gatling.commons.validation.Validation[io.gatling.core.session.Session]
.exec{session => if(newSegmentTest(session,“activity_server_id”,“isNewSeg”))”

.exec{session => if(newSegmentTest(session,"activity_server_id","isNewSeg")) {exec(session => session .set("testNewSeg","true") )} }

Hi,

Try following the example I posted a few minutes ago - you have to return a session regardless of whether you modify it or not - but since session.set returns an immutable session object then you return either that OR the original session object (use if/else)

Barry

Hey Barry,

Thank you so much! New to Gatling and Scala. This should open up a lot for me.

Hi Jason,

No problems - glad it was helpful… Enjoy!

Barry