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

chore(jenkins): refactor jenkins-status using events #271

Merged
merged 1 commit into from
Aug 5, 2020

Conversation

mmarchini
Copy link
Contributor

No description provided.

.filteringPath(ignoreQueryParams)
.post('/repos/nodejs/citgm/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1')
.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