asLongAs condition problem

Hi,

I have defined a loop which is supposed to end once the current time is greater than a predefined value.

Before scenario:

val proposedEndTime = System.currentTimeMillis + (1601000)

Inside scenario:

.asLongAs(proposedEndTime > System.currentTimeMillis) {
pause(1)
.group(“ChatMessage”){
exec(session => session.set(“sentOnTime”, System.currentTimeMillis))
.exec(ws(“ActualChatMessage”).sendText("""{“messageType”: “newChatMessage”, “you”: “${currentUser}”, “thirdParty”: “${currentThirdParty}”,
“sendTime”: “${sentOnTime}”, “message”: “Hello”}""")
.check(wsAwait.within(10).until(1).regex("""{.“messageType”:“newChatMessage”,“you”:"${currentUser}",“thirdParty”:"${currentUser}",“message”:"",“wasSentOn”:"${sentOnTime}",“communicationWith”:"${currentThirdParty}".}""")))
}
}

The problem is that the loop is never stopping, as if there is no condition. Do you have some ideas of what may be the problem?

Thanks a lot.

Jamie Tabone

First, your condition is not a function but is static, so it’s only evaluated once, when the simulation is built.
You’d have to pass a function: .asLongAs(session => proposedEndTime > System.currentTimeMillis)

Then, assuming what you want to achieve is indeed the sample you provided, using a during loop would be way more simple:
during(60)

Thanks a lot :slight_smile: I solved it now.

Jamie Tabone