You have a good summary of exactly what it takes to calculate the max duration of the test run. A couple of minor points though:
Setup() duration is variable and not included. This should mostly be negligible assuming that this doesn’t take more than a couple of minutes.
You can restrict max setup()
and teardown()
times with the setupTimeout
and teardownTimeout
options, which will give you an upper bound in your calculations.
§ Non-scenario profiles:
â–ˇ Sum(stages.duration)
â–ˇ Duration
After k6 v0.27.0, every k6 run is running one or more scenarios, each with a specific executor. The top-level duration
, iterations
and stages
options are just shortcuts to running a single-scenario test run with the specific executor that corresponds to the option (see the docs for which it is). So even they have gracefulStop
, it’s just the default one of 30s.
So, yeah… calculating the total test duration is a bit complex. We plan to add some helper functions to get this type of execution information inside of the scripts, and I made a note about this use case specifically: Improve execution information in scripts · Issue #1320 · k6io/k6 · GitHub
Until that lands though, you either have to re-implement the Go logic that exists in k6 in JavaScript, or you’d have to write an use an xk6 extension (more info) and then use k6 as a library and call the same functions we do to calculate the max duration internally.