Skip to content

Commit

Permalink
test: Fix health check tests hanging
Browse files Browse the repository at this point in the history
The Fastify server seems to hang and never gets ready
when using the `modern` implementation of `jest.useFakeTimers`.

Minimal repro: https://github.com/rburgst/fastify-jest-timers
  • Loading branch information
franky47 committed Nov 20, 2021
1 parent 0df33b4 commit 5863de3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/health.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Health checks', () => {
})

test('Custom health check handler is called at startup and every 5 seconds', async () => {
jest.useFakeTimers()
jest.useFakeTimers('legacy')
const healthCheck = jest.fn().mockResolvedValue(true)
const server = createServer({
underPressure: {
Expand All @@ -29,7 +29,7 @@ describe('Health checks', () => {
})

test('Custom health check throwing results in 503', async () => {
jest.useFakeTimers()
jest.useFakeTimers('legacy')
const healthCheck = jest
.fn()
.mockResolvedValueOnce(true) // First call passes (setup)
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('Health checks', () => {

test('Disabled health monitoring', async () => {
process.env.FASTIFY_MICRO_DISABLE_SERVICE_HEALTH_MONITORING = 'true'
jest.useFakeTimers()
jest.useFakeTimers('legacy')
const healthCheck = jest.fn().mockResolvedValue(true)
const server = createServer({
underPressure: {
Expand Down

0 comments on commit 5863de3

Please sign in to comment.