How to accumulate the time?

Hi folks,

I’m using Gatlng 1.5.5 and I’m facing a hard time with the following situation:

I would like to measure the total time that takes a specific “user action”. For example, an user hits a button that trigger an action into the system. The system process it and keep returning a bunch of JSON Responses that has a status attribute that can be PRODUCT_MATCH_RUNNING or PRODUCT_MATCH_COMPLETE.

My goal is to measure how long it took to process and stop when I get a “PRODUCT_MATCH_COMPLETE” in my JSON Response (status). I believe I would have to keep executing GETs and analyzing it Response, then when I get a status Complete, then I accumulate the whole time and stop the execution.

How can I do that?

Right now, my Report is just showing how long it took to execute the GET below once. Here is the piece of code I have so far:

.
.
.
.doIf("${status}" != “PRODUCT_MATCH_COMPLETE”) {
exec(http(“product_match_status_verification_GET”)
.get("/project/app/service/workgroup/status/${workgroupId}")
.header(“Content-Type”, “application/json”)
.check(jsonPath(“status”)
.saveAs(“status”))
)

Thanks a lot!

Use an asLongAs loop wrapped in a group (for measuring the total time).

Hi Stéphane,

I’m almost there. I tried through two different ways:

  1. This piece of code loops forever and never end (even after the processing is completed):

.asLongAs("${status}" != “PRODUCT_MATCH_COMPLETE”) {
exec(http(“product_match_status_verification_GET”)
.get("/project/app/service/workgroup/status/${workgroupId}")
.header(“Content-Type”, “application/json”)
.check(jsonPath(“status”)
.saveAs(“status”))
)

  1. With the approach below I got an exception[2]

.asLongAs(session => session.getAttribute(“status”) != “PRODUCT_MATCH_COMPLETE”, “status”) {
exec(http(“product_match_status_verification_GET”)
.get("/project/app/service/workgroup/status/${workgroupId}")
.header(“Content-Type”, “application/json”)
.check(jsonPath(“status”)
.saveAs(“status”))
)

Anything that I’m doing wrong?

Thank you!

  1. There’s no way this could work. You can’t mix Gatling EL and regular code.

2.1) When you write asLongAs(session => session.getAttribute(“status”) != “PRODUCT_MATCH_COMPLETE”, “status”) status will be the loop index name, hence is supposed to store an Int. First, there’s no way it could equal a String. Then, you’re overriding the Int loop index with a String (saveAs), hence the CCE. You don’t even need the loop index, so just remove the way you force the loop index name to status.
2.2) jsonPath(“status”) This is no a valid JsonPath expression. Please check out the syntax: http://goessner.net/articles/JsonPath/

“status” in my case is a String like “PRODUCT_MATCH_COMPLETE” or “PRODUCT_MATCH_RUNNING”, for instance. Also, jsonPath is picking the value correctly.

Just for future references in the mail list, the following piece of code works fine for me:

.asLongAs(session => session.getAttribute(“status”) != “PRODUCT_MATCH_COMPLETE”) {

exec(http(“product_match_status_GET”)
.get("/project/app/service/workgroup/status/${workgroupId}")
.header(“Content-Type”, “application/json”)
.check(jsonPath(“status”)
.saveAs(“status”))
)
}

Thanks a lot, Stephane!

I’m pretty sure that jsonPath(“status”) shouldn’t be working (nremond can correct me on this). I don’t think that’s valid, according to the spec: http://goessner.net/articles/JsonPath. IMHO, it should have a root and the correct form would be “$.status”.

It could just be working because the version of Gatling you’re using ships with the Jayway’s implementation that’s both permissive and buggy.

Upcoming version ships our own implementation that sticks to the spec (and is twice faster).
So, don’t be surprised if your expression stops working the day you upgrade.

Cheers,
Stéphane

I confirm what Stephane said. It won’t be working in Gatling2 anymore, it will only accept strictly valid JsonPath expression.

Cheers

Thanks for your input, guys. I’ll be aware in case I migrate to newer versions.

Cheers!

You’re welcome.
Have fun!