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

fix: remove server.unref from tests (#3790) #3815

Merged
merged 1 commit into from Apr 3, 2022

Conversation

alex-parra
Copy link
Contributor

@alex-parra alex-parra commented Apr 2, 2022

Closes #3790

  1. Replacing in /test files calls to fastify.server.unref() with t.teardown(() => { fastify.close() }) as detailed in the issue.
  2. Most existing test files called t.error before t.teardown. Normalising to this pattern where it wasn't.

Checklist

@github-actions github-actions bot added the test Issue or pr related to our testing infrastructure. label Apr 2, 2022
@@ -98,7 +98,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this return will cause t.teardown not to be called.
To be inline with most other test files, suggest we remove the if and the return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another way to resolve this one is normalise calling t.teardown immediately after fastify is instantiated as stated in the test docs and not done in many places.
Kinda like go's defer.

@@ -139,7 +139,7 @@ module.exports.payloadMethod = function (method, t) {
t.error(err)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this if around t.error can likely be removed following what's done in most other test files.

@@ -115,7 +115,7 @@ test('route', t => {

fastify.listen({ port: 0 }, function (err) {
if (err) t.error(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this if around t.error can likely be removed following what's done in most other test files.

@@ -25,7 +25,7 @@ test('Should honor ignoreTrailingSlash option', t => {
})

fastify.listen({ port: 0 }, (err) => {
fastify.server.unref()
t.teardown(() => { fastify.close() })
if (err) t.threw(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

calling t.threw instead of t.error as we do in most other test files.
For consistency, would change to t.error and call before t.teardown.

@alex-parra alex-parra marked this pull request as draft April 2, 2022 15:48
@alex-parra alex-parra marked this pull request as ready for review April 2, 2022 16:19
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

@mcollina mcollina merged commit a4b21f0 into fastify:main Apr 3, 2022
@github-actions
Copy link

github-actions bot commented Apr 4, 2023

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 Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
test Issue or pr related to our testing infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove server.unref from tests
2 participants