Prior to v0.27.0, k6 would interrupt any iterations in progress when the test duration was reached or when scaling down VUs with the stages option. In some cases this would lead to skewed metrics and unexpected test results. Starting with v0.27.0, this behavior can be controlled through the gracefulStop and gracefulRampDown options.
This option is available for all executors except externally-controlled and allows the user to specify a duration to wait before forcefully interrupting them. The default value of this property is 30s.
Running this script would result in something like:
Notice that even though the total test duration is 10s, the actual execution time was 13s because of gracefulStop, giving the VUs a 3s additional time to complete iterations in progress. 23 of the iterations currently in progress did not complete within this window and was therefore interrupted.
A similar option exists for the ramping-vus executor: gracefulRampDown. This specifies the time k6 should wait for any iterations in progress to finish before VUs are returned to the global pool during a ramp down period defined in stages.