-
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
#1289: Error will be displayed that only 1 array is allowed in batch #2585
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.
Hi @vanshaj, LGTM. Can you sign the CLA so we can accept your contribution, please?
Hi @vanshaj ! Thanks for your contribution! It seems like the changes affected other tests. Could you please have a look? Cheers! |
Sorry for the failures. I have added the validation for init context above my new validation. Pushed the changes Regards |
Codecov Report
@@ Coverage Diff @@
## master #2585 +/- ##
==========================================
- Coverage 75.59% 75.03% -0.56%
==========================================
Files 202 203 +1
Lines 15992 16274 +282
==========================================
+ Hits 12089 12212 +123
- Misses 3151 3296 +145
- Partials 752 766 +14
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
js/modules/k6/http/request.go
Outdated
if len(reqsValues) == 0 { | ||
return nil, fmt.Errorf("no argument was provided to http.batch()") | ||
} else if len(reqsValues) > 1 { // Validation for http.batch(["https://validurl"],["https://validurl"]) | ||
return nil, fmt.Errorf("http.batch() must have only one single array as an argument") |
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.
return nil, fmt.Errorf("http.batch() must have only one single array as an argument") | |
return nil, fmt.Errorf("http.batch() must have only one single array as a root argument. Define the requests as nested items.") |
@olegbespalov WDYT? Do you have better suggestions? I would be very clear here because I think it's easy to waste time making the error to forget the root array.
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.
return nil, fmt.Errorf("http.batch() must have only one single array as an argument") | |
return nil, fmt.Errorf("http.batch() accepts only an array or an object of requests.") |
@olegbespalov your version sounds better, I would just avoid the slash.
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.
Done updated to "http.batch() accepts only an array or an object of requests." in file and test case also .
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, just some minors improvements
js/modules/k6/http/request.go
Outdated
@@ -437,21 +437,25 @@ func (c *Client) prepareBatchObject(requests map[string]interface{}) ( | |||
|
|||
// Batch makes multiple simultaneous HTTP requests. The provideds reqsV should be an array of request | |||
// objects. Batch returns an array of responses and/or error | |||
func (c *Client) Batch(reqsV goja.Value) (interface{}, error) { | |||
func (c *Client) Batch(reqsValues ...goja.Value) (interface{}, 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.
func (c *Client) Batch(reqsValues ...goja.Value) (interface{}, error) { | |
func (c *Client) Batch(reqsV ...goja.Value) (interface{}, error) { |
Removing the line after we can restore the name so we don't need to update the comment.
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.
Thanks a lot for your valuable feedback. Implemented the change.
js/modules/k6/http/request.go
Outdated
return nil, fmt.Errorf("http.batch() accepts only an array or an object of requests") | ||
} | ||
|
||
reqsV := reqsValues[0] |
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.
reqsV := reqsValues[0] |
This change doesn't seem required, so we can avoid one more allocation, you can use directly reqsV[0].Export()
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.
Thanks a lot for your valuable feedback. Implemented the change.
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! Thanks for your contribution! 👍
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! Hey @vanshaj, we are going to merge this, thanks for your contribution. 👏 🎉
Thanks a lot, very glad for your review and valuable feedback. Will keep on contributing |
Updated Batch method to contain array of goja.Value and if the size is greater than 1 then return and error. Else continue with the data.