Sequentially run scenarios

I have three tests which I want to run sequentially, after the one is completely done. I am using scenarios and I got it working, but as of now my tests are being run simultaneously.

I have been looking for quite a while now, without success. I get the feeling that I am completely overlooking the answer for this.

My code:

import runLoginTest from './loginTest.js'
import runGetCustomizationTest from './get-customizationTest.js'
import runGetCustomizationsTest from './get-customizationsTest.js'

export const options = {
  scenarios: {
    login_test: {
      executor: 'constant-vus',
      vus: 5,
      duration: '10s',
      gracefulStop: '0s',
      exec: 'loginTest',
    },
    get_customization_test: {
      executor: 'constant-vus',
      vus: 5,
      duration: '10s',
      gracefulStop: '0s',
      exec: 'getCustomizationTest',
    },
    get_customizations_test: {
      executor: 'constant-vus',
      vus: 5,
      duration: '10s',
      gracefulStop: '0s',
      exec: 'getCustomizationsTest',
    },
  },
}

export function loginTest () {
  runLoginTest()
}

export function getCustomizationTest () {
  runGetCustomizationTest()
}

export function getCustomizationsTest () {
  runGetCustomizationsTest()
}

Thank you for reading and for the help in advance.

See the startTime option in https://k6.io/docs/using-k6/scenarios

In your case, it’d go somewhat like this:


export const options = {
  scenarios: {
    login_test: {
      executor: 'constant-vus',
      vus: 5,
      duration: '10s',
      gracefulStop: '0s',
      exec: 'loginTest',
    },
    get_customization_test: {
      executor: 'constant-vus',
      vus: 5,
      duration: '10s',
      gracefulStop: '0s',
      exec: 'getCustomizationTest',
      startTime: '10s',  // duration + gracefulStop of the above
    },
    get_customizations_test: {
      executor: 'constant-vus',
      vus: 5,
      duration: '10s',
      gracefulStop: '0s',
      exec: 'getCustomizationsTest',
      startTime: '20s',  // duration + gracefulStop of the above
    },
  },
}
3 Likes

That does the job, thanks! Turns out I’ve been overlooking it all along.

1 Like

How can I run scenarios sequentially if I don’t want to configure a duration, but execute a fixed number of iterations for each scenario and then run the next one?

@jacob, unfortunately there’s no way to do that yet. We plan to eventually implement a startAfter property to allow you to chain scenarios like that, as described in https://github.com/loadimpact/k6/issues/1342. However, as you can see from the comments I made there regarding the implementation complexity, I can’t promise it will be any time soon.

For now, the best you can do is set a good approximate maxDuration of your iteration-based scenarios and calculating their startTime based on the maxDuration + gracefulStop of all preceding scenarios. Or, do things the old way, as separate k6 scripts you execute sequentially with a bash script or something like that.

thanks for the speedy reply @ned! i’ll find away around it for now.