during & pace with websocket

Hi, All!

I’m recently running a websocket with stomp test.

The stomp client has a heartbeat function, and I’m going to write it as a test in gatling.

Looking at the gatling docs If I use during and pace together, I thought I could imitate the heart-beat.

What I want to send a message to the websocket every 5 seconds for a certain amount of time.

So I wrote the scenario as below.

scenario("subscribe topic from STOMP")
.feed(userFeeder.circular)
.exec(ws("connect websocket").connect(webSocketPath).onConnected(exec(tryStompConnect)))
.exitHereIfFailed
.exec(tryStompSubscribe(topic))
.during(duringTime) {
pace(5.second).exec(ws("send heart-beat").sendText(HEART_BEAT_COMMAND))
} // here : during & pace for heart-beat
.exec(ws("close").close)

However, if I actually run it, it seems that the exec inside pace is not executed.

Is there something wrongly written?

import com.pe.gatling.scenarios.TestScenario
import com.pe.gatling.scenarios.live11.SubscribeTopicTestScenario._
import io.gatling.core.Predef.scenario
import io.gatling.core.Predef._
import io.gatling.core.structure.ScenarioBuilder
import io.gatling.http.Predef.{ws, _}
import io.gatling.http.action.ws.WsSendTextFrameBuilder
import io.gatling.http.check.ws.WsTextFrameCheck

import scala.concurrent.duration.{DurationInt, FiniteDuration}

case class SubscribeTopicTestScenario(userFeeder: IndexedSeq[Map[String, String]],
webSocketPath: String,
topic: String,
duringTime: FiniteDuration) extends TestScenario {

private val checkConnected: WsTextFrameCheck = ws
.checkTextMessage("check connected via STOMP")
.check(regex(".*CONNECTED.*"))

private val sendStompCommand = (description: String, stompCommand: String) => ws(description).sendText(stompCommand)

private val tryStompConnect = sendStompCommand("connect command via STOMP", CONNECT_COMMAND)
.await(30.seconds)(checkConnected)

private val tryStompSubscribe = (topic: String) => sendStompCommand("subscribe command via STOMP", SUBSCRIBE_COMMAND(topic))

private val sendHeartBeat: WsSendTextFrameBuilder = sendStompCommand("send heart-beat", HEART_BEAT_COMMAND)

private val testDuringTime = 20.second

override def getScenarioBuilder: ScenarioBuilder = {
scenario("subscribe topic from STOMP")
.feed(userFeeder.circular)
.exec(ws("connect websocket").connect(webSocketPath).onConnected(exec(tryStompConnect)))
.exitHereIfFailed
.exec(tryStompSubscribe(topic))
.during(testDuringTime) {
pace(5.second).exec(sendHeartBeat)
}
.exec(ws("close").close)
}

}

object SubscribeTopicTestScenario {

private val CONNECT_COMMAND: String =
"""|CONNECT
>heart-beat:15000,0
>accept-version:1.1,1.2
>
>\u0000""".stripMargin

private val SUBSCRIBE_COMMAND: String => String = (subscribeTopic: String) =>
s"""|SUBSCRIBE
>id:0
>destination:$subscribeTopic
>
>\u0000""".stripMargin

private val HEART_BEAT_COMMAND: String =
"""|HEARTBEAT
>
>>> PING
>\u0000""".stripMargin

}

2021년 4월 14일 수요일 오후 3시 22분 10초 UTC+9에 heesuk님이 작성:

Could you please provide some debug logs. This should be working. Also, make sure to use the latest Gatling version (3.5.1 as of now).

Thanks for the answer :slight_smile:

my current gatling version is already 3.5.1.

There is no special debug log, but I’ll share what’s going on.

console log

I noticed the difference between the working version and the non-working version.

The difference seems to be the difference in message format when you do ws.sendText.

[Expected Working version]
...
.during(testDuringTime) {
pace(5.second).exec(ws("TEST").sendText("HEARTBEAT")) // just send HEARTBEAT message. it's work
}
[Non Working Version]
...
.during(testDuringTime) {
pace(5.second).exec(ws("TEST").sendText(HEART_BEAT_COMMAND)) // Heart-Beat Command String not working

}

private val HEART_BEAT_COMMAND: String =
"""|HEARTBEAT
>
>\u0000""".stripMargin

I don’t know what the difference between these two works or not… :frowning:

2021년 4월 17일 토요일 오후 7시 7분 48초 UTC+9에 Stéphane Landelle님이 작성:

Oh, I think this is a problem with my code. It seems to have occurred because the command for HEART-BEAT in stomp protocol is wrong. HEARTBEAT command should just be \n.

I’ll close this question Thank you for checking!

2021년 4월 19일 월요일 오후 3시 53분 27초 UTC+9에 heesuk님이 작성: