Skip to content

Commit 6c8e095

Browse files
authored
fix(test): flaky on-listen hook test (fastify#5256)
* fix(test): flaky on-listen hook test * Apply suggestions from code review Signed-off-by: Aras Abbasi <[email protected]> * simplify * use t.equal instead t.ok --------- Signed-off-by: Aras Abbasi <[email protected]>
1 parent 70a1d3f commit 6c8e095

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

test/hooks.on-listen.test.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const Fastify = require('../fastify')
55
const fp = require('fastify-plugin')
66
const split = require('split2')
77
const helper = require('./helper')
8-
9-
// fix citgm @aix72-ppc64
10-
const LISTEN_READYNESS = process.env.CITGM ? 250 : 50
8+
const { kState } = require('../lib/symbols')
119

1210
let localhost
1311
before(async function () {
@@ -1056,36 +1054,35 @@ test('async onListen does not need to be awaited', t => {
10561054

10571055
test('onListen hooks do not block /1', t => {
10581056
t.plan(2)
1057+
10591058
const fastify = Fastify()
10601059
t.teardown(fastify.close.bind(fastify))
10611060

10621061
fastify.addHook('onListen', function (done) {
1063-
setTimeout(done, 500)
1062+
t.equal(fastify[kState].listening, true)
1063+
done()
10641064
})
10651065

1066-
const startDate = new Date()
10671066
fastify.listen({
10681067
host: 'localhost',
10691068
port: 0
10701069
}, err => {
10711070
t.error(err)
1072-
t.ok(new Date() - startDate < LISTEN_READYNESS)
10731071
})
10741072
})
10751073

10761074
test('onListen hooks do not block /2', async t => {
10771075
t.plan(1)
1076+
10781077
const fastify = Fastify()
10791078
t.teardown(fastify.close.bind(fastify))
10801079

10811080
fastify.addHook('onListen', async function () {
1082-
await new Promise(resolve => setTimeout(resolve, 500))
1081+
t.equal(fastify[kState].listening, true)
10831082
})
10841083

1085-
const startDate = new Date()
10861084
await fastify.listen({
10871085
host: 'localhost',
10881086
port: 0
10891087
})
1090-
t.ok(new Date() - startDate < LISTEN_READYNESS)
10911088
})

0 commit comments

Comments
 (0)