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

Dont share setup data #799

Merged
merged 11 commits into from
Oct 10, 2018
Merged

Dont share setup data #799

merged 11 commits into from
Oct 10, 2018

Conversation

mstoykov
Copy link
Contributor

@mstoykov mstoykov commented Oct 8, 2018

No description provided.

This removes the ability to change setupData between calls of the
default function. This removes a race condition where multiple VUs are
changin the setupData at the same time.
This change also makes certain that each call to the default function and
teardown get a setupData that has the same contents making it less
confusing if you change the setupData inside any of them for some reason.
The behaviour we want is if there is a setup function and it returns a
value it should be provided to the default function and the teardown.
Otherwise they should be provided with a null value.
@mstoykov mstoykov requested a review from na-- October 8, 2018 11:46
@CLAassistant
Copy link

CLAassistant commented Oct 8, 2018

CLA assistant check
All committers have signed the CLA.

js/runner.go Outdated
// the local executor further by deferring SetVUsMax() calls to within the Run() function.
if u.setupData == nil && u.Runner.setupData != nil {
u.setupData = u.Runtime.ToValue(u.Runner.setupData)
// Always unmarshall the setupData so that it doesn't change between calls
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I don't think that we should Unmarshal the setup data before each iteration, it seems like it would be a waste of CPU resources in the middle of the test, especially when the setup data is a big object. Using something similar to the old logic, where the setupData is injected before the beginning of the first iteration of a VU, should work better even when we decode it from JSON.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will mean that changes between iterations will be seen withing the same VU

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, shouldn't be an issue, since there couldn't be any data races that way. I think we shouldn't advertise it in the docs, since we might want to change it in the future, but it should be fine - other things in VUs stick around between iterations as well.


func testSetupDataHelper(t *testing.T, src *lib.SourceData) {
expScriptOptions := lib.Options{SetupTimeout: types.NullDurationFrom(1 * time.Second)}
r1, err := New(src, afero.NewMemMapFs(), lib.RuntimeOptions{Env: map[string]string{"expectedSetupTimeout": "1s"}})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectedSetupTimeout isn't actually used

require.NoError(t, err)
require.Equal(t, expScriptOptions, r1.GetOptions())

r2, err := NewFromArchive(r1.MakeArchive(), lib.RuntimeOptions{Env: map[string]string{"expectedSetupTimeout": "3s"}})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, expectedSetupTimeout seems like a copy-paste error. To be honest, I'm not sure if we actually need r2 at all. I know that a lot of the other tests make an archive from a script like this and test both, but not sure we need to do that everywhere, the only thing it would probably gain from it is extended test execution times.

return
}

r2, err := NewFromArchive(r1.MakeArchive(), lib.RuntimeOptions{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note about archives in this test as in the other - not sure testing both archives and scripts would help us catch any errors in this context.

js/runner_test.go Show resolved Hide resolved
Data: []byte(`
export let options = { setupTimeout: "1s", myOption: "test" };
export default function(data) {
if (data != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to be pedantically JS compatible, data should probably be undefined. goja supports it as easily enough - https://godoc.org/github.com/dop251/goja#Undefined

export let options = { setupTimeout: "1s", myOption: "test" };
export function setup() { }
export default function(data) {
if (data != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably data should be undefined here as well. This script prints undefined in browsers as well as node.js:

function f() { };
console.log(f());

Copy link
Member

@na-- na-- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codecov-io
Copy link

Codecov Report

Merging #799 into master will increase coverage by 0.07%.
The diff coverage is 69.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #799      +/-   ##
==========================================
+ Coverage   63.66%   63.74%   +0.07%     
==========================================
  Files         103      103              
  Lines        8464     8489      +25     
==========================================
+ Hits         5389     5411      +22     
- Misses       2714     2716       +2     
- Partials      361      362       +1
Impacted Files Coverage Δ
lib/runner.go 0% <0%> (ø) ⬆️
stats/dummy/collector.go 60% <100%> (ø) ⬆️
js/runner.go 78.96% <65.21%> (-0.3%) ⬇️
api/v1/setup_teardown_routes.go 63.82% <81.25%> (+8.56%) ⬆️
js/modules/k6/ws/ws.go 72.54% <0%> (+0.4%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 94bbc7f...d716089. Read the comment docs.

@na-- na-- merged commit c4618de into master Oct 10, 2018
@na-- na-- deleted the dontShareSetupData branch October 10, 2018 14:52
na-- added a commit that referenced this pull request Oct 10, 2018
mstoykov added a commit that referenced this pull request Feb 11, 2020
as in #799(which was about the same issue with setup data), we
don't actually have problems with a VU seeing changes from
previous iterations. It will be too expensive to constantly copy, it
won't panic and there are no issues with distributed execution.
mstoykov added a commit that referenced this pull request Feb 11, 2020
as in #799(which was about the same issue with setup data), we
don't actually have problems with a VU seeing changes from
previous iterations. It will be too expensive to constantly copy, it
won't panic and there are no issues with distributed execution.
mstoykov added a commit that referenced this pull request Feb 17, 2020
as in #799(which was about the same issue with setup data), we
don't actually have problems with a VU seeing changes from
previous iterations. It will be too expensive to constantly copy, it
won't panic and there are no issues with distributed execution.
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