英文:
How to write socket.io tests in JMeter?
问题
以下是您要翻译的代码部分:
这是我用socket.io库编写的简单服务器:
const app = express();
app.use(express.static('public'));
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
});
const server = http.createServer(app);
const io = new Server(server);
const port = 3000;
app.get('/help', (req, res) => {
res.send('HELP PAGE')
})
io.on('connection', (socket) => {
console.log(socket.id);
console.log('User connected');
socket.on('message', (msg) => {
console.log('Message: ' + msg);
io.emit('message', msg + socket.id);
});
socket.on('disconnect', () => {
console.log('User disconnected');
});
});
server.listen(port, () => {
console.log(`Server Socket.IO listen on: ${port}`);
});
我需要为JMeter编写测试。我使用Peter的插件来测试WebSocket。我应该如何为message
方法编写测试?
socket.on('message', (msg) => {
console.log('Message: ' + msg);
io.emit('message', msg + socket.id);
});
有人可以发布他自己的测试吗?我已经在Postman中有工作的测试,但这些是针对socket.io的特殊请求类型 - 不幸的是,Postman不如JMeter那么可扩展,我不能使用它。
英文:
There is my simple server written with socket.io library:
const app = express();
app.use(express.static('public'));
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
});
const server = http.createServer(app);
const io = new Server(server);
const port = 3000;
app.get('/help', (req, res) => {
res.send('HELP PAGE')
})
io.on('connection', (socket) => {
console.log(socket.id);
console.log('User connected');
socket.on('message', (msg) => {
console.log('Message: ' + msg);
io.emit('message', msg + socket.id);
});
socket.on('disconnect', () => {
console.log('User disconnected');
});
});
server.listen(port, () => {
console.log(`Server Socket.IO listen on: ${port}`);
});
I need to write test in JMeter. I use plugin from Peter for testing WebSockets. How should I write test for method message
?
socket.on('message', (msg) => {
console.log('Message: ' + msg);
io.emit('message', msg + socket.id);
});
Could someone post his own test? I have already working tests in Postman, but there are special type of request for socket.io - unfortunately Postman is not such scalable as JMeter and I can't use it.
答案1
得分: 1
使用类似Wireshark的嗅探工具捕获Postman发送的所有请求,并配置JMeter以发送相同的请求。
-
添加一个HTTP请求采样器以实例化初始的HTTP连接并获取
sid
-
添加一个Boundary Extractor以从响应中提取
sid
-
打开一个WebSocket连接
-
对这个连接执行需要的操作
英文:
Capture all the requests which are being sent by Postman using a sniffer tool like Wireshark and configure JMeter to send the same requests.
-
Add a HTTP Request sampler to instantiate the initial HTTP connection and get
sid
-
Add a Boundary Extractor to extract the
sid
from the response -
Open a websocket connection
-
Do what you need with this connection
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论