I have a gatling scenario where I subscribe to a websocket and want to check the incoming messages for internal consistency.
E.g. the messages coming over the websocket are <user>: <sequence number>
, and I want to check that for each user string, the sequence number is continuous and increasing from 1.
a: 1
b: 1
a: 2
b: 2
a: 1 // <= this would be an error because last a was 2, so should be 3
My first approach was to store something like a Map[String, Int]
in a session variable. But it seems to me that the gatling webservice API does not allow storing non-string session variables:
This (just concatenating everything we got over the WS) compiles:
def updateState(text: String, session: Session): String = {
session("wsState").as[String] + "\n" + text
}
val scn = scenario("String")
.exec(ws("Connect WS")
.open("/indexWS?topic=${topic}")
.check(
wsListen
.within(3600.seconds)
.until(10)
.message
.find
.transform(updateState _)
.saveAs("wsState"))
)
But as soon as the updateState function returns something other than string, it does not compile anymore
def updateState(text: String, session: Session): Map[String, Int] = {
session("counts").as[Map[String, Int]] // + update from message text
}
val scn = scenario("String")
.exec(ws("Connect WS")
.open("/indexWS?topic=${topic}")
.check(
wsListen
.within(3600.seconds)
.until(10)
.message
.find
.transform(updateState _)
.saveAs("counts"))
)
Here is the error message:
[error] found : io.gatling.core.check.CheckBuilder[io.gatling.http.check.ws.WsCheck,String,String,Int]
[error] required: io.gatling.http.check.ws.WsCheckBuilder
[error] (which expands to) io.gatling.core.check.CheckBuilder[io.gatling.http.check.ws.WsCheck, String, _, String]
Now obviously I could just serialize the map to a string on every update. But I would rather avoid that. Non-string session variable seem to be allowed in gatling, so why not in websockets?