-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added example for running specific scenario via cli #1762
base: main
Are you sure you want to change the base?
Changes from all commits
ac40093
a9faa2b
e34f27d
cbc7f1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -201,3 +201,64 @@ export function apitest() { | |||||
``` | ||||||
|
||||||
{{< /code >}} | ||||||
|
||||||
## Run specific scenario via environment variable | ||||||
|
||||||
Utilizing an [environment variable](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/environment-variables/#environment-variables) and a bit of code, you can run a specific scenario via command line as opposed to running all configured scenarios. By default, [k6 runs all scenarios listed in a file](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/scenarios/#scenarios). | ||||||
|
||||||
The following provides an example of how to add the ability to run a specific scenario among multiple configured scenarios: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{{< code >}} | ||||||
|
||||||
```javascript | ||||||
import http from 'k6/http'; | ||||||
|
||||||
const scenarios = { | ||||||
my_web_test: { | ||||||
executor: 'per-vu-iterations', | ||||||
vus: 1, | ||||||
iterations: 1, | ||||||
maxDuration: '30s', | ||||||
}, | ||||||
my_api_test: { | ||||||
executor: 'per-vu-iterations', | ||||||
vus: 1, | ||||||
iterations: 1, | ||||||
maxDuration: '30s', | ||||||
}, | ||||||
}; | ||||||
|
||||||
const { SCENARIO } = __ENV; | ||||||
export const options = { | ||||||
// if a scenario is supplied via cli env, then run that scenario. Otherwise, run like normal | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// using the pre-configured scenarios above. | ||||||
scenarios: SCENARIO ? { [SCENARIO]: scenarios[SCENARIO] } : scenarios, | ||||||
discardResponseBodies: true, | ||||||
thresholds: { | ||||||
http_req_duration: ['p(95)<250', 'p(99)<350'], | ||||||
}, | ||||||
}; | ||||||
|
||||||
export default function () { | ||||||
const response = http.get('https://test-api.k6.io/public/crocodiles/'); | ||||||
} | ||||||
``` | ||||||
|
||||||
{{< /code >}} | ||||||
|
||||||
Alternatively, slightly modifying this approach, it can instead be used as a skip feature. Reading from the custom environment variable allows calling a specific scenario via command line: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think we can just give an instruction for the user as to how they can execute this from the command line. If we want to mention using this as a skip feature, I think we should do it after the command line examples, or in the first section. |
||||||
|
||||||
{{< code >}} | ||||||
|
||||||
```bash | ||||||
$ SCENARIO=my_web_test k6 run script.js | ||||||
``` | ||||||
|
||||||
```windows | ||||||
C:\k6> set "SCENARIO=my_web_test" && k6 run script.js | ||||||
``` | ||||||
|
||||||
```powershell | ||||||
PS C:\k6> $env:SCENARIO="my_web_test"; k6 run script.js | ||||||
``` | ||||||
|
||||||
{{< /code >}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we change the order of the sentences here, it might be a little bit easier to read.