Search code examples
artillery

artillery.io doesn't recognize passed variable


I have a test written in Artillery.io which I run in PowerShell with the following command:

artillery run --variables '{ \"duration\": 1, \"data\": \"pgqrdbtymracjrkgzwtdvjaxzgvsvzcdilemxswwbewfbxq\", \"count\": 1 }' --output C:\Users\patryk\socket_io\server\tests\test-run-report.json C:\Users\patryk\socket_io\server\tests\load-test.yml

The test looks like this:

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

After running it, I see:

Test run id: txatr_qm5cwzzjffawbg6x9z57am6ne59p8_fhme
Phase started: unnamed (index: 0, duration: undefineds) 13:29:15(+0100)

Why isn't the variable passed correctly inside the test? If i hardcode value in my test like this:

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

i see that duration is 1s (that's proper scenario).

BTW:I also tried run that command and pass duration as string:

artillery run --variables '{ \"duration\": \"1\", \"data\": \"pgqrdbtymracjrkgzwtdvjaxzgvsvzcdilemxswwbewfbxq\", \"count\": \"1\" }' --output C:\Users\patryk\socket_io\server\tests\test-run-report.json C:\Users\patryk\socket_io\server\tests\load-test.yml

but effect was the same.


Solution

  • I think the answer is in documentation. I trying to overwrite part of config (duration is in config). Due to official documentation: https://www.artillery.io/docs/reference/test-script#variables---inline-variables

    "Variables defined in this block are only available in scenario definitions. They cannot be used to template any values in the config section of your scripts. If you need to dynamically override values in the config section, use environment variables in conjunction with $env. "

    So i will try to use env to overwrite duration.

    EDIT: Yes, it works. Test looks like:

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

    and command for run is like:

    artillery run -e 500 --variables '{ \"data\": \"pgqrdbtymracjrkgzwtdvjaxzgvsvzcdilemxswwbewfbxq\", \"count\": 1 }' --output C:\Users\patryk\socket_io\server\tests\test-run-report.json C:\Users\patryk\socket_io\server\tests\load-test.yml