Setting the test duration

I’m having a hard time defining the duration of a test, it always shows maxDuration of 10m.

I use the following code to define the k6 options, but for some reason the duration and scenarios don’t take effect:

export const options = {
  duration: "60s",
  scenarios: {
    s1: {
      executor: "per-vu-iterations",
      gracefulStop: "0s",
      maxDuration: "80s",
    },
  },
  insecureSkipTLSVerify: true,
  thresholds: {
    "checks{myTag: authenticate}": ["rate==1.0"],
    "checks{myTag: book-update}": ["rate>=0.9"],
    "checks{myTag: historical-orders}": ["rate==1.0"],
    "checks{myTag: historical-partials}": ["rate==1.0"],
    "checks{myTag: historical-shadow}": ["rate==1.0"],
    "checks{myTag: historical-viewers}": ["rate==1.0"],
    "checks{myTag: login}": ["rate==1.0"],
    "checks{myTag: today-orders}": ["rate==1.0"],
    "checks{myTag: today-shadow}": ["rate==1.0"],
    "checks{myTag: user-settings}": ["rate==1.0"],
    "checks{myTag: user-widgets}": ["rate==1.0"],
    "checks{myTag: user-information}": ["rate==1.0"],
    "checks{myTag: ws_auth}": ["rate==1.0"],
    "checks{myTag: ws connect}": ["rate==1.0"],
  },
};

...

export default function () {
  console.log(JSON.stringify(exec.test.options));
  console.log(JSON.stringify(options));
}

The output is as follows:

  execution: local
     script: k6_test/ws_v1.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations shared among 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0002] {"paused":null,"scenarios":{"default":{"executor":"shared-iterations","startTime":null,"gracefulStop":null,"env":null,"exec":null,"tags":null,"vus":1,"iterations":1,"maxDuration":null}},"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpDebug":null,"insecureSkipTLSVerify":true,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"throw":null,"thresholds":{"checks{myTag: authenticate}":["rate==1.0"],"checks{myTag: book-update}":["rate>=0.9"],"checks{myTag: historical-orders}":["rate==1.0"],"checks{myTag: historical-partials}":["rate==1.0"],"checks{myTag: historical-shadow}":["rate==1.0"],"checks{myTag: historical-viewers}":["rate==1.0"],"checks{myTag: login}":["rate==1.0"],"checks{myTag: today-orders}":["rate==1.0"],"checks{myTag: today-shadow}":["rate==1.0"],"checks{myTag: user-information}":["rate==1.0"],"checks{myTag: user-settings}":["rate==1.0"],"checks{myTag: user-widgets}":["rate==1.0"],"checks{myTag: ws connect}":["rate==1.0"],"checks{myTag: ws_auth}":["rate==1.0"]},"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg","min","med","max","p(90)","p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"localIPs":null}  source=console
INFO[0002] {"duration":"60s","scenarios":{},"insecureSkipTLSVerify":true,"thresholds":{"checks{myTag: today-orders}":["rate==1.0"],"checks{myTag: user-settings}":["rate==1.0"],"checks{myTag: user-widgets}":["rate==1.0"],"checks{myTag: ws connect}":["rate==1.0"],"checks{myTag: login}":["rate==1.0"],"checks{myTag: today-shadow}":["rate==1.0"],"checks{myTag: authenticate}":["rate==1.0"],"checks{myTag: book-update}":["rate>=0.9"],"checks{myTag: historical-orders}":["rate==1.0"],"checks{myTag: historical-viewers}":["rate==1.0"],"checks{myTag: user-information}":["rate==1.0"],"checks{myTag: historical-partials}":["rate==1.0"],"checks{myTag: historical-shadow}":["rate==1.0"],"checks{myTag: ws_auth}":["rate==1.0"]},"vus":1,"iterations":1,"summaryTrendStats":["avg","min","med","max","p(90)","p(95)"],"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"]}  source=console

Note that the scenarios object is empty in options even though it has been assigned, so it appears to have been modified during k6 execution. It is also a different value in exec.test.options than what was assigned.

Other than passing –duration from CLI, how can I set these duration options?

Note - the real purpose of this is to extend the total test time above the maxDuration, i.e., 30 minutes, and it doesn’t seem to work!

Hi @hptabster !

I believe the result you’re seeing can be caused by mixing the flags and options.

First of all, I’d like to ask you what version of the k6 you are using? Because using the latest k6 (and several more previous), the code with the options of your script should return the following error:

ERRO[0000] using an execution configuration shortcut (`duration`) and `scenarios` simultaneously is not allowed

Note that the scenarios object is empty in options even though it has been assigned, so it appears to have been modified during k6 execution. It is also a different value in exec.test.options than what was assigned.

Yes, that’s possible for example, if you’re passing the flags.

Like in your example, the executor can be switched to a shared-iterations if pass an Iterations flag --iterations,-i since it’s a shortcut for a single scenario with a shared iterations executor.

The same applies to a duration flag which is a shortcut to a single scenario with a constant VUs executor.

So if you run your script without any flags, it should provide the desired outcome:

k6 run test-time.js

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: test-time.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 1m20s max duration (incl. graceful stop):
           * s1: 1 iterations for each of 1 VUs (maxDuration: 1m20s)

INFO[0000] {"paused":null,"scenarios":{"s1":{"executor":"per-vu-iterations","startTime":null,"gracefulStop":"0s","env":null,"exec":null,"tags":null,"vus":null,"iterations":null,"maxDuration":"1m20s"}},"executionSegment":null,"executionSegmentSequence":null,"noSetup":null,"setupTimeout":null,"noTeardown":null,"teardownTimeout":null,"rps":null,"dns":{"ttl":null,"select":null,"policy":null},"maxRedirects":null,"userAgent":null,"batch":null,"batchPerHost":null,"httpDebug":null,"insecureSkipTLSVerify":true,"tlsCipherSuites":null,"tlsVersion":null,"tlsAuth":null,"throw":null,"thresholds":{"checks{myTag: authenticate}":["rate==1.0"],"checks{myTag: book-update}":["rate>=0.9"],"checks{myTag: historical-orders}":["rate==1.0"],"checks{myTag: historical-partials}":["rate==1.0"],"checks{myTag: historical-shadow}":["rate==1.0"],"checks{myTag: historical-viewers}":["rate==1.0"],"checks{myTag: login}":["rate==1.0"],"checks{myTag: today-orders}":["rate==1.0"],"checks{myTag: today-shadow}":["rate==1.0"],"checks{myTag: user-information}":["rate==1.0"],"checks{myTag: user-settings}":["rate==1.0"],"checks{myTag: user-widgets}":["rate==1.0"],"checks{myTag: ws connect}":["rate==1.0"],"checks{myTag: ws_auth}":["rate==1.0"]},"blacklistIPs":null,"blockHostnames":null,"hosts":null,"noConnectionReuse":null,"noVUConnectionReuse":null,"minIterationDuration":null,"ext":null,"summaryTrendStats":["avg","min","med","max","p(90)","p(95)"],"summaryTimeUnit":null,"systemTags":["check","error","error_code","expected_response","group","method","name","proto","scenario","service","status","subproto","tls_version","url"],"tags":null,"metricSamplesBufferSize":null,"noCookiesReset":null,"discardResponseBodies":null,"consoleOutput":null,"localIPs":null}  source=console

Let me know if that helps,
Cheers

k6 version
k6 v0.38.3 ((devel), go1.18.2, darwin/amd64)

@olegbespalov Actually I’m a bit more confused…Now if I do not specify the “-i” option, the “-u” option value is ignored…how can I scale up the number of users and still use the scenarios object? Before I had to specify something like “-u 50 -i 50” to get 50 users.

Just define it there :smile:

scenarios: {
    s1: {
      executor: "per-vu-iterations",
      gracefulStop: "0s",
      vus: 50,
      iterations: 20,
      maxDuration: "80s",
    },
  },
1 Like

Thanks, I did get that figured out, so I will be passing in an environment variable to set it:

const k6Options = {
  scenarios: {
    s1: {
      vus: parseInt(__ENV.TEST_USERS) || 1,
      executor: "per-vu-iterations",
      gracefulStop: "0s",
      maxDuration: `${TIMERS.testTime + 5}s`,
    },
  },
...
1 Like