-
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
Add JS function to abort test #2093
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2093 +/- ##
==========================================
- Coverage 72.11% 72.01% -0.10%
==========================================
Files 180 181 +1
Lines 14249 14319 +70
==========================================
+ Hits 10275 10312 +37
- Misses 3348 3375 +27
- Partials 626 632 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Lint errors are from #2073, so ignore :) And there are currently no tests for this, since they were all at the JS level and were moved to the extension (mostly). Should we add some lower level tests here? |
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 didn't understand why you need to use my WIP PRs to test it?
Apart from that and the error comment it seems okay to me
Because |
87b85d6
to
913c0bf
Compare
b899f9e
to
314e25c
Compare
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.
LGTM apart from the possible change to showing the summary
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.
LGTM in principle, but I didn't review this very deeply, mostly relied on my memories from reviewing the old PR 😅
cmd/run.go
Outdated
if runErr != nil { | ||
if common.IsInterruptError(runErr) { | ||
return errext.WithExitCodeIfNone(runErr, exitcodes.ScriptException) | ||
} | ||
return errext.WithExitCodeIfNone(runErr, exitcodes.GenericEngine) |
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.
this also changes that we will show the summary on non InterruptError which probably is not what we want
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.
No? I did that intentionally as I don't see why we shouldn't show the summary in all cases.
I'll leave this as is, but you guys feel free to change it before merging.
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 see some merit to showing the summary in more cases but I think this is kind of a bigger and different change so I would prefer to have it outside of this PR
cc @na--
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 removed this in the latest force push, so now only interrupt errors should show the summary.
2381b70
to
06cc52f
Compare
06cc52f
to
710cfed
Compare
@codebien I wanted to keep the original commit mostly intact, as it was authored by gernest. The changes on top of it are mostly atomic new features and shouldn't be squashed, but I can rebase it on current |
Co-authored-by: Ivan Mirić <[email protected]> Closes #1001 This adds abortTest() helper function to the k6 module. This function when called inside a script it will - stop the whole test run and k6 will exit with 107 status code - stops immediately the VU that called it and no more iterations are started - make sure the teardown() is called - the engine run status is 7 (RunStatusAbortedScriptError) `(*goja.Runtime).Interrupt` is used for halting script execution and capturing stack traces for better error message of what is happening with the script. We introduce InterruptError which is used with `(*goja.Runtime).Interrupt` to identify interrupts emitted by abortTest(). This way we use special handling of this type. Example script is ```js import { abortTest, sleep } from 'k6'; export default function () { // We abort the test on second iteration if (__ITER == 1) { abortTest(); } sleep(1); } export function teardown() { console.log('This function will be called even when we abort script'); } ``` abortTest() can be called in both default and setup functions, however you can't use it in the init context The following script will fail with the error ``` ERRO[0000] Using abortTest() in the init context is not supported at (...path to the script )init.js:13:43(34) ``` ```js import { abortTest } from 'k6'; abortTest(); export function setup() { } export default function () { // ... some test logic ... console.log('mayday, mayday'); } ``` You can customize the reason for abortTest() by passing values to the function ```js abortTest("Exceeded expectations"); ``` Will emit `"Exceeded expectations"` on the logs
This is needed to be able to read the test run status via the API, e.g. in the Cloud.
This ensures we exit with code 108 (ScriptAborted) in all places where it might be called from.
ae7aaee
to
dfab9bf
Compare
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.
5 months later and almost 9 months since #1920, we're finally merging this! 😅 It's a Christmas miracle! 😄🎄 Thanks for the reviews everyone! I'll try to add some documentation for this next week. Actually, spoke too soon... The CLA not passing is blocking it 🤦♂️ Anyone know how to retrigger it? Or should we just merge this manually? Ah, it won't pass because gernest hasn't signed the new CLA. Since he did sign the previous one and the new one just has branding changes, should we manually merge this or ping him here? |
He signed the old CLA in #1920 (comment), which is basically identical to the current one for k6 (the new one only expands to cover other xk6 projects), so it's fine to merge as it is. |
Hey all, Have found my way onto this PR as a result of looking for the ability to abort k6 execution with non-zero exit code. I appreciate the efforts required to develop these changes, so thank you for building on top of suggestions/requests coming from users. I was just wondering, although this functionality is merged to master I don't believe it is available in an official version yet right? If not, are there currently any estimations as to when this may occur? Thanks again UPDATE 20220128: I see this is now released under v0.36.0. Tyvm |
These are the changes from #1920, squashed and rebased on
master
, while changing the function fromk6.abortTest()
to thek6/execution
module astest.abort()
. Additionally a newExecutionStatusInterrupted
was added, a separate exit code (108), and a few other fixes and minor changes. See the commits for details.Closes #1001