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

reopened server show more detail error msg #2415

Merged
merged 2 commits into from Jul 16, 2020

Conversation

zhangwinning
Copy link
Contributor

@zhangwinning zhangwinning commented Jul 16, 2020

Checklist

Fix #2411

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

@zhangwinning
Copy link
Contributor Author

cc @mcollina, thanks

Copy link
Member

@mcollina mcollina left a 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.

test/close.test.js Show resolved Hide resolved
t.is(err.code, 'FST_ERR_REOPENED_CLOSE_SERVER')
t.ok(err)
})
})
Copy link
Member

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?

Copy link
Contributor Author

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)
  })
})

Copy link
Member

@Eomm Eomm Jul 16, 2020

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)

Copy link
Contributor Author

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.

Copy link
Member

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 👍🏼

Copy link
Contributor Author

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

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@Eomm Eomm added backport 2.x Issue or pr that should be backported to Fastify v2 bugfix Issue or PR that should land as semver patch labels Jul 16, 2020
@mcollina mcollina merged commit e53abd1 into fastify:master Jul 16, 2020
@zhangwinning zhangwinning deleted the bug/reopenServer branch July 16, 2020 15:15
@github-actions
Copy link

github-actions bot commented Feb 9, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport 2.x Issue or pr that should be backported to Fastify v2 bugfix Issue or PR that should land as semver patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot listen on a port after closing the server. Error is misleading.
3 participants