When I specify vus or duration in k6, the default scenario is executed

■ Test Environment
Local: k6 version 0.44.1
Github Actions: grafana/k6-action@v0.2.0

~~~~
export let options = {
  scenarios: {
    getExample: {
      executor: "constant-vus",
      vus: 1,
      duration: "3s",
      exec: "getExample",
      startTime: "0s",
    },
};
export default function () { }

I would like to specify vus and duration for the above scenario to be executed.
However, if vus or duration is optionally passed and executed, the exec specification is ignored. As a result, the default function is executed and the test is not executed.

verbose log

  • OK (scenario=getExample)

k6 run main.js
DEBU[0000] Starting executor run… duration=3s executor=constant-vus scenario=getExample type=constant-vus vus=1

  • Bad(scenario=default)

k6 run --vus 1 --duration 10s main.js
DEBU[0000] Starting executor run… duration=10s executor=constant-vus scenario=default type=constant-vus vus=1

If you specify getExample() in the function default, it will be executed, but this was not a good approach because we want to run multiple scenarios in parallel.

Could you please advise me on this?

Hi @Scble

Welcome to the community forum :wave:

When using duration as a CLI flag, you are actually using a shortcut for a single scenario with constant vus. You won’t be able to create more scenarios using that. And there is no way to specify the exec via CLI, so it takes the default. I find this a bit confusing as well so I’ll discuss this with the devs team.

Have a look at the options order of preference, and the options reference for more details.

If I understand correctly, this is similar to what we discussed in How to specify `rate` on CLI - #3 by immavalls2. Support for configuring scenarios via CLI flags is very limited, and it’s probably causing this unexpected behavior.

If you want to inform vus and duration for several scenarios, I would create custom environment variables to pass those and replace in the options. If you plan to have more than one scenario, the CLI flag won’t work for you anyway, and the issue to implement this is a bit complex: Support Scenarios in the CLI options · Issue #3054 · grafana/k6 · GitHub

I hope this helps :bowing_woman:

Cheers!

1 Like

Hi @eyeveebe ,

Thanks for the advice !!
I see, so that’s how it was. I didn’t understand the documentation well enough…
That is exactly what I am doing now to avoid the problem by replacing it with an environment variable.

It was really helpful.

1 Like