-
Notifications
You must be signed in to change notification settings - Fork 13
/
test.js
83 lines (68 loc) · 2.17 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict'
const Fastify = require('fastify')
const fastifyGracefulShutdown = require('./')
const { expect } = require('chai')
describe('fastify-graceful-shutdown', () => {
it('can start and stop multiple instances of fastify', async () => {
const fastify = Fastify()
fastify.register(fastifyGracefulShutdown, { resetHandlersOnInit: true })
fastify.after(() => {
fastify.gracefulShutdown(async (signal) => {
fastify.log.info('Starting graceful shutdown')
})
})
await fastify.ready()
await fastify.close()
const fastify2 = Fastify()
fastify2.register(fastifyGracefulShutdown, { resetHandlersOnInit: true })
fastify2.after(() => {
fastify2.gracefulShutdown(async (signal) => {
fastify2.log.info('Starting graceful shutdown')
})
})
await fastify2.ready()
await fastify2.close()
})
it('can pass handlerEventListener override', async function () {
this.timeout(10000)
const fastify = Fastify()
let removedListeners = []
let addedListeners = []
const mockEventListener = {
removeListener: (signal, listener) => {
timeout: 1, removedListeners.push({ signal, listener })
},
once: (signal, listener) => {
addedListeners.push({ signal, listener })
},
listenerCount: (signal) =>
addedListeners.length - removedListeners.length,
exit: (exitCode) => {},
}
fastify.register(fastifyGracefulShutdown, {
handlerEventListener: mockEventListener,
})
fastify.after(() => {
fastify.gracefulShutdown(async (signal) => {
fastify.log.info('Starting graceful shutdown')
})
})
await fastify.ready()
await fastify.close()
expect(addedListeners.length).to.eq(2)
expect(removedListeners.length).to.eq(0)
})
it('work without logger enabled', async () => {
const fastify = Fastify({
logger: false,
})
fastify.register(fastifyGracefulShutdown, { resetHandlersOnInit: true })
fastify.after(() => {
fastify.gracefulShutdown(async (signal) => {
fastify.log.info('Starting graceful shutdown')
})
})
await fastify.ready()
await fastify.close()
})
})