.doif is skipping exec(test1.action) ==>.doif skips Object Execution

Hi Team,

Am trying to execute two exec snippets based on some .doif validations. PFB my logic

val scene1 = scenario(“scene”)

.forever
{ .doIf(session => session(“testCount”).as[Integer] > 0 && session(“testCount”).as[Integer] < 102)

{
exec(test1.action)
.exec(session => {
testCount = session(“testCount”).as[Integer] + 1
println(“testCount inside::”+testCount)
session.set(“testCount”,testCount)})
}

}

Problem :: Above logic skips the exec(test1.action) object execution step every time and it just increments “testCount” value continuously.
FYI, all my logics are inside exec(test1.action).

What am I missing here and why its skipping exec(test1.action) ?!

Please help!!

Thanks,
GBK

Your code doesn’t compile (dangling dot before doIf).
Please provide a proper working sample that can be executed.

Hi @Stéphane,

Here is my logic

class TestClass extends Simulation {

var testCount = 1

val ApiHeaders = Map(
“accept-encoding” → “gzip, deflate”,
“accept” → “application/json”,
“authorization” → “Bearer ${authtoken}”,
“cache-control” → “no-cache”,
“connection” → “keep-alive”,
“content-type” → “application/json”
)

object Test1 { //METHOD INVOKED
val action = exec(.set(“authtoken”, authtoken))
.exec(
http("b2e_POST
/members")
.post(url+"/test/user")
.body(StringBody(
“”"{“name”: “User1”,“email”: “test@email.com”,“phone”: “1234567890”,“address”: {“countryCode”: “US”,“line1”: “test”,“line2”: “test”,“zipCode”: “60025”,“city”: “Brooklyn”,“state”: “NY”}}""".stripMargin)).asJson
.headers(ApiHeaders)
.check(status.is(201),status.saveAs(“status”))
)
}

val scene1 = scenario(“scene”)
.forever {
during (5 minutes)
{
exec(_.set(“testCount”, testCount))
.exec(session => {
testCount= session(“testCount”).as[Integer]
println(“testCount::”+testCount)
session.set(“testCount”,testCount)})

.doIf(session => session(“testCount”).as[Integer] > 0 && session(“testCount”).as[Integer] < 102)
{
exec(Test1.action) //THIS PART IS GETTING SKIPPED WHEN I RUN
.exec(session => {
testCount = session(“testCount”).as[Integer] + 1
session.set(“testCount”,testCount)})
}
}
}
setUp(
scene1.inject(nothingFor(10 seconds),rampUsers (1) during (10 seconds))
.throttle (jumpToRps (1), holdFor (5 minutes))
)
}

Works fine for me, even though there are buggy things such as you using a global var: shared amongst virtual users (intended) and not thread-safe (use an AtomicInteger).