Search code examples
websocketjmetersignalrjmeter-plugins

How to write request in Jmeter to test SignalR hub


I have very simple method in my SignalR hub:

public class ActivityHub : Hub
    {
        public async Task NewMessage(string username, string message) =>
            await Clients.All.SendAsync("ReceiveMessage", username, message);
    }

It works perfectly when I use my client (also very simple application written in JavaScript)

The clue of my question is to find how to test my hub via Jmeter. I found already some topics on stackoverflow, and well tutorial: https://medium.com/@goldberg_rui/test-signalr-performance-with-jmeter-59083554f917 I wrote simple test, but it doesn't works. I used “ WebSocket Samplers by Peter Doornbosch” as in tutorial.

Firstly I negotiate (simple HTTP Request): http://localhost:56325/activity/negotiate that returns me some data I extract connectionId from.

Then I open new connection (WebSocket Open Connection) with /activity?id=$(ConnectionId).

On the end I trying to invoke method (WebSocket Single Write Sampler) in my hub with existing connection, and I put data: {"arguments": ["abc","abc"], "invocationId":123,"target":"NewMessage","type":4}. Unfortuantely i getting errors with message:

Response code:Sampler error
Response message:Sampler configured for using existing connection, but there is no connection

Where Is bug in my test? I know that I need to add terminating character 0x1E at the end of the message what I have done. Maybe type of message (4) is not proper or arguments are wrongly paassed? I also put screenshots of my JMeter test. Important: Only second writer is enabled, the first one is disabled.

enter image description here

enter image description here

enter image description here

enter image description here


Solution

  • Found. Change RegEx Extractor to JSON Extractor and set Json Path Expression as $.connectionId.

    The rest of test was ok.