Send requests in Taurus once in several minutes

31 views Asked by At

I would like to test a simple scenario with the Taurus tool.

scenarios:
  getdata:
    requests:
      - url: https://myurl.com/auth
        method: POST
        label: auth
        body:
          username: my_usernmae
          password: my_password
        extract-jsonpath:
          auth_token: $.token
      - url: https://myurl.com/get-data
        method: GET
        headers:
          x-access-token: ${auth_token}
        label: getdata
        

Firstly, I need to send the /auth request and get the token.
Secondly, I need to pass this token as a header on a second request to get the data. The token lifetime is 5 minutes and it would be good to send the /auth request once in 5 minutes but not every time we get the data.

Is there any way to implement such a flow (send the first request once in 5 minutes)?

I tried to use the think-time option but it affects the second request as well and I do not need it.

1

There are 1 answers

1
Dmitri T On BEST ANSWER

I think the only option is going for 2 scenarios and passing the updated value of the token via file in the file system, something like:

scenarios:
  Scenario1:
    requests: 
      - url: https://myurl.com/auth
        method: POST
        label: auth
        body:
          username: my_usernmae
          password: my_password
        extract-jsonpath:
          auth_token: $.token
        jsr223:
          script-text: 'new File("myfile.txt").text = vars.get("auth-token")' 
          execute: after
  Scenario2:
    requests:
      - url: https://myurl.com/get-data
        headers: 
          x-access-token: ${auth_token}
        jsr223:
          execute: before
          script-text: 'vars.put("auth_token", new File("myfile.txt").text)'

This way you will be able to run requests with different throughputs.

More information: