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 ready order execution #2333

Merged
merged 3 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ function hookRunnerApplication (hookName, boot, server, cb) {
if (i === 0 && c === 0) { // speed up start
exit()
} else {
// This is the last function executed for every fastify instance
boot(function manageTimeout (err, done) {
done(err)
// this callback is needed by fastify to provide an hook interface without error
// and managing the error for the user
Eomm marked this conversation as resolved.
Show resolved Hide resolved
exit(err)

// this callback is needed by avvio to continue the loading of the next `register` plugins
done(err)
})
}
return
Expand Down
10 changes: 10 additions & 0 deletions test/hooks.on-ready.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,13 @@ t.test('onReady does not call done', t => {
t.equal(err.code, 'ERR_AVVIO_READY_TIMEOUT')
})
})

t.test('onReady execution order', t => {
t.plan(3)
const fastify = Fastify({ })

let i = 0
fastify.ready(() => { i++; t.equals(i, 1) })
fastify.ready(() => { i++; t.equals(i, 2) })
fastify.ready(() => { i++; t.equals(i, 3) })
})