drill icon indicating copy to clipboard operation
drill copied to clipboard

Assigns stores data in array when run with_items_from_csv

Open patrick-armitage opened this issue 4 years ago • 2 comments

Feature request:

I want to be able to load test a mass number of users running through multiple actions (purchasing on a site, configuring their account, etc.). Right now I am able to login those users using with_items_from_csv and their credentials in each row of a CSV.

However, with subsequent steps the assign data is only going to be the latest data for the variable in the CSV user login step. So for example, when I assign data to user in Get token for user step below, only the latest row of the CSV input will be present in assign:

Threads 1
Iterations 1
Rampup 0
Base URL https://mysite.com

Get token for user [email protected] https://mysite.com/token 200 OK 660ms
Get token for user [email protected] https://mysite.com/token 200 OK 222ms
Get user info for Jocelyn Frank https://mysite.com/users/8331593/ 200 OK 125ms

It would be awesome if assign when called in a step with a CSV fixture supported arrays and stored the data that way, so subsequent steps could access the array with an option like with_items_from_assign_data, and I could do something like:

  - name: Get token for user {{ item.email }}
    request:
      url: /token
      method: POST
      headers:
        Accept: "{{ header_accept }}"
        Content-Type: "{{ header_content_type }}"
        Authorization: "{{ header_auth }}"
      body: grant_type=password&username={{ item.email }}&password={{ item.plaintext_password }}
    with_items_from_csv: ./fixtures/users.csv
    assign: users

  - name: Get user info for {{ user.body._embedded.user.first_name }} {{ user.body._embedded.user.last_name }}
    request:
      url: "{{ user.body._links.user }}"
      method: GET
      headers:
        Accept: "{{ header_accept }}"
        Content-Type: "{{ header_content_type }}"
        Authorization: Bearer {{ user.body.access_token }}
    with_items_from_assign_data: users

Then for this example run it would iterate over that array of data responses in the second step, yielding:

Threads 1
Iterations 1
Rampup 0
Base URL https://mysite.com

Get token for user [email protected] https://mysite.com/token 200 OK 660ms
Get token for user [email protected] https://mysite.com/token 200 OK 222ms
Get user info for Jessica Rice https://mysite.com/users/8331592/ 200 OK 168ms
Get user info for Jocelyn Frank https://mysite.com/users/8331593/ 200 OK 125ms

patrick-armitage avatar May 26 '20 21:05 patrick-armitage

yep, your problem is quite similar to mine, given you probably want to test {{ user.body._links.user }} the first request is just a pre-condition to the second

after a couple of changes to drill code I managed to do something like:

base: "https://targethostname"
concurrency: 100
iterations: 1

plan:
  - name: "Fetch cadastro from server iteration:{{ iteration }} user:{{ concurrency }}"
    request:
      url: http://localhost:9000/api/cadastros/{{ concurrency }}
    assign: cadastro

  - name: "Criando um cliente iteration:{{ iteration }} user:{{ concurrency }}"
    request:
      url: /qa/wcs/resources/v1/customer/create
      method: POST
      body: "{{ cadastro.body }}"
      headers:
        Content-Type: "application/json"

But it turns out that the first call is very expensive and messes with test results, a better approach maybe should be to create another keyword to get the data from a csv file once and throw it all to the second request(one row per virtual user(concurrency))

base: "https://targethostname"
concurrency: 100
iterations: 1

plan:
 - name: Getting csv data
     csv-file: cadastro-list.csv
     csv-row-assign: {{ concurrency }}
     assign: cadastro

 - name: "Criando um cliente iteration:{{ iteration }} user:{{ concurrency }}"
   request:
     url: /qa/wcs/resources/v1/customer/create
     method: POST
     body: "{{ cadastro }}"
     headers:
       Content-Type: "application/json"

That's what I'm currently trying to do and it's quite a useful feature, @fcsonline what do you think?

jrabello avatar May 27 '20 03:05 jrabello

Ok, now I understand a bit more the kind of test you want to achieve. I'll think about it to know which is the best and more flexible way to do it.

fcsonline avatar May 27 '20 07:05 fcsonline