Richard Richard - 3 months ago 9
Scala Question

Push a message and then Poll for a result

We have two services, one which receives a message and a second which tells us when the message has been processed. I'm trying to cover this in a gatling test. Here's what I have so far but I'm struggling with the last bit..

scenario("push message and poll for result")
.feed(feeder)
.group("push and check: group") {
exec(http("push")
.put("/create")
.check(status.is(200))
)
.asLongAs(session => !session.contains("messageProcessed")) {
exec(http("poll")
.get("/poll")
.check(status.is(200), jsonPath("$.results[0].resultCount").saveAs("resultCount"))
}

}


My problem is resultCount will initially be zero so I want to keep polling until it becomes != 0. When this happens I thought I could set "messageProcessed" to something and then it would drop out of the loop.

Is there a way to do this? Thanks for your help.

Answer

this was the solution I used in the end

.asLongAs(session => getResultCount(session) == 0) {

and added this method:

def getResultCount(session: Session): Int = {
    session("resultCount").asOption[String].map(_.toInt).getOrElse(0)
  }
Comments