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

Iterate through multiple get calls. #559

Open
bora19 opened this issue May 4, 2020 · 3 comments
Open

Iterate through multiple get calls. #559

bora19 opened this issue May 4, 2020 · 3 comments

Comments

@bora19
Copy link

bora19 commented May 4, 2020

Im trying to iterate through multiple devices and getting the response from each device. But since frisby requires return to work then I cannot use it in a for loop.

Is there any way to loop through multiple devices.

ex. device 123456 gets a response then I grab that response and save it in a text file then I want to continue looping through the rest of the devices and save the response on text file.

basic form:
for (i = 0; i < foo.length; i++) {
return frisby.get(baseUrl + foo[i]+ endPoint)
.then(function (res) {
console.log('HERE');
});
}

The above will only process the 1st iteration due to the required return. Is there a way to bypass it?

@H1Gdev
Copy link
Collaborator

H1Gdev commented May 5, 2020

use Promise.all().

sample code:

const frisby = require('frisby');

it('issue 559.', () => {
    let f = id => {
      return frisby.get(baseUrl + id + endPoint)
        .then(res => {
          console.log('HERE');
        });
    };
    let p = Array(5);
    for (let i = 0; i < p.length; ++i)
      p[i] = f(i);

    return Promise.all(p);
});

@bora19
Copy link
Author

bora19 commented May 5, 2020

Using promise.all works but I keep getting random error 504 gateway timeouts. It will not complete my test list of 8 items without an error 504. I usually get anywhere from 3-4 results back. Every time I run a different result will come back

@H1Gdev
Copy link
Collaborator

H1Gdev commented May 6, 2020

Test time may be insufficient.

#515 (comment)

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

No branches or pull requests

2 participants