-
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
update recommendation for async check #4037
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ package k6 | |
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"math/rand" | ||
"strings" | ||
"time" | ||
|
@@ -24,9 +23,6 @@ var ( | |
ErrCheckInInitContext = common.NewInitContextError("Using check() in the init context is not supported") | ||
) | ||
|
||
const asyncFunctionNotSupportedMsg = "%s() does not support async functions as arguments, " + | ||
"please see https://grafana.com/docs/k6/latest/javascript-api/k6/group/#working-with-async-functions for more info" | ||
|
||
type ( | ||
// RootModule is the global module instance that will create module | ||
// instances for each VU. | ||
|
@@ -104,7 +100,8 @@ func (mi *K6) Group(name string, val sobek.Value) (sobek.Value, error) { | |
return nil, errors.New("group() requires a callback as a second argument") | ||
} | ||
if common.IsAsyncFunction(mi.vu.Runtime(), val) { | ||
return sobek.Undefined(), fmt.Errorf(asyncFunctionNotSupportedMsg, "group") | ||
return sobek.Undefined(), errors.New("group() does not support async functions as arguments, " + | ||
"please see https://grafana.com/docs/k6/latest/javascript-api/k6/group/#working-with-async-functions for more info") | ||
} | ||
oldGroupName, _ := state.Tags.GetCurrentValues().Tags.Get(metrics.TagGroup.String()) | ||
// TODO: what are we doing if group is not tagged | ||
|
@@ -182,7 +179,9 @@ func (mi *K6) Check(arg0, checks sobek.Value, extras ...sobek.Value) (bool, erro | |
} | ||
|
||
if common.IsAsyncFunction(rt, val) { | ||
return false, fmt.Errorf(asyncFunctionNotSupportedMsg, "check") | ||
return false, errors.New("built-in check() does not support async functions as arguments, " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is probably good idea either here or/and the linked utils to explain why this is a problem similar to how it does it fro group. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @heitortsergent maybe we should fix this part in the docs ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that makes sense @mstoykov. I'll open an issue for it. 🙇 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "The built-in check() does not support async functions as arguments. Use the JavaScript utils library as a replacement. Refer to https://grafana.com/docs/k6/latest/javascript-api/jslib/utils/check/ for more info" Small suggestion for the message on these lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I've opened the #4043 for addressing 👍 |
||
"please switch to JavaScript replacement, see " + | ||
"https://grafana.com/docs/k6/latest/javascript-api/jslib/utils/check/ for more info") | ||
} | ||
|
||
// Resolve callables into values. | ||
|
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.
Just as a small nit, we don't have the heading #working-with-async-functions on that page, so you could just link to: https://grafana.com/docs/k6/latest/javascript-api/k6/group/.
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.
Good catch, thanks! @heitortsergent