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

Unify duration configuration values #1738

Merged
merged 1 commit into from
Dec 1, 2020
Merged

Unify duration configuration values #1738

merged 1 commit into from
Dec 1, 2020

Conversation

na--
Copy link
Member

@na-- na-- commented Nov 25, 2020

This should close #1305

@na-- na-- requested review from mstoykov and imiric November 25, 2020 10:05
Comment on lines +267 to +276
case time.Duration:
return d, nil
case string:
return ParseExtendedDuration(d)
case float32:
return time.Duration(float64(d) * float64(time.Millisecond)), nil
case float64:
return time.Duration(d * float64(time.Millisecond)), nil
default:
n, err := getInt64(v)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are any beside time.Duration, string, float64 and int64 ... even possible? Because the previous code didn't handle the rest, and I have the feeling that was because we will never actually get one ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added them out of an abundance of caution... I have no idea if some weird webpack minification magic or something like that won't try to encode plain integer values as something that goja will export as uint8 or whatever... Stranger things have happened... 😅 And given that this helper function is intentionally outside of js/, I also think it makes some sense to handle the other Go int native types. This way the function is more complete and can basically convert every possible value we can recognize as a time.Duration to that, no need to second-guess.

imiric
imiric previously approved these changes Nov 26, 2020
Copy link
Contributor

@imiric imiric left a comment

Choose a reason for hiding this comment

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

LGTM, but have you tested this with old archive files? Hopefully we won't run into any issues with old tests.

js/modules/k6/ws/ws.go Outdated Show resolved Hide resolved
js/modules/k6/ws/ws.go Outdated Show resolved Hide resolved
Comment on lines +233 to +240
case int:
return int64(n), nil
case int8:
return int64(n), nil
case int16:
return int64(n), nil
case int32:
return int64(n), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still baffled that multiple cases don't work for type switches 😕:

This could be much more succinct:

	case int, int8, int16, int32:
	  return int64(n), nil

But I guess there's a good reason for it.

Copy link
Member Author

@na-- na-- Nov 27, 2020

Choose a reason for hiding this comment

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

You can do that, but then n will be of an interface{} type, and you can't directly cast that to int64... You can do it via the reflect package, but that'd be much slower and somewhat type unsafe.

@na--
Copy link
Member Author

na-- commented Nov 27, 2020

LGTM, but have you tested this with old archive files? Hopefully we won't run into any issues with old tests.

Hmm good point, I'll see about adding a test. Not sure it's required, since the options in the archive bundles are basically the equivalent of the JSON+JS ones, but I'll dig around and test it manually, if nothing else. In any case, most old tests with duration values without units probably hadn't worked since k6 v0.27.0, since people would have gotten errors like scenario default has configuration errors: the duration should be at least 1s, but is 1ms.

@codecov-io
Copy link

codecov-io commented Dec 1, 2020

Codecov Report

Merging #1738 (6dd5316) into master (40979fd) will increase coverage by 0.05%.
The diff coverage is 94.54%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1738      +/-   ##
==========================================
+ Coverage   71.40%   71.45%   +0.05%     
==========================================
  Files         178      178              
  Lines       13751    13777      +26     
==========================================
+ Hits         9819     9845      +26     
  Misses       3320     3320              
  Partials      612      612              
Flag Coverage Δ
ubuntu 71.43% <94.54%> (+0.08%) ⬆️
windows 70.00% <94.54%> (+0.04%) ⬆️

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

Impacted Files Coverage Δ
cmd/common.go 36.36% <ø> (ø)
js/modules/k6/ws/ws.go 81.56% <ø> (ø)
js/modules/k6/http/request.go 80.14% <50.00%> (-0.51%) ⬇️
lib/types/types.go 89.55% <97.72%> (+3.98%) ⬆️
js/modules/k6/grpc/client.go 78.82% <100.00%> (-0.36%) ⬇️
js/runner.go 80.45% <100.00%> (-0.66%) ⬇️
core/engine.go 90.95% <0.00%> (-2.02%) ⬇️
stats/cloud/collector.go 80.44% <0.00%> (+0.63%) ⬆️
cmd/config.go 84.92% <0.00%> (+1.58%) ⬆️
... and 1 more

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 40979fd...6dd5316. Read the comment docs.

@na-- na-- requested review from mstoykov and imiric December 1, 2020 08:51
@na--
Copy link
Member Author

na-- commented Dec 1, 2020

I tested archives manually, and they are not a problem. If someone created an archive with k6 between v0.27.0 and v0.29.0, anything smaller than duration: 1000000000 (1 billion nanoseconds is 1s) would have resulted in a validation error. And if they did it with a previous version, it would have executed, FWIW... 😄 But in both cases, when the duration value was serialized in the archive, it would have used stringy values, 1s or 1ms or whatever. So everything should be fine.

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.

This might not actually be breaking anything ... it will just now handle "10s" in http request timeouts?

@na--
Copy link
Member Author

na-- commented Dec 1, 2020

This might not actually be breaking anything ... it will just now handle "10s" in http request timeouts?

Basically, yes. And also treat integers ad milliseconds instead of nanoseconds everywhere, which hopefully no-one has ever consciously used.... 😅 I'll add a breaking-changes github label though, to remind us when we write the release notes.

@na-- na-- merged commit ddee5dd into master Dec 1, 2020
@na-- na-- deleted the unify-duration-configs branch December 1, 2020 09:24
@na-- na-- added this to the v0.30.0 milestone Dec 1, 2020
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.

Unify duration configurations
4 participants