Skip to content

Commit

Permalink
test: fix flaky http2-session-unref
Browse files Browse the repository at this point in the history
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.

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]>
  • Loading branch information
apapirovski authored and MylesBorins committed May 22, 2018
1 parent 171600d commit 275907f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/parallel/test-http2-session-unref.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const Countdown = require('../common/countdown');
const makeDuplexPair = require('../common/duplexpair');

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

const counter = new Countdown(3, () => server.unref());

// 'session' event should be emitted 3 times:
// - the vanilla client
// - the destroyed client
// - manual 'connection' event emission with generic Duplex stream
server.on('session', common.mustCallAtLeast((session) => {
counter.dec();
session.unref();
}, 3));

Expand Down Expand Up @@ -54,4 +58,3 @@ server.listen(0, common.mustCall(() => {
}
}));
server.emit('connection', serverSide);
server.unref();

0 comments on commit 275907f

Please sign in to comment.