Increment session param in asLongAs loop

Hi,

Could someone please explain how to can I use asLongAs with a counter?

Documentation states that

.asLongAs(condition, counterName) {
    myChain
}
 
but it does not say how can I increment counter
 
I'm new to Gatling and Scala so have no clue how to implement this
 
Could you please provide some examples? 
Where is the counter stored and how can I address it? 
How to increment it? 
Can i use it in chain? 
 
For example, if I need to create 400 users:
 
.asLongAs(counter < 400, "counter"){
	exec(CreateUser(counter))
	exec((session => session.set("counter", sounter+1))
 
}
 
 
Will this work? 
 
Thanks! 
 
GerraldG

Hi,

Loops use a session attribute counter underneath. If you don’t specify a name, Gatling will generate a random uuid.
You can use it just as any normal attribute.

In your example, it seems that counter is an externally defined variable (counter < 400), so that won’t work.

Why don’t you use a simple repeat loop?

repeat(400, “counter”) {
exec(session => CreateUser(session(“counter”).as[Int]); session)
}

Thanks!

Need to read documentation more carefully.

Regards,
GerraldG

Hi Shephane,

How about if you need to use a csv feeder?
I’ve also been reading the documentation but don’t actually know how to do it on my actual script.

Will this work?

val userCredentials = csv(“users.csv”).circular
val user_counter = userCredentials.records.size
val count = new java.util.concurrent.atomic.AtomicInteger(0)

.asLongAs(condition = _ => count.getAndIncrement() < user_counter, exitASAP = false) {

.exec(http(“NavigateIntranet”)
.get(uri1 + “/ListApplications.do”)
.headers(headers_0))
.pause(13)

exec{
session => session.set(“email”, “${email}”)

.feed(userCredentials)
.exec(http(“EnterCredentials”)
.post(uri1 + “/login.do”)
.headers(headers_2)
.formParam(“location”, " ")
.formParam(“email”, “${email}”)
.formParam(“password”, “${password}”))
.pause(13)
}
}

Yep

Hi,
I want to add one condition in below scenario. Like I would like to exit from the scenario if counter=8 or WorkflowStatus=true
does anyone knows how to add increment counter variable and above condition in below scenario?

class LaunchResources extends Simulation {

val scenarioRepeatCount = Integer.getInteger("scenarioRepeatCount", 1).toInt
val userCount = Integer.getInteger("userCount", 1).toInt
val UUID = System.getProperty("UUID", "24d0e03")
val username = System.getProperty("username", "p1")
val password = System.getProperty("password", "P12")
val testServerUrl = System.getProperty("testServerUrl", "[https://someurl.net](https://someurl.net/)")

val httpProtocol = http
.baseURL(testServerUrl)
.basicAuth(username, password)
.connection("""keep-alive""")
.contentTypeHeader("""application/vnd+json""")

val headers_0 = Map(
"""Cache-Control""" -> """no-cache""",
"""Origin""" -> """chrome-extension://fdmmgasdw1dojojpjoooidkmcomcm""")

val scn = scenario("LaunchAction")
.repeat (scenarioRepeatCount) {
exec(http("LaunchAResources")
.post( """/api/actions""")
.headers(headers_0)
.body(StringBody(s"""{"UUID": "$UUID", "stringVariables" : {"externalFilePath" : "/Test.mp4"}}"""))
.check(jsonPath("$.id").saveAs("WorkflowID")))
``
.exec(http("SaveWorkflowStatus")
.get("""/api/actions/{$WorkflowID}""")
.headers(headers_0)
.check(jsonPath("$.status").saveAs("WorkflowStatus")))

}

setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)
}

What happens if I want to set a time limit? How do I use asLong with a time condition, should I use a timer, how do I implement it?

This is purpose of during: https://gatling.io/docs/current/cheat-sheet/#scenario-definition-loops-during
There is also asLongAsDuring and doWhileDuring to combine criterias and time constraints:

.during(5.minutes) {
chain
}

Wait, in another thread you spoke about synchronize the limit limit for all users. Is this what you intend to do here?

Untitled.png

what I really want to do is create a pattern like the image

image (137).png

I have several user groups that start when another group ends with similar configurations, what I want is to hold a group until a time and end suddenly, and then another group starts, this to not have at the same time the execution of two groups of virtual users

image (138).png

I’ve done this, but with the problem I’ve mentioned, in which two groups actually run for the same but short time, but ruins my pattern, this I’ve done with the command during(), but does not kill the groups but they wait to finish their flow, do not know if the image is seen in the overlap between two groups, what I really need is an example to end the flow of a group of users without waiting for them to finish, but that the simulation continues so that other groups do their thing.