-
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
k6/cloud module with the testRunId #4092
base: master
Are you sure you want to change the base?
Conversation
Note that the approach followed here won't make But I'd be very happy to see any suggestions or ideas for possible workarounds. |
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 left a couple of nit comments behind, but none of them blocking, I'd be happy with this merged as-is. Great work!
rt := vu.Runtime() | ||
|
||
mi.obj = rt.NewObject() | ||
defProp := func(name string, getter func() (sobek.Value, error)) { |
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.
Genuine curiosity, is there an advantage to defining a closure for this operation considering it's used only once? Or is it to scope the logic in the code and make it easier to maintain: which I'm completely okay with.
func (mi *ModuleInstance) testRunId() (sobek.Value, error) { | ||
// In case we have a value (e.g. loaded from env), we return it. | ||
// If we're in the init context (where we cannot read the options), we return undefined (the default value). | ||
if !sobek.IsUndefined(mi.testRunID) || mi.vu.State() == nil { |
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.
Would it make sens to use common.IsNullish here? Or do we want to specifically look only for undefined here?
|
||
// Otherwise, we try to read the test run id from options. | ||
// We only try it once for the whole execution, as options won't change. | ||
vuState := mi.vu.State() |
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.
nit: as you already check whether mi.vu.State() is nil before, would it make sense moving this assignment at the top of the function? What do you think?
What?
It adds a new
k6/cloud
JS module that exposes thetestRunId
.This is defined in any of the following scenarios:
k6 cloud run --local-execution
).The
testRunId
could also be read by any other module extension, as thek6/cloud
introduced in this changeset does.Why?
Because this unlocks many different projects we have ongoing, currently blocked by the lack of mechanisms to read the
testRunId
, either from the JS or the Go (extensions) surface.Checklist
make lint
) and all checks pass.make tests
) and all tests pass.Related PR(s)/Issue(s)
Contributes to #4041