Add new values to .saveAs("var")

40 views
Skip to first unread message

Олег Бройченко

unread,
Sep 18, 2017, 12:15:12 PM9/18/17
to Gatling User Group
Hello there. 

I have a websocket server which returns a JSON with some data if I subscribe on proper model with proper id.
I have a list of those ids and subscribe in the loop on model with each id. 
Server returns JSON on every subscription. 
I fetch via jsonPath another ids and save them.

Problem is that in next iteration previously saved ids would be overwritten by new ones. 
Lets say:

With first run of the loop I'll receive 10 "anotherids"
With second - five.
With the last - one.

So "anotherIds" in the end of the loops will contain only one id instead of all that was collected during the loop.
Is there a way to accumulate data in 'saveAs' variable with each loop iteration?

Example of code:

        val subscription = exec(ws("subscribe on model")
       .sendText("""["subscribe_on_model", {"collection": "Model", "id": 2}]""")
       .check(wsAwait.within(20).until(1).jsonPath("$..someIds[*]").findAll.saveAs("someIds")))

       .foreach("${someIds}", "someId") {
         exec(ws("subscribe on model2")
         .sendText("""["subscribe_on_model", {"collection": "Model2", "id": "${someId}"}]""")
         .check(wsAwait.within(20).until(1).jsonPath("$..anotherIds[*]").findAll.saveAs("anotherIds")))
       }

        .foreach("${anotherIds}", "anotherId") {
         exec(ws("subscribe on model3")
         .sendText("""["subscribe_on_model", {"collection": "Model3", "id": "${anotherId}"}]""")
         .check(wsAwait.within(20).until(1).jsonPath("$..someAnotherIds[*]").findAll.saveAs("someAnotherIds")))
       }




Nige

unread,
Sep 18, 2017, 8:32:35 PM9/18/17
to Gatling User Group
You might consider merging the three sequences (someIds, anotherIds, someAnotherIds) after the the last foreach.  Not ideal, but...

Олег Бройченко

unread,
Sep 19, 2017, 3:59:07 AM9/19/17
to Gatling User Group
Perhaps my explanation was quite vague. 
The problem lays within one foreach. Since with each iteration for example "anotherIds" got overwritten. 
I want to have all data that was saved during foreach in that var. 

Nigel Donaldson

unread,
Sep 19, 2017, 6:33:57 AM9/19/17
to gat...@googlegroups.com
Ah, yeah, my bad.  So, you're looking for saveAs to function like an 'appendTo', if it existed.  I believe you're out of luck.  Happy to be told otherwise.

--
You received this message because you are subscribed to a topic in the Google Groups "Gatling User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gatling/yAw0Zv5TWRs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gatling+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages