You can use multiple scenarios in one script, and these scenarios can be run in sequence or in parallel. Some ways that you can combine scenarios include the following:
- Have different start times to sequence workloads
- Add per-scenario tags and environment variables
- Make scenario-specific thresholds.
- Use multiple scenarios to run different test logic, so that VUs don't run only the default function.
Combine scenarios
With the startTime property, you can configure your script to start some scenarios later than others. To sequence your scenarios, you can combine startTime with the duration options specific to the executor. (this is easiest to do with executors with set durations, like the arrival-rate executors).
This script has two scenarios, contacts and news, which run in sequence:
- At the beginning of the test, k6 starts the contacts scenario. 50 VUs try to run as many iterations as possible for 30 seconds.
- After 30 seconds, k6 starts the news scenario. 50 VUs each try to run 100 iterations in one minute.
Along with startTime, duration, and maxDuration, note the different test logic for each scenario.
Use different environment variables and tags per scenario.
The previous example sets tags on individual HTTP request metrics. But, you can also set tags per scenario, which applies them to other taggable objects as well.
noteBy default, k6 applies a scenario tag to all metrics in each scenario, whose value is the scenario name. You can combine these tags with thresholds, or use them to simplify results filtering.
To disable scenario tags, use the --system-tags option.
Run multiple scenario functions, with different thresholds
You can also set different thresholds for different scenario functions. To do this:
- Set scenario-specific tags
- Set thresholds for these tags.
This test has 3 scenarios, each with different exec functions, tags and environment variables, and thresholds: