-
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
setup
and teardown
methods
#194
Comments
This has been talked about before, but was shut down… I can't entirely remember why though? @ragnarlonn @robingustafsson |
It could very well be done by a test management framework/tool controlling the test execution outside of k6 where k6 is only the execution of the test. The principle is sound - but it might not belong inside k6? More an implementation sample using some reasonable test management framework/tool? |
As a user, I see the feature to be a
@micsjo My doubt is if this feature is useful (demanded feature) when load testing some systems. I may be wrong when doing the analogy with other test frameworks. |
I got more requests for this when demoing k6 to a group of people a week or so ago. What about something like this: export let options = {
lifecycle: {
setup: setupFun,
teardown: teardownFun
}
};
function setupFun() {
...
}
function teardownFun() {
...
}
export default function() {
...
} In the case of local execution these would execute once. In the case of distributed execution it could be executed once on each node/server unless user uses env vars or similar to limit it to one node/server or region. Thoughts? |
Could work, alternatively something like: export function setup() {
// ...
}
export function teardown() {
// ...
}
export function default() {
// ...
} I don't think they should be run per-instance though, their primary use will be in setting up test databases, etc. and it doesn't make sense to do that multiple things, nor does it really matter where it's done from. |
@liclac Yeah, that looks like a better API, will make sure setup/teardown function always has the same name. Agree that we should start with most common use case and iterate from there, so start with running it global-once (in a distributed/cloud context). I guess it will require some additional flag being added to the CLI like |
If users want to perform some initializations routines, they may need to perform requests to their systems and wait for the task completion to start the load test execution. Is this an issue? Thoughts?
|
There's no asynchrony in k6, things run and return when finished. |
Perfect, go ahead! I am looking forward seeing how users will make use of this feature. |
After some offline discussion the following API was proposed: export function setup() {
let setupData = ...;
return JSON.stringify(setupData); // return valid JSON string
}
export function teardown() {
// ...
}
export function default(setupData) {
let parsedSetupData = JSON.parse(setupData);
// ...
} This API seems to work well for both the local as well as cloud/clustered execution contexts, as it'd let k6 execute the @liclac @ppcano @martinfijal Did I miss anything from the discussion we had regarding this issue? |
There's not even a need for I'll also introduce warnings for unrecognised exports, now that we're ending up with a few more. |
I want to give some input on a nice use case for this. Currently our project has the following structure:
The idea is like this:
Example export default {
someUrl: 'http://example.com'
} description/test.js: export default function ({ someUrl }){
http.get(someUrl);
} execution/qa/test.js: import description from '../../description/test.js';
import context from '../../context/qa.js';
export default () => description(context); The |
Last day, I had a similar situation when discussing environment variables. I am not sure if this solves your case but, what about the following structure?
Now, you could easily change the script context with environment variable like:
In the case that you want your context settings in different files, you could also modify your |
@ppcano interesting approach. However, one of the things I want to accomplish is that the |
When running a test, it's a common practice to prepare the system under test. For example, database setup or data population are common actions to perform before a test begins.
I think it may be useful to provide an API to support the
setup
case, and additionally theteardown
API.Because the async nature of http requests, the
setup
callback could accept to return an async request or promise object to start the test after its completion.Below an example (not a proposal) to show the idea:
Thoughts?
The text was updated successfully, but these errors were encountered: