Skip to content

Conversation

@mmarchini
Copy link
Contributor

No description provided.

.reply(201)
.on('replied', (req, interceptor) => {
t.doesNotThrow(() => interceptor.scope.done())
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting alternative approach to verifying scopes that I haven't used before. Any obvious upsides compared to the previous approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we're using EventEmitter and Promises, the timing is different and as a result the callback below to run before we made a call to the scope URL, so we get an error when we call scope.done()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh okey, so that's another approach to fixing what was my biggest headache in #258 basically.

What I ended up doing there, was to make sure all event handlers returned a Promise. That way the resulting Promise coming out of the app.emitJenkinsEvent()-equivalent of #258 would actually resolve after all handlers had completed. In the end we can be sure that all handlers (and thereby scope) has finished when the request gets the 200 response back.

No biggie tho, just wanted to understand the pros & reasons behind this new approach introduced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works too, but no reason to delay the response until app.emitJenkinsEvent finishes since Jenkins doesn't do anything with 200/500 status codes. We could for testability if we wanted to, but this approach seems fine and more robust?

prCommitsScope.done()
scope.done()
// prCommitsScope.done()
// scope.done()
Copy link
Member

@phillipj phillipj Aug 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we don't need these commented lines anymore.

@phillipj
Copy link
Member

phillipj commented Aug 3, 2020

Nice refactor 💯

Copy link
Member

@phillipj phillipj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after either remove commented lines or keep them if event handlers are adjusted to ensure they have completed before responding to incoming HTTP request.

@phillipj
Copy link
Member

phillipj commented Aug 5, 2020 via email

@mmarchini mmarchini merged commit 93ac4e9 into nodejs:master Aug 5, 2020
@mmarchini mmarchini deleted the jenkins-events branch August 5, 2020 21:03
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

Successfully merging this pull request may close these issues.

2 participants