如何在Jmeter中编写请求以测试SignalR hub

huangapple go评论78阅读模式
英文:

How to write request in Jmeter to test SignalR hub

问题

我在我的SignalR hub中有一个非常简单的方法:

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

当我使用我的客户端(也是用JavaScript编写的非常简单的应用程序)时,它能够完美地工作。

我的问题是如何通过Jmeter测试我的hub。我已经在stackoverflow上找到了一些相关主题,以及一个很好的教程:
https://medium.com/@goldberg_rui/test-signalr-performance-with-jmeter-59083554f917
我编写了一个简单的测试,但它不起作用。我像教程中一样使用了"WebSocket Samplers by Peter Doornbosch"。

首先,我进行协商(简单的HTTP请求):
http://localhost:56325/activity/negotiate,这个请求返回一些数据,我从中提取了connectionId。

然后,我打开一个新的连接(WebSocket Open Connection)到/activity?id=$(ConnectionId)

最后,我尝试使用现有的连接调用我的hub中的方法(WebSocket Single Write Sampler),并且我放入了数据:

{"arguments": ["abc","abc"], "invocationId":123,"target":"NewMessage","type":4}

不幸的是,我收到了带有以下消息的错误:

响应代码:Sampler错误
响应消息:配置为使用现有连接的Sampler,但没有连接

我的测试中有什么问题?我知道我需要在消息末尾添加终止字符0x1E,这一点我已经做了。也许消息的类型(4)不正确,或者参数传递错误?
我还放置了我的JMeter测试的屏幕截图。
重要提示:只启用了第二个写入器,第一个写入器被禁用。

如何在Jmeter中编写请求以测试SignalR hub

如何在Jmeter中编写请求以测试SignalR hub

如何在Jmeter中编写请求以测试SignalR hub

如何在Jmeter中编写请求以测试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.

如何在Jmeter中编写请求以测试SignalR hub

如何在Jmeter中编写请求以测试SignalR hub

如何在Jmeter中编写请求以测试SignalR hub

如何在Jmeter中编写请求以测试SignalR hub

答案1

得分: 1

你的设置看起来不错,然而错误消息意味着连接未打开,所以我的期望是你的WebSocket Open Connection采样器在某个地方出现了问题。

  1. 使用查看结果树监听器来检查请求和响应,并将它们与JavaScript发送的内容进行比较。
  2. 检查jmeter.log文件是否有可疑条目,因为从你JMeter GUI右上角的黄色感叹号看,至少有2个需要修复的错误。你还可以考虑通过将下一行添加到log4j2.xml文件来增加WebSocket采样器的JMeter调试日志详细程度至DEBUG级别
<Logger name="eu.luminis" level="debug" />

需要重新启动JMeter才能应用此更改。

英文:

Your setup looks good, however the error message means that the connection is not open so my expectation is that your WebSocket Open Connection sampler fails somewhere somehow.

  1. Use View Results Tree listener to inspect request and response and compare them with the ones sent by JavaScript

  2. Check jmeter.log file for any suspicious entries as looking into yellow exclamation sign at upper right corner of your JMeter GUI it looks like there are at least 2 errors which need to be fixed. You can also consider increasing JMeter debug logging verbosity to DEBUG level for the websocket samplers by adding the next line to log4j2.xml file:

    &lt;Logger name=&quot;eu.luminis&quot; level=&quot;debug&quot; /&gt;
    

    JMeter restart will be required to pick up the change

答案2

得分: 0

已找到。
将正则表达式提取器更改为JSON提取器,并将Json Path Expression设置为$.connectionId

其余测试正常。

英文:

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

The rest of test was ok.

huangapple
  • 本文由 发表于 2023年6月9日 08:12:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76436426.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定