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

http.batch(array) result isn't an array #767

Closed
na-- opened this issue Sep 13, 2018 · 2 comments · Fixed by #1259
Closed

http.batch(array) result isn't an array #767

na-- opened this issue Sep 13, 2018 · 2 comments · Fixed by #1259

Comments

@na--
Copy link
Member

na-- commented Sep 13, 2018

The following code

import http from "k6/http";

export default function () {
    let jsArr = [5, 6, 7, 8];
    if (jsArr.every(el => el > 3)) {
        console.log("great!");
    }

    let k6Responses = http.batch([
        ["GET", "https://test.loadimpact.com/"],
        ["GET", "https://test.loadimpact.com/style.css"],
        ["GET", "https://test.loadimpact.com/images/logo.png"]
    ]);
    if (k6Responses.every(resp => resp.status === 200)) {
        console.log("it works");
    }
}

outputs

INFO[0000] great!                                       
ERRO[0001] TypeError: Object has no member 'every'
	at [.....]/test_case.js:14:26(41)
@na--
Copy link
Member Author

na-- commented Sep 13, 2018

I think this is because of an implementation detail that we always use an object as the http.batch() result, since we allow users to request named responses: https://docs.k6.io/docs/batch-requests#section-named-requests

We might want to split the Batch() implementation a bit, so that if users pass an array with requests they receive an array with responses back (that should have the every(), forEach(), etc. methods) and if they pass an object with named requests, they get an object back. This would have some code duplication, but I'd say that it would probably be a bit clearer than the current implementation...

Might go well together with #574

@na-- na-- added the ux label Sep 13, 2018
@na-- na-- changed the title Array returned by http.batch() doesn't have some js methods http.batch(array) result isn't an array Sep 13, 2018
@na-- na-- added this to the v0.26.0 milestone Aug 27, 2019
@na-- na-- removed this from the v0.26.0 milestone Sep 26, 2019
@na--
Copy link
Member Author

na-- commented Sep 26, 2019

Removed the milestone, since this will likely be obsoleted by the new HTTP API we're planning (issue pending)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant