Artillery - 如何在 POST 请求中指定嵌套的 json 主体

Bak*_*vic 6 load-testing artillery

我正在尝试将 Artillery 配置设置为能够发送嵌套的 JSON 正文。这是我的配置的样子:

config:
  target: <URL>
  phases:
    - duration: 10
      arrivalRate: 20
  processor: "./input-parser.js"
scenarios:
  - flow:
    - function: "parseJsonFile"
    - post:
        url: /workflow-instance
        headers:
           Content-Type: "application/json"
        json:
          name: "{{ name }}"
          namespace: "{{ namespace }}"
          template_name: "{{ template_name }}"
          attributes: "{{ attributes }}"
    - get:
        url: "/workflow-instance/status?name={{ template_name }}&namespace={{ namespace }}"
Run Code Online (Sandbox Code Playgroud)

我对“属性”有疑问,因为属性的内容是:

{ pod_name: 'POD_NAME', port: 'PORT_NUMBER' }
Run Code Online (Sandbox Code Playgroud)

所以基本上,这行不通:

attributes: "{ pod_name: 'POD_NAME', port: 'PORT_NUMBER' }"
Run Code Online (Sandbox Code Playgroud)

还有这个:

attributes:
  pod_name: 'POD_NAME'
  port: 'PORT_NUMBER'
Run Code Online (Sandbox Code Playgroud)

我没有在 Artillery 文档中找到这个特殊案例的好例子。

jma*_*ori 1

以下解决方法对我有用将 JSON 数据嵌入到 YAML 文件中

那么你必须将你的更改attributes为:

attributes: '{ pod_name: "POD_NAME", port: "PORT_NUMBER" }'
Run Code Online (Sandbox Code Playgroud)

我在用着:

Artillery: 1.7.9
Artillery Pro: not installed (https://artillery.io/pro)
Node.js: v14.6.0
OS: darwin/x64
Run Code Online (Sandbox Code Playgroud)