Skip to content

Commit 5d29e2c

Browse files
apapirovskiBethGriggs
authored andcommitted
test: fix flaky http2-session-unref
It's possible for the connections to take too long and since the server is already unrefed, the process will just exit. Instead adjust the test so that server unref only happens after all sessions have been successfuly established and unrefed. That still tests the same condition but will not fail under load. Backport-PR-URL: #22850 PR-URL: #20772 Fixes: #20705 Fixes: #20750 Fixes: #20850 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0a6672f commit 5d29e2c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

test/parallel/test-http2-session-unref.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ const common = require('../common');
99
if (!common.hasCrypto)
1010
common.skip('missing crypto');
1111
const http2 = require('http2');
12+
const Countdown = require('../common/countdown');
1213
const makeDuplexPair = require('../common/duplexpair');
1314

1415
const server = http2.createServer();
1516
const { clientSide, serverSide } = makeDuplexPair();
1617

18+
const counter = new Countdown(3, () => server.unref());
19+
1720
// 'session' event should be emitted 3 times:
1821
// - the vanilla client
1922
// - the destroyed client
2023
// - manual 'connection' event emission with generic Duplex stream
2124
server.on('session', common.mustCallAtLeast((session) => {
25+
counter.dec();
2226
session.unref();
2327
}, 3));
2428

@@ -54,6 +58,3 @@ server.listen(0, common.mustCall(() => {
5458
}
5559
}));
5660
server.emit('connection', serverSide);
57-
server.unref();
58-
59-
setTimeout(common.mustNotCall(() => {}), 1000).unref();

0 commit comments

Comments
 (0)