how to implement proper per user session cleanup after certain amount of time?

Hello,

I do face the following challenge. In my gatling script I want to run simulate 1000 user session in parallel. Each user session starts with a beforeTest script (e.g. logging in). After that a single user session proceeds with the actual test and repeats this some times (e.g. forever). Once the test runs for 15 minutes I would need to stop all of the user sessions but before I would need each session to cleanup its stuff by executing its after Test script.

My code looks as following:

val scenarios = scenario(“Performance-Test-Scenario”).exec {
randomSwitch(
getScenarios.map( scenario => (100.0/ getScenarios.size) →
exec {
scenario.beforeTest.exec {
asLongAs(true) {
scenario.test.pace(1 seconds)
}.exec {
scenario.afterTest
}
}
}
) : _*
)
}

setUp(
scenarios.inject(rampUsers(1) over (5 seconds)).protocols(httpConf).inject(atOnceUsers(1))
)

What I tried so far is to use the asLongAs mechanism to check an atomicBoolean which was set to false after 15 minutes but this did not work. Am I doing here something conceptional wrong? or how could I technically solve my problem.

Thanks for any hints!

Cheers,
Michael

I was able to solve my issue:

val scenarios = scenario(“Performance-Test-Scenario”).exec {
randomSwitch(
getScenarios.map( scenario => (100.0/ getScenarios.size) →
exec { session =>
session.set(“continue”, true)
}.exec {
scenario.beforeTest.asLongAs("${continue}") {
scenario.test.exec { session =>
session.set(“continue”, continue.get())
}.pace(1 seconds)
}.exec {
scenario.afterTest
}
}
) : _*
)
}

setUp(
scenarios.inject(rampUsers(1) over (5 seconds)).protocols(httpConf),
scenario(“Set-Continue-To-False”).exec {
pause(10 seconds).exec { session =>
continue.set(false)
session
}
}
.inject(atOnceUsers(1))
)