reopened server show more detail error msg#2415
Conversation
|
cc @mcollina, thanks |
| t.is(err.code, 'FST_ERR_REOPENED_CLOSE_SERVER') | ||
| t.ok(err) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
would you mind to use async/await in the test?
There was a problem hiding this comment.
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.
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.
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.
Ops 😅
Then you can just wrap the callback in a new Promise 👍🏼
|
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 testandnpm run benchmark