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

Blocking event listeners #1698

Closed
adamp524 opened this issue Aug 31, 2018 · 5 comments
Closed

Blocking event listeners #1698

adamp524 opened this issue Aug 31, 2018 · 5 comments

Comments

@adamp524
Copy link

Hi,

I'm running postman collections using the newman node runner. I would like to intercept calls to various events such as 'start', 'beforeRequest', 'request' but have them block before continuing to the next stage. As far as I can tell, the handlers that are currently exposed are just triggers on events and can't block.

postman.run(script, resultDir)
        .on('start', function(err, args) {
             // Some logic here
        })
        .on('beforeItem', function(err, args) {
            // I would like this block not to execute until 'start' has executed fully.
        })
        .on('beforeRequest', function(err,args){
        })

Does anyone know if it's possible to intercept events and block in this way?

@kunagpal
Copy link
Member

kunagpal commented Sep 1, 2018

@adamp524 This isn't currently possible, as event handling works in fire and forget mode, so to speak. Could you elaborate a bit on your use case?

@adamp524
Copy link
Author

adamp524 commented Sep 1, 2018

We're running Newman tests on a network with a corporate proxy. I'm trying to parse a proxy pac file and set the http_proxy and https_proxy environment variables before the main request is issued.
The proxy destination changes depending on the request URL so we can't just hardcode the proxy environment variables at the beginning of the script.

If Newman had support for setting a proxy Pac URL that would be a really useful improvement. The npm pac-resolver library or similar is something you could use to easily read and parse.

@kunagpal
Copy link
Member

kunagpal commented Sep 3, 2018

@adamp524 Thanks for the context. Based on the snippet you'd shared above, you could shift the logic in the start event handler to before the run even starts. This ensures that the run only starts after your preparatory logic has completed its work. Based on the file parsing structure, you can update the values of the proxy environment variables in the beforeRequest/beforeItem event handlers.

@adamp524
Copy link
Author

adamp524 commented Sep 3, 2018

@kunagpal Our tests dynamically load in environment URLs, credentials etc. in the 'Pre-request' portion of a postman script. We don't know the full URL that the main request is going to be hitting until after the pre-request stage has been run.

You mention using the 'start' event handler however is there still not a risk of the script proceeding to further stages as the events are fire and forget?
In my case I'd want to wait until the 'prerequest' event before I set the proxy. However I wouldn't be able to guarantee that the proxy had been determined before my script's main request get executed.

@shamasis
Copy link
Member

shamasis commented Sep 3, 2018

Yep. There’s no way to block it. Even I wanted to block some events for a newman debugging reporter I was planning. On top of it, blocking events is first an anti pattern and secondly it would go against the architecture of newman’s internals. So, on that ground we have nowhere to go - as far as I can think of.

For the proxy PAC file thing, we have support for that in our app. Wondering what effort would it take to bring the same to Newman. I’m closing this ticket and creating a new feature request. 😊

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

No branches or pull requests

3 participants