# How to accumulate the time?

**URL:** <https://community.gatling.io/t/how-to-accumulate-the-time/1018>\
**Category:** Gatling (Open-Source)\
**Created:** [May 7, 2014, 7:25pm UTC](https://community.gatling.io/t/how-to-accumulate-the-time/1018 "2014-05-07T19:25:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodrigo\_B\_Tolledo](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Rodrigo\_B\_Tolledo](https://community.gatling.io/u/Rodrigo_B_Tolledo)\
**Post date:** [May 7, 2014, 7:25pm UTC](https://community.gatling.io/t/how-to-accumulate-the-time/1018/1 "2014-05-07T19:25:47Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [May 7, 2014, 7:32pm UTC](https://community.gatling.io/t/how-to-accumulate-the-time/1018/2 "2014-05-07T19:32:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rodrigo\_B\_Tolledo](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Rodrigo\_B\_Tolledo](https://community.gatling.io/u/Rodrigo_B_Tolledo)\
**Post date:** [May 7, 2014, 8:33pm UTC](https://community.gatling.io/t/how-to-accumulate-the-time/1018/3 "2014-05-07T20:33:49Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [May 8, 2014, 4:08am UTC](https://community.gatling.io/t/how-to-accumulate-the-time/1018/4 "2014-05-08T04:08:18Z")

</div>

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

2. 

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/](http://goessner.net/articles/JsonPath/)

---

<div class="post-metadata">

**Author:** ![Rodrigo\_B\_Tolledo](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Rodrigo\_B\_Tolledo](https://community.gatling.io/u/Rodrigo_B_Tolledo)\
**Post date:** [May 8, 2014, 7:31pm UTC](https://community.gatling.io/t/how-to-accumulate-the-time/1018/5 "2014-05-08T19:31:41Z")

</div>

“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!

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [May 8, 2014, 7:51pm UTC](https://community.gatling.io/t/how-to-accumulate-the-time/1018/6 "2014-05-08T19:51:37Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)\
**Post date:** [May 8, 2014, 8:30pm UTC](https://community.gatling.io/t/how-to-accumulate-the-time/1018/7 "2014-05-08T20:30:10Z")

</div>

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

Cheers

---

<div class="post-metadata">

**Author:** ![Rodrigo\_B\_Tolledo](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Rodrigo\_B\_Tolledo](https://community.gatling.io/u/Rodrigo_B_Tolledo)\
**Post date:** [May 9, 2014, 6:14pm UTC](https://community.gatling.io/t/how-to-accumulate-the-time/1018/8 "2014-05-09T18:14:04Z")

</div>

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

Cheers!

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [May 9, 2014, 6:42pm UTC](https://community.gatling.io/t/how-to-accumulate-the-time/1018/9 "2014-05-09T18:42:43Z")

</div>

You’re welcome.  
Have fun!
