check websocket response data

Hey,

I’m new with gatling. So I want to make some tests with websockets. For this I have a backend which reads data from a mongo db and send it over the websocket connection.
So if I send a request with for example “10”. The backend reads 10 datasets from the mongo db and send it.

The datasets I send look like this:


DB Time:21ms [{ "_id" : { "$oid" : "59a4010bcdc5dbae3dde1ae9"} , "data_id" : 1.0 , "data" : { "x" : 36.0 , "y" : 88.0 , "z" : 4.0}}, { "_id" : { "$oid" : "59a4010bcdc5dbae3dde1aea"} , "data_id" : 2.0 , "data" : { "x" : 89.0 , "y" : 25.0 , "z" : 56.0}}, { "_id" : { "$oid" : "59a4010bcdc5dbae3dde1aeb"} , "data_id" : 3.0 , "data" : { "x" : 5.0 , "y" : 19.0 , "z" : 79.0}}, { "_id" : { "$oid" : "59a4010bcdc5dbae3dde1aec"} , "data_id" : 4.0 , "data" : { "x" : 21.0 , "y" : 46.0 , "z" : 48.0}}, { "_id" : { "$oid" : "59a4010bcdc5dbae3dde1aed"} , "data_id" : 5.0 , "data" : { "x" : 42.0 , "y" : 49.0 , "z" : 52.0}}, { "_id" : { "$oid" : "59a4010bcdc5dbae3dde1aee"} , "data_id" : 6.0 , "data" : { "x" : 18.0 , "y" : 49.0 , "z" : 35.0}}, { "_id" : { "$oid" : "59a4010bcdc5dbae3dde1aef"} , "data_id" : 7.0 , "data" : { "x" : 91.0 , "y" : 97.0 , "z" : 30.0}}, { "_id" : { "$oid" : "59a4010bcdc5dbae3dde1af0"} , "data_id" : 8.0 , "data" : { "x" : 87.0 , "y" : 57.0 , "z" : 31.0}}, { "_id" : { "$oid" : "59a4010bcdc5dbae3dde1af1"} , "data_id" : 9.0 , "data" : { "x" : 99.0 , "y" : 28.0 , "z" : 73.0}}, { "_id" : { "$oid" : "59a4010bcdc5dbae3dde1af2"} , "data_id" : 10.0 , "data" : { "x" : 54.0 , "y" : 69.0 , "z" : 73.0}}]

I send the db read time at the beginning and after it the datasets.

Now I want to check if "data_id":1.0 is in my response. The same for for the last dataset "data_id":10.0. So I want to see when arrives the first and the last dataset.
Later I want to send different numbers of datasets and different numbers of useres to check the backend performance. Below is my Code which doesn't work. Any Ideas?

Additionally I want to log the response data with the response times in a csv file, because I want to create my own graphs in excel. How can I do this?

Greetings Martin

package websockets

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.jsonpath._

class WebSockets extends Simulation {

 val httpProtocol = http
 .userAgentHeader("gatling")
 .wsBaseURL("ws://localhost:8080")

 val scn = scenario("WebSocket")
 .exec(ws("Connect WS").open("/testsocket/echo"))
 .exec(ws("request").sendText("10")
 //.check(wsAwait.within(30).until(1).regex("data_id"))
 .check(wsListen.within(5).until(1).jsonPath("$..data_id==1").exists)
 //.check(jsonPath("$[?(@.data_id==1)]").exists)
 //listen in the background
 //.check(wsAwait.within(5).until(1).jsonPath("$data_id").saveAs("yourVariable"))

 )
 //.pause(1)
 //}
 .exec(ws("Close WS").close)

 //setUp(scn.inject(rampUsers(50) over (60 seconds))).protocols(httpProtocol)
 setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)

}

Hey,

I found a solution to check the “data_id”

.exec(ws("request data").sendText("10")

.check(wsAwait.within(10 seconds).until(1).regex(""".*"data_id" : 1.0.*"""))

So now I want to check the “data_id:10”, but in my simulation result I can find only one check and not two checks. I want to know how long it needs to send the first dataset and the last dataset.
How can I fix it? I need like a multiple check simulation.

Additionally I want to log the response data with the response times in a csv file, because I want to create my own graphs in excel. How can I do this?


Greetings Martin