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
reopened server show more detail error msg #2415
Conversation
cc @mcollina, thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! Just a nit.
t.is(err.code, 'FST_ERR_REOPENED_CLOSE_SERVER') | ||
t.ok(err) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you mind to use async/await in the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @mcollina.
I try use async/await, while when I modify code below it, show error for it tapError: incorrect number of tests
, plan test is 2, I dig it for a while, but not solved. please told me where is errors.
test('Cannot be reopened the closed server has listen callback', async t => {
t.plan(2)
const fastify = Fastify()
await fastify.listen(0)
await fastify.close()
fastify.listen(0, (err) => {
t.is(err.code, 'FST_ERR_REOPENED_CLOSE_SERVER')
t.ok(err)
})
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you must write
try{
await fastify.listen(0)
}catch(err){
t.is(err.code, 'FST_ERR_REOPENED_CLOSE_SERVER')
t.ok(err)
}
(the promise of the test ends, so it is resolved as undefined and the callback of the fastify.listen is ignored even if it is executed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Eomm thanks for the answer.
The test unit is listen has callback
. if I follow the code about 👆,I don't test code logic. https://github.com/fastify/fastify/pull/2415/files#diff-c945a46d13b34fcaff544d966cffcabaR138.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops 😅
Then you can just wrap the callback in a new Promise 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @Eomm, I got it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Checklist
Fix #2411
npm run test
andnpm run benchmark