-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Option to toggle the scenario run #2780
Comments
I find the possibility of executing specific scenarios a basic functionality of any testing platform. I don't have an strong opining here if the interface should allow selecting which to execute or which to exclude or both. I personally find this proposal of using an attribute in the scenario in conjunction with environment variables inconvenient because requires modifying the scenarios. I would prefer to add CLI parameters to
This same possibility could be added as an configuration option:
In practice, this feature could be implemented by setting the |
Hmm, if we were to document an "officially suggested" solution to this problem with the currently existing k6 versions, I wouldn't recommend the one from the OP, something like this looks much nicer: function filterScenarios(scenarios) {
// ... filter the scenarios however the user wants - by __ENV blocklist,
// by __ENV allowlist, by noRun property, whatever...
}
export const options = {
scenarios: filterScenarios({
scenario_1: {
// ...
},
// ...
})
}; This looks quite clean and can be as simple or as flexible as is required by the user and their use case... And given how easy it is to implement a However, both of the proposals share another problem - they use negative configuration. Besides, we don't actually have any way to configure scenarios from the CLI flags or environment variables. We left that for the future when we were originally implementing them, since it's quite tricky to cram such a complex configuration in a single string value... Maybe we can have both under the same flag 🤔 Something like this: k6 run --scenario "sc1" --scenario "sc2" script.js # run only sc1 and sc2
k6 run --scenario "scp*" # run only the previously configured scenarios that start with scp
k6 run --scenario "executor=per-vu-iterations,iterations=100,vus=5" # actually configure the scenario directly here This deserves quite a lot of thought, since I can see a bunch of problems with the proposal even as I make it. But, if we figure it out, it will bring much more value than just adding a blacklist to configure which scenarios should not be executed. |
I don't think more configuration options is the way. In my experience providing support, people don't know and can't find some of the current ones. So having more of them when we don't need them seems like making the problem worse, not easier. So making a blog post with how to do it with JS seems like a much better way forward. I have also mostly seen the case where people want to run one specific scenario, usually with 1 iteration (w/e that means for each executor). Usually in the context of trying to work on a specific scenario. This seems like a lot more complex (and impossible for some executors) thing to script in js and might be worth an option 🤷 . The current workaround is to extract its default function and run it with
I was left with the impression we left it because we don't want to implement it as it seems not very useful. It is very unlikely anyone will try to write more then 1 scenario in the CLI. And doing it in env variables is "supported" even now if you just write it as the json and then parse it in the script. But it does bring questions such as how do we merge scenario options ... which arguably already confuses people a lot see #2529. Again IMO adding more configuration options is not making things easier as it means we need to explain how they all work together. Having them in JS code removes (to some extend) that part by doing it in js code the user can see and in a place in the configuration merging that is known (the execution of the init context). |
@mstoykov Even though I understand your view, I am not convinced with this argument. I think useful APIs with proper docs are easier to discover and improve the day-to-day experience.
I am with @pablochacin here. I have updated the proposal to use |
Test skipping is something that can also be done with Go tests, but its purpose has generally been to temporarily disable some broken tests until you have time to fix or rewrite them. From what I can see by skimming the links @ppcano gave, this is the case for most other testing frameworks, and it makes a lot of sense in that context. However, that means we need to go back in our discussion and, before discussing how the solution should look like, first agree on what the problem we are trying to solve actually is 😅 Because the use case for these test skipping functions doesn't seem to be the same one we have in k6. This sentence from the OP doesn't describe the problem very well:
In my experience, there have often been at least 3 somewhat connected use cases that have caused users to want to do something like this:
Here are some forum topics I could find that corroborate this, though I am probably missing a bunch:
In short, it doesn't seem like skipping tests is what our users actually want. They kind of want the opposite, to be able to run only a specific sub-set of a larger test. Or, often, a sub-set of a larger test suite, so it's arguable if scenarios are even the right abstraction layer we need to concern ourselves with, "test suites" (#1342) might be a prerequisite for this feature... 🤔 And all of these frameworks that you linked to also have an abstraction that is a better match for the use cases described above, usually called something like
Though, again, even these are not a great fit for the current k6 capabilities, with single "tests" that may have multiple scenarios... 😞 At least until we implement test suites (#1342), k6 won't have the same semantics as other tools that use To conclude, I am still very much against adding a |
Workaround: This is not an efficient but works I have created two files and conditionally executing the test. |
I did this the other way around from OP as I always just want to run one scenario at a time:
|
Is any new about this? We have an API Owner that has multiple methods in his API. Each method has a different URL, and its load scenario is very different one from another. One can be called 60 times in a minute, and the other one can be called 1000 times in a minute. We have a k6 script which includes one function (and one scenario) per each method of the API. The API Owner is doing his development, and he only wants to test the method that is developing, not every method every time. Without the ability of choose which scenario we want to execute, we have to apply the workaround described above to select which scenario we want to execute. The alternative is having one script for each method, but we would have to create 2.000 scripts aprox... With JMeter it was very easy, just disabling the Thread Group. I think it is a basic functionality too. |
Inputs:I want to use k6 to do regression and performance testing in DRY. First, let's see if the endpoint is functional, then to do performance testing. Developer will start writing individual regression test cases and scenarios. I used the config to describe all different scenarios scenarios.json
But if I want to borrow scenario "scanOk" and want to run performance test with different parameters like vus, iterations ... etc. I can easily pass in as well. For example of running regression testing Or for running performance testing in one of the scenario I am hoping not to repeat the same scenario to do regression and performance; difference is the options only. |
@jochan-clgx your use case seems to be perfectly fine handled by having separate scripts that import the test function and set the options as in import {testFunction} from "./path/to/definitions.js"
export default testFunction;
export const options = {...}; And having separate such files for your different cases. And you can even have some that just import multiple and then run them together as one test. I don't really see how having the options have N scenarios where you will choose one of them will be more beneficial for your case. That is of course if I got your use case correct. The discussion here is more around cases where you have a script that usually runs 10 scenarios, but you want for this specific case to run 5 .. or 1 of them or something like that. What you are proposing is more a kin to a make file or something similar. And while I am not technically against it, I see very little benefit without also quite a lot of additional features to list you what you can run and so on and so forth ... a kin to a make file. |
I was looking for a way to pick exactly one scenario without much fuss and otherwise run either all of them or one specific default. While @bystedtpontus solution should work as well, I made somewhat simpler one (at least for me), without much changing the overall structure of test. I have this function in "utils.js" next to my test script: export function pickScenarioOrDefault(options, defaultScenario) {
const scenario = () => { return __ENV.SCENARIO || defaultScenario }
if (scenario()) {
options.scenarios = {
[scenario()]: options.scenarios[scenario()]
}
}
} then importing it from script: import { pickScenarioOrDefault } from "./utils.js"; and adding this bit directly under options: pickScenarioOrDefault(options, "constant_request_rate") Now running SCENARIO=debug k6 run ... would pick specific scenario, or if SCENARIO not provided - run default one. This feels somewhat more convenient for me, especially if one has several scripts. If you call it like this |
Feature Description
When using multiple scenarios, you might want to have a quick way to run the test with or without a particular scenario.
The suggested solution is to use environment variables to edit the scenarios object.
A dummy example:
Suggested Solution
Provide an scenario common option to toggle the scenario execution.
And/or using the CLI:
Already existing or connected issues / PRs (optional)
https://community.k6.io/t/how-to-execute-single-scenario-out-of-multiple-scenarios-in-a-script/1573
The text was updated successfully, but these errors were encountered: