在 artillery.io 中将时间作为数据消息发送

问题描述 投票:0回答:2

我需要在 artillery.io 测试中使用当前时间(或日期时间)。我想测试当前时间作为消息:

config:
  target: "http://localhost:3000/"
  phases:
    - duration: 10 
      arrivalRate: 1
  environments:
    local:
      target: "http://localhost:3000/"
      phases:
        - duration: 10
          arrivalRate: 1
    prod:
      target: "http://localhost:3000/"
      phases:
        - duration: 100
          arrivalRate: 1 
          
scenarios:
  - name: "Emit an event"
    engine: socketio
    flow:
      - loop:
          - emit:
              channel: "chat
               message"
              data: " messageWithTime "
          - think: 1
        count: "{{ count }}" 

其中

data: " messageWithTime "
应该有当前时间。我无法在执行命令期间将时间作为变量传递,因为我需要在每个请求中包含当前时间。 可以吗?

artillery
2个回答
0
投票
scenarios:
  - name: "Emit an event"
    engine: socketio
    flow:
      - loop:
          - function: "getCurrentTime"
          - emit:
              channel: "chat
               message"
              data: "{{currentTime}} "
          - think: 1
        count: "{{ count }}" 



in the processor functions define:
async function getCurrentTime(context, events) {
  context.vars["currentTime"] = new Date().getTime();
}

0
投票

.yaml 应如下所示:

scenarios:
  - name: "Emit an event"
    engine: socketio
    flow:
      - loop:
          - function: "setupSomeData" 
          - emit:
              channel: "chat
               message"
              data: "{{ data }}"
          - think: 1
        count: "{{ count }}"

我的 my-functions.js 看起来像这样:

module.exports = {
   setupSomeData: function (userContext, events, done) {
    userContext.vars.data = Date.now(); 
    console.log(userContext.vars.data);
    done()
}
}

答案参考:https://github.com/artilleryio/artillery/discussions/2600

© www.soinside.com 2019 - 2024. All rights reserved.