如何使用artillery.io将两个参数从yaml发送到socket.io

3

相关链接:测试Socket.io - Artillery.io文档

我不知道如何从yaml的emit中发送两个参数,对于我的情况,这两个参数是"data"和"message",要发送到"send-room-message"。

Socket.io

socket.on('send-room-message', function (data, message) {
    socket.broadcast.to(data.room).emit('get-room-message', data, message);
});

socketio-chat-load-test.yaml

config:
    target: "http://localhost:3030"  
phases:
- duration: 5 
  arrivalRate: 100   
variables:
greeting: ["hello", "goedemorgen", "добрый день", "guten tag", "bonjour", "hola"]  
variables:
room:
  - 2
scenarios:
 - name: "A user that just talks"
weight: 75
engine: "socketio"
flow:
  - get:
      url: "/"     
  - emit:          
      channel: "add-user"
      data: {"id": "112312", "Name":'Hello'}
  - emit:
      channel: "join-room"
      data: "2"
  - emit :
      channel: "push-room-button"
      data: "2"
      response: 
        channel: "room-busy"
        data: "2"
  - emit:
      channel: "send-room-message"
      data: <<--TODO-->>

有什么想法吗?
1个回答

1

目前 artillery 不支持此功能。不过我找到了一种方法来实现它。 你需要做的是:

  1. Fork artillery-core
  2. Open the file engine_socketio.js
  3. Replace all socketio.emit(...) messages with the following code:

    const splitData = ougoing.data.split('|');
    socketio.emit(outgoing.channel, ...splitData);
    
  4. Commit and push changes to your branch

  5. Clone artillery

  6. Open package.json and change the dependency artillery-core to: "artillery-core": "git://github.com/YOUR-GITHUB-USERNAME/artillery-core.git#YOUR-BRANCH",

  7. Run the command npm link in the directory in which you cloned artillery so it uses the version with the updated artillery-core in the command line.

现在,当你使用火炮时,你可以在socketio-chat-load-test.yaml文件中指定多个参数,例如:
- emit:
        channel: "Insert your channel here"
        data: "Insert first parameter here|Insert second parameter|Third parameter"

1
FYI新版本已更改此项,不再使用artillery-core。您可以克隆artillery存储库,并直接在engine_socketio.js中进行这些更改。请注意,有两个地方需要修改(一个带有回调,一个没有)。谢谢! - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接