Procedure of running K6 script

Dear madam/sir,

I have one question about the K6 js script running procedure, first of all, please see below of my code:

      response = http.post(*
      apiUrl + "/v1/alarms/summary",
      globalNetworkFilterString,
      {
        headers: {*
          accept: "application/json",
          //authorization: authString,
          "content-type": "application/json",
          requestcacheid: "",
          tenant: tenant,
        },
      }
    );
    sleep(5);

    response = http.post(
      apiUrl + "/v1/alarms/summary",
      globalNetworkFilterString,
      {
        headers: {
          accept: "application/json",
          //authorization: authString,
          "content-type": "application/json",
          requestcacheid: "",
          tenant: tenant,
        },
      }
    );

As you see, I have two post queries in my code, when I execute this script, the first post will be sent to server, then wait for the first post’s response, after the response is received(or timeout for 60s), sleep 5 seconds, and then send out the second post query, wait for the second response and ends.
Is this the correct procedure?
I think there is no way that after sending out the first post, doesn’t wait for its response and send out the second post immediately, right?
Could you please help to reply me?

Thanks,
Ken

Hi @Ken

If I understood correctly, you might be looking for batch requests. Or the asyncRequest method (waiting for all promises). Both would probably work for you, depending on what you try to reproduce with the test.

I hope this helps.

Cheers!

Hi, eyeveebee,

Thank you for your reply.
The code I mentioned in the topic is what I record from manual behavior.
And I want to make sure it is syncRequest as the procedure I said

Thanks,
Ken

Hi @Ken

To your initial questions, maybe my answer was not clear enough.

Is this the correct procedure?

Yes, if this is what you want to do: send a request, wait for the response, sleep 5 seconds, send another request, wait for the response. Each virtual user iteration would do that.

If the code is recorded from manual behavior this would be correct. The requests will wait for a response (or Params.timeout which defaults to 60 seconds).

My confusion is with the second sentence:

I think there is no way that after sending out the first post, doesn’t wait for its response and send out the second post immediately, right?

To what my response applies. You can send both requests in a batch, and do the sleep after that (if you want to simulate a sleep). Or use async/await and wait of all the responses.

I hope this helps clarify.

Cheers!