K6 API test scenario

Hello!

I was wondering is it possible to create a test flow where first you make request to API (a), then you wait to get response and continue to make request on second API (b), again wait for response and continue to API (c) ?

I did see “scenarios” capability but I am not sure if that is what I am looking for. Or maybe I have misunderstood it :question:

Hi @sillymoomoo

It is indeed possible. Have a look at the example Advanced API flow. Or the similar example in our test API: https://test-api.k6.io/, under “Sample HTTP API test script”. You’ll see that we have the same user (VU) doing several “chained” calls.

I hope this helps :bowing_woman:

Cheers!

Hi!

So I suppose I would need to use describe block for each Endpoint separately to imitate flow of a user :thinking: , I think that was your suggestion ?

Also I was thinking, how can I make so the second API call does not begin until first one ends ?
I tried with describe blocks, doesnt seem to work that way :frowning:

hey @eyeveebe
After experimenting for quite a bit I believe that using scenario capabilities + describe blocks allows me to create a flow for endpoints to be tested simultaneously :slight_smile: what I did was for scenarios:

  flowTests: {
    scenarios: {
      test_suite_one: {
        executor: 'constant-vus',
        vus: 5,
        duration: '10s',
        exec: 'testSuiteOne'
      },
    },
    thresholds: {
      http_req_duration: [
        {
          threshold: 'avg<1000', // if http req duration is avg over 2000, test aborts
          abortOnFail: true // abort test if thresholds breached use true
          // delayAbortEval: '5s' // delay of abort so data can be gathered in metrics
        }
      ],
      http_req_failed: [
        {
          threshold: 'rate<0.01', // During the whole test execution, the error rate must be lower than 1%.
          abortOnFail: true // abort test if thresholds breached use true
          // delayAbortEval: '5s' // delay of abort so data can be gathered in metrics
        }
      ]
    }
  }

And for actual script:

export function testSuiteOne(data) {
  describe('First API Call', () => {
    const response = http.get(Configuration.urlGetApi, data.data);
    check(response, {
      'status is 200': (r) => r.status === 200
    });

    timeGauge.add(new Date() - new Date(exec.scenario.startTime)); // retuns in summary the amount of time test ran

    sleep(1); // After each user pause for 1 sec to see how many calls can be done for API within duration
    console.log('First API Call');
  });
  describe('Second API Call', () => {
    const response = http.get(Configuration.urlGetApi2, data.data);
    check(response, {
      'status is 200': (r) => r.status === 200
    });

    timeGauge.add(new Date() - new Date(exec.scenario.startTime)); // retuns in summary the amount of time test ran

    sleep(1); // After each user pause for 1 sec to see how many calls can be done for API within duration
    console.log('Second API Call');
  });
}

And here I get result where first time 5 VU’s make request to first API and then 5 VU’s make request to second API.

However how can I be sure that first endpoint call actually went through to the end and only then the second call started?