Options: scenarios: executor: shared-iterations combined with parallel scenarios execution

How to combine this type of test:

export const options = {
    scenarios :{
        "use-all-the-data": {
        executor: "shared-iterations",
        iterations: testdata[0]["user"].length,
        maxDuration: "5s"
        }
    },
    tags: {
        project_name: 'PROJECT_NAME',
    }
}

with parallel execution for all testdata that I have

export default function testSuite(data) {
  describe("01. someMethod1 should return 200 OK and correct data", (t) => {
  ...
  })
  &&
  describe("02. someMethod2 should return 200 OK and correct data", (t) => {
  ...
  })
  &&
  describe("03. someMethod3 should return 200 OK and correct data", (t) => {
  ...
  });

so for one user from my testdata (SharedArray) describe-scenarios were executed sequentially in right order, but different users at the same time may run in parallel those sequential scenarios
?
P.S.: I know that expect.js deprecated and it is recommended to use ChaiJS lib, but, unfortunately, we don’t have much time to migrate current old code…
PP.S.: Sorry for my english (not native speaker) and, probably, for the bad grammar and, probably, for not very clear description… I’m in a rush (deadlines are near :sweat_smile:)
I’ll try to answer all necessary questions.

Hey @Crosby

I’m not entirely confident that I understand what you’re trying to achieve, but I’ll give it my best shot. My current understanding is:

  • You have a SharedArray containing some users’ test data
  • In the context of your k6 script default function, you write express.js tests to assert that your system behaves as expected.
  • You use a shared-iterations executor, as you wish to perform each of the tests described in your default function exactly once per user. Hence, your iterations count is the length of your test data SharedArray.

From this understanding, I believe a good alternative for your use case, might be to have multiple scenarios, one for each of your describe calls. Something along the lines of this:

import { check } from 'k6';
import { SharedArray } from 'k6/data';
import http from 'k6/http';

const testdata = new SharedArray('test data', function () {
  const dataArray = [{ name: 'usera' }, { name: 'userb' }, { name: 'userc' }];
  return dataArray;
});

export const options = {
  scenarios: {
    someMethod1: {
      executor: 'shared-iterations',
      iterations: testdata.length,
      exec: 'someMethod1',
    },
    someMethod2: {
      executor: 'shared-iterations',
      iterations: testdata.length,
      exec: 'someMethod2',
    },
    someMethod3: {
      executor: 'shared-iterations',
      iterations: testdata.length,
      exec: 'someMethod3',
    },
  },
};

export function someMethod1() {
  const res = http.get('https://httpbin.org/status/200');
  check(res, {
    'status is 200': (r) => r.status === 200,
  });
}

export function someMethod2() {
  const res = http.get('https://httpbin.org/status/201');
  check(res, {
    'status is 201': (r) => r.status === 201,
  });
}

export function someMethod3() {
  const res = http.get('https://httpbin.org/status/202');
  check(res, {
    'status is 202': (r) => r.status === 202,
  });
}

Here, each scenario will result in the function defined by the exec property being executed exactly N times (with N being the size of your test data), in parallel.

Let me know if that’s helpful :bowing_man:

1 Like

Thank you! Also helped your answer/solution from another topic with similar issue.

1 Like

Are those scenarios (someMethod1, someMethod2, someMethod3) will be executed sequentially if I specify several VUs ?

Actually, there’s one thing missing:

  • Those scenarios with SharedArray should be paralleled/run concurrently across specified amount of VUs
  • There’s also should be a way to run all of this (including above/mentioned_earlier preconditions/prerequisites) as a rumping-up scenario, e.g.: from 0 to specified amount of VUs (e.g.: to 1000s of VUs)

VUs act in a parallel fashion, indeed. You could observe it by replacing testData.length in the test script I posted with an arbitrarily large value like 1000. In your terminal, you would witness the three someMethod being updated in parallel :+1: