-
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
sleep() ignored when there's a JS error #688
Comments
I've hit this issue before, only it was with an exception I was trowing. I think you can import { sleep } from 'k6';
export default function () {
console.log("Iteration...");
try {
someNonsense
}
catch (err) {
console.warn(err);
}
sleep(3);
} I don't have a good idea how to fix this by default though. Introducing some sort of minimum iteration time that's enforced by k6 (i.e. after a VU iteration ends in Edit: just to be clear, |
Makes sense. And catching the error, or fixing it if possible, is the best way. Though I found it a bit unintuitive so to say, that the execution continues after an exception/error:
In retrospect, it's as you wrote, the script is just interrupted on every iteration. In my head the script corresponded to the test, so I expected the entire test to fail alltogether if it encountered an exception/error. How about an option parameter that makes the test execution abort in case of a script exception/error? |
Edit: nevermind, I totally misread what you wrote... |
I think such an option has a lot of merit, but the tricky question is whether it should be enabled by default. If it is disabled by default, we're back to square one - if you know you can hit this issue with exceptions causing "instantaneous" iterations and want to guard against it, you can just use a global If it is enabled by default, writing tests can become a lot more complicated. You'd have to very carefully guard and null-check everything. Especially code that parses and uses data from the responses of the tested website, which may become unreliable under the heavy load. In a way, enabling this behavior by default could potentially cause people to have the opposite global |
I hadn't thought of a global try-catch plus threshold as a workaround :), that's cool. Not the prettiest workaround, but it's a workaround. Yeah, having it enabled by default is very bad imo and can lead to bad things, as you wrote, when working with response data. So a setting like that should definitely be off by default. |
Closing this issue, since one of the solutions discussed here (minimum iteration duration) was implemented in this pull request and was released as part of k6 0.23.0. I also created a new, separate issue for the other idea partially mentioned above (and in a few other places): #877 |
The sleep() function is getting ignored when the JS code in the script produces an error during runtime.
Example:
script.js:
Output:
Compared to code that does not produce an error:
script.js:
Output:
This is a trivial example, but the problem has been causing quite the hassle in more complex scripts. For example, when the test parameter isn't iteration, but duration. Judging by the iteration rate above, the output can spam 4623 error messages in 1 second.
The text was updated successfully, but these errors were encountered: