Skip to content
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

Remove the unnecessary execution.Scheduler.Init() #2885

Merged
merged 2 commits into from
Jan 30, 2023
Merged

Conversation

na--
Copy link
Member

@na-- na-- commented Jan 30, 2023

This is the first commit from #2815, plus an extra test that checks the exit code when aborting a k6 run --paused test with Ctrl+C.

Unfortunately, it turned out that 19dd505 from #2813 introduced a regression. Interrupting the k6 process with a signal should result in a 105 exit code (ExternalAbort), but with that commit k6 exited with 103 if k6 was --paused. The good news is that the fix was already done in the first commit of #2815, which was entirely self-sufficient and can be moved to this separate PR. As a bonus, this makes reviewing everything even easier... 😅

So, some details about the commit itself... 😅 In short, there is no need to have 2 separate Run() and Init() methods in the execution.Scheduler. Instead, Run() can start the VU initialization itself. As a bonus, this immediately makes the error handling around init errors much more in line with other error handling, allowing us to resolve the bug, but also to respect --linger and to try and execute handleSummary() if there were problems. Except the first init that is used to get the exported options, of course, that one is still special.

@na-- na-- added this to the v0.43.0 milestone Jan 30, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #2885 (60c1026) into master (582ec4d) will decrease coverage by 0.21%.
The diff coverage is 96.15%.

@@            Coverage Diff             @@
##           master    #2885      +/-   ##
==========================================
- Coverage   76.75%   76.54%   -0.21%     
==========================================
  Files         225      223       -2     
  Lines       16807    16796      -11     
==========================================
- Hits        12900    12857      -43     
- Misses       3080     3105      +25     
- Partials      827      834       +7     
Flag Coverage Δ
ubuntu 76.54% <96.15%> (-0.06%) ⬇️
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
core/engine.go 83.75% <ø> (-1.62%) ⬇️
execution/scheduler.go 92.83% <96.15%> (+0.63%) ⬆️
loader/filesystems.go 60.00% <0.00%> (-40.00%) ⬇️
js/common/initenv.go 66.66% <0.00%> (-33.34%) ⬇️
api/v1/status_routes.go 32.65% <0.00%> (-26.54%) ⬇️
api/v1/metric.go 54.54% <0.00%> (-9.10%) ⬇️
cmd/tests/test_state.go 87.75% <0.00%> (-4.09%) ⬇️
lib/netext/httpext/error_codes.go 94.52% <0.00%> (-2.74%) ⬇️
lib/testutils/minirunner/minirunner.go 79.72% <0.00%> (-2.71%) ⬇️
js/initcontext.go 86.61% <0.00%> (-1.58%) ⬇️
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

execution/scheduler.go Outdated Show resolved Hide resolved
mstoykov
mstoykov previously approved these changes Jan 30, 2023
Copy link
Contributor

@mstoykov mstoykov left a 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 naming nitpick.

But to be honest I will likely need a day or two to remember all the intricacies, I knew, of this code to be certain that I don't forget about a corner case.

So I am hopeful that you working with it all the time means you would've caught it :P

There is no need to have 2 separate methods, Run() can start the VU initialization itself. As a bonus, this immediately makes the error handling around init errors much more in line with other error handling, allowing us to respect --linger and to try and execute handleSummary() if there were problems. Except the first init that is used to get the exported options, of course, that one is still special.
@na--
Copy link
Member Author

na-- commented Jan 30, 2023

But to be honest I will likely need a day or two to remember all the intricacies, I knew, of this code to be certain that I don't forget about a corner case.
So I am hopeful that you working with it all the time means you would've caught it :P

This whole sequence of 10+ PRs and tons of e2e tests has been mostly an attempt to simplify the old mess, so nobody has to remember all of its corner cases 😅 🤞 🙏

There is some unavoidable inherent complexity here, true, but most of the complexity before was accidental... 😞 That, coupled with all of the previously undefined behavior regarding exit codes and error handing (#2804), was a millstone around our neck - a huge piece of technical debt that we had to constantly work around... 😞

@na-- na-- merged commit 61ddf97 into master Jan 30, 2023
@na-- na-- deleted the remove-scheduler-init branch January 30, 2023 17:19
na-- added a commit that referenced this pull request Feb 2, 2023
This reverts a big part of #2885 because with all of the logic in Run(), k6 didn't know if it needed to wait when --linger was specified.

In general, if a script error or test.abort() occurs during init, --linger should not apply and k6 should exit immediately. But if test.abort() is called during the test run itself, or the test was stopped in some other way besides Ctrl+C, --linger means that k6 should not exit immediately after stopping the test.
na-- added a commit that referenced this pull request Feb 2, 2023
This reverts a big part of #2885 because with all of the logic in Run(), k6 didn't know if it needed to wait when --linger was specified.

In general, if a script error or test.abort() occurs during init, --linger should not apply and k6 should exit immediately. But if test.abort() is called during the test run itself, or the test was stopped in some other way besides Ctrl+C, --linger means that k6 should not exit immediately after stopping the test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants