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

pm.sendRequest is not working in promise.then() chain #5606

Open
Massukio opened this issue Dec 4, 2018 · 6 comments
Open

pm.sendRequest is not working in promise.then() chain #5606

Massukio opened this issue Dec 4, 2018 · 6 comments

Comments

@Massukio
Copy link

Massukio commented Dec 4, 2018

Describe the bug

I wrote a function to wait for my async API to be done first and execute related tests later.

something like below:

wait_for_task_to_be_done(jsonData.taskId).then(function(value) {

    pm.test("Test A", function () {
        pm.expect(data).to.eql("expectation"));
    });

    pm.sendRequest( ... ,function (err, res) {
        pm.test("Test B", function () {
            pm.expect(data).to.eql("expectation"));
        });
    });

    pm.test("Test C", function () {
        pm.expect(data).to.eql("expectation"));
    });
});

test result ==>

[PASS]  Test A
[PASS]  Test C

"Test B" is gone somehow.

Then I checked the console output, the request has never been sent, it seems like the pm.sendRequest is not working in promise.then(). Could anyone help? Any workaround?

Expected behavior

pm.sendRequest shall be working fine in promise.then()

App information (please complete the following information):

  • App Type = Native App
  • Postman Version = v6.5.3
  • OS: Windows 10

Additional Tests

Tested with promise.then chain, it's also not working.

wait_for_task_to_be_done(jsonData.taskId).then(function(value) {
    pm.test("Test A", function () {
        pm.expect(data).to.eql("expectation"));
    });
}).then(function(value) {
    pm.sendRequest( ... ,function (err, res) {
        pm.test("Test B", function () {
            pm.expect(data).to.eql("expectation"));
        });
    });
)}.then(function(value) {
    pm.test("Test C", function () {
        pm.expect(data).to.eql("expectation"));
    });
})

test result ==>

[PASS]  Test A
[PASS]  Test C
@felipeplets
Copy link

@timmy8526 I had the same issue and solved it by leaving an open timeout while processing the async code. Here is my solution.

@pomeh
Copy link

pomeh commented Jan 7, 2019

For information, this bug looks similar to issue #4131 and https://community.getpostman.com/t/using-native-javascript-promises-in-postman/636/5. If confirmed, this is a known issue.

@felipeplets do you know why your workaround works ? This clearTimeout(interval) thing drives me crazy, I don't get why this would make the code work ! I would like to use this trick while using await, so there is no .then method... and I'm stucked !

@felipeplets
Copy link

@pomeh I don't know exactly why it works, but I imagine that the timeout make the session stay open while Promise and Async/Await is not doing that.

@shamasis
Copy link
Member

shamasis commented Jun 30, 2019

Note for future reference: @codenirvana we need to migrate to async_hooks from our current timerz implementation in postman-sandbox. That should open support for all language async features. Currently only setTimeout and setInterval are supported.

@Yilin-Ma
Copy link

Any update in 2021?

@Yilin-Ma
Copy link

Still having this issue in newman 5.2.1

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

No branches or pull requests

8 participants