-
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
js/k6/exec: test.options object #2493
Conversation
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.
Have you thought about freezing the object that is returned so that users will get an error if they try to modify something?
@mstoykov it would add a breaking change, if we have to do it I think could be good to give to the users at least one release before doing it, so they would have the time to migrate. WDYT? |
I meant the |
Oh, you're right. 🤦♂️ I thought you meant the exported |
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.
Overall looks good, left a small comment 👍
fd05c98
to
280ca72
Compare
The I also added an integration test for monitoring the default values. Unfortunately, they will be Here, an example: k6/lib/executor/ramping_vus.go Lines 68 to 74 in 57e9942
Of course, they will be set when the user explicitly set them or the config is derived. |
It doesn't, but I managed to make it work for the original SharedArray implementation https://github.com/grafana/k6/pull/1739/files |
Added the object freeze: import exec from 'k6/execution'
export default function() {
console.log(Object.isFrozen(exec.test.options))
console.log(Object.isFrozen(exec.test.options.paused))
console.log(Object.isFrozen(exec.test.options.httpDebug))
console.log(Object.isFrozen(exec.test.options.dns))
console.log(Object.isFrozen(exec.test.options.scenarios))
console.log(Object.isFrozen(exec.test.options.scenarios.default))
console.log(Object.isFrozen(exec.test.options.scenarios.default.iterations))
} INFO[0000] true source=console
INFO[0000] true source=console
INFO[0000] true source=console
INFO[0000] true source=console
INFO[0000] true source=console
INFO[0000] true source=console
INFO[0000] true source=console |
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.
💪
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 looks awesome, congrats! Special kudos for adding the FreezeObject construct! 👍🏻 🦖
Regarding the default values of thresholds, I would prefer it to be an empty object {}
, but if I console.log(options.thresholds)
as of today, it prints undefined
which makes sense. I can see both work, so up to you 🦕
@oleiade I updated the description with the decision applied for that part, sorry for not doing it before. Reporting here also ⬇️ :
At the moment, it is also the same default value reported in the docs so it shouldn't change the current UX. |
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
46f112b
I rebased the fixups and applied the @mstoykov's suggestion |
This PR will implement the doc: grafana/k6-docs#629 |
This PR adds the capability for fetching the consolidated and derived options for tests using the
k6/execution
API. It adds atest.options
object exporting all the potential set properties.A simple example of the expected API:
Open questions
We are defining the default values for some objects/arrays asWe will use the same value returned from the JSON marshal, at the moment, the k6 options' values are Nullable so the default value will benull
. An example is Thresholds.Which value do we expect to get if we access properties like Thresholds?
undefined
ornull
or{}
(empty object)?null
.In case ofWe used a classic JS Object but with the Object.freeze function applied.const
, it seems not possible by spec to set back an eventual wrap/proxy for warning the access. Do we have an alternative?I would define these cases before polishing and addressing edge cases.
Closes #2450