Reputation: 57
Hello I have a websocket server for a text game. The server works, I'm using it with a JS client and have also used it with Postman. At the moment I'm trying to perform a load test using Gatling Websocket API but without any success.
Upon connecting to the server it sends a message prompting for a selection (1 or 2). What I'm trying to do is to receive that message and send a "2" right after and keep the connection hanging.
The simulation code looks like this:
package computerdatabase;
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;
import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;
public class WebsocketSimulation extends Simulation {
HttpProtocolBuilder httpProtocol = http
.wsBaseUrl("ws://localhost:5000");
ScenarioBuilder scene = scenario("Websocket")
.exec(ws("connect")
.connect("")
.await(30).on(ws.checkTextMessage("checkMessage")
.check(regex(".*?").saveAs("message")))
)
.exec(session -> {
System.out.println("response: " + session.get("message"));
return session;
})
.exec(ws("sendMessage").sendText("2"))
.pause(30)
.exec(ws("Close WS").close());
{
setUp(scene.injectOpen(
atOnceUsers(1))
.protocols(httpProtocol));
}
}
Setting <root level="DEBUG">
in logback.xml, shows that the message is received in Gatling, however the session.get("response")
returns nothing. And while the logs say that the message containing 2 is sent, the server never receives it.
Gatling's logs:
03:51:01.522 [DEBUG] i.g.h.a.w.WsListener - Received response to WebSocket CONNECT: 101 Switching Protocols DefaultHttpHeaders[Upgrade: websocket, Connection: Upgrade, Sec-WebSocket-Accept: Bhe1yEfgK701lLdh9BK4+ZVDr4k=, Sec-WebSocket-Extensions: permessage-deflate; client_no_context_takeover; server_max_window_bits=12; client_max_window_bits=12, Date: Tue, 29 Oct 2024 01:51:01 GMT, Server: Python/3.11 websockets/13.1, content-length: 0]
03:51:01.527 [DEBUG] i.g.h.a.w.f.WsConnectingState - Connected, performing checks before proceeding (no onConnected action)
03:51:01.528 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 1437022170 scheduled
03:51:03.529 [DEBUG] i.g.h.c.i.WebSocketHandler - Read msg=TextWebSocketFrame(data: CompositeByteBuf(ridx: 0, widx: 895, cap: 895, components=1))
03:51:03.533 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Received matching message <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<style type="text/css">
.ansi2html-content { display: inline; white-space: pre-wrap; word-wrap: break-word; }
.body_foreground { color: #AAAAAA; }
.body_background { background-color: #000000; }
.inv_foreground { color: #000000; }
.inv_background { background-color: #AAAAAA; }
.ansi1 { font-weight: bold; }
.ansi2 { font-weight: lighter; }
.ansi37 { color: #F5F1DE; }
</style>
</head>
<body class="body_foreground body_background" style="font-size: normal;" >
<pre class="ansi2html-content">
<span class="ansi2"></span><span class="ansi1"></span><span class="ansi1 ansi37">Welcome to the Script!
Which mode would you like to play?
1.Single Player
2.Multi Player</span>
</pre>
</body>
</html>
03:51:03.544 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Current check success
03:51:03.544 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Current check sequence complete
03:51:03.544 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 1437022170 cancelled
03:51:03.544 [DEBUG] i.g.h.a.w.f.WsPerformingCheckState - Check sequences completed successfully
response:
03:51:03.548 [DEBUG] i.g.h.a.w.WsSendTextFrame - Sending text frame 2 with WebSocket '<function1>': Scenario 'Websocket', UserId #1
03:51:03.550 [DEBUG] i.g.h.a.w.f.WsIdleState - Send text frame sendMessage 2
03:51:03.550 [DEBUG] i.g.h.c.i.WebSocketHandler - ctx.write msg=TextWebSocketFrame(data: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 1, cap: 64))
03:51:03.553 [DEBUG] i.g.c.a.Pause - Pausing for 30000ms
================================================================================
2024-10-29 01:51:21 GMT 20s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=3 KO=0 )
> connect (OK=1 KO=0 )
> checkMessage (OK=1 KO=0 )
> sendMessage (OK=1 KO=0 )
---- Websocket -----------------------------------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done: 0
================================================================================
03:51:21.517 [DEBUG] i.g.h.c.i.WebSocketHandler - Read msg=PingWebSocketFrame(data: PooledUnsafeDirectByteBuf(ridx: 0, widx: 4, cap: 4))
================================================================================
2024-10-29 01:51:31 GMT 30s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=3 KO=0 )
> connect (OK=1 KO=0 )
> checkMessage (OK=1 KO=0 )
> sendMessage (OK=1 KO=0 )
---- Websocket -----------------------------------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done: 0
================================================================================
03:51:33.556 [DEBUG] i.g.h.a.w.WsClose - Closing websocket '<function1>': Scenario 'Websocket', UserId #1
03:51:33.558 [DEBUG] i.g.h.a.w.f.WsIdleState - Client requested WebSocket close
03:51:33.559 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 2061203621 scheduled
03:51:33.560 [DEBUG] i.g.h.c.i.WebSocketHandler - ctx.write msg=CloseWebSocketFrame(data: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 5, cap: 64))
03:51:33.565 [DEBUG] i.g.h.c.i.WebSocketHandler - Read msg=CloseWebSocketFrame(data: PooledUnsafeDirectByteBuf(ridx: 0, widx: 5, cap: 5))
03:51:33.570 [DEBUG] i.g.h.a.w.f.WsFsm - Timeout 2061203621 cancelled
03:51:33.571 [DEBUG] i.g.h.a.w.f.WsClosingState - Server has acked closing: 1000/Bye
03:51:33.573 [DEBUG] i.g.c.a.Exit - End user #1
03:51:33.578 [DEBUG] i.g.c.c.i.Injector - End user #Websocket
03:51:33.579 [DEBUG] i.g.h.c.i.WebSocketHandler - channelInactive
03:51:33.579 [INFO ] i.g.c.c.i.Injector - All users of scenario Websocket are stopped
03:51:33.582 [INFO ] i.g.c.c.i.Injector - Stopping
03:51:33.583 [INFO ] i.g.c.c.Controller - Injector has stopped, initiating graceful stop
================================================================================
2024-10-29 01:51:33 GMT 32s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=4 KO=0 )
> connect (OK=1 KO=0 )
> checkMessage (OK=1 KO=0 )
> sendMessage (OK=1 KO=0 )
> Close WS (OK=1 KO=0 )
---- Websocket -----------------------------------------------------------------
[##########################################################################]100%
waiting: 0 / active: 0 / done: 1
================================================================================
03:51:33.598 [DEBUG] i.g.c.c.Controller - StatsEngine was stopped
03:51:33.598 [INFO ] i.g.app.Runner - Simulation computerdatabase.WebsocketSimulation completed in 32 seconds
Any ideas what's wrong?
Upvotes: -1
Views: 90
Reputation: 6623
I’m surprised by the behavior you’re experiencing. I’ll check next week. But your regex check is weird as it doesn’t contain a capture group. If your goal is to capture the full inbound message, just use a bodyString check. Otherwise, add a capture group.
Upvotes: 0