From 26e4c587eb218251e29d268c31dcd18a4f962d44 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sat, 23 Sep 2017 13:07:38 -0400 Subject: [PATCH] test: fix flaky test-http2-create-client-connect The first group of tests makes one more connection and leave the server alive for longer. Otherwise the test is just catching that the server has closed the socket, depending on timing. This does not quite make the test pass yet, however. There are some quirks with how the http2 code handles errors which actually affect 1.0.2 as well. PR-URL: https://github.com/nodejs/node/pull/16130 Reviewed-By: Ben Noordhuis Reviewed-By: Rod Vagg --- .../test-http2-create-client-connect.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-http2-create-client-connect.js b/test/parallel/test-http2-create-client-connect.js index 7fdea9aef41a08..cd7d8b4fc8c3f9 100644 --- a/test/parallel/test-http2-create-client-connect.js +++ b/test/parallel/test-http2-create-client-connect.js @@ -3,6 +3,7 @@ // Tests http2.connect() const common = require('../common'); +const Countdown = require('../common/countdown'); if (!common.hasCrypto) common.skip('missing crypto'); const fixtures = require('../common/fixtures'); @@ -25,13 +26,12 @@ const URL = url.URL; [{ port: port, hostname: '127.0.0.1' }, { protocol: 'http:' }] ]; - let count = items.length; + const serverClose = new Countdown(items.length + 1, + () => setImmediate(() => server.close())); const maybeClose = common.mustCall((client) => { client.destroy(); - if (--count === 0) { - setImmediate(() => server.close()); - } + serverClose.dec(); }, items.length); items.forEach((i) => { @@ -42,7 +42,7 @@ const URL = url.URL; // Will fail because protocol does not match the server. h2.connect({ port: port, protocol: 'https:' }) - .on('socketError', common.mustCall()); + .on('socketError', common.mustCall(() => serverClose.dec())); })); } @@ -70,13 +70,12 @@ const URL = url.URL; [{ port: port, hostname: '127.0.0.1', protocol: 'https:' }, opts] ]; - let count = items.length; + const serverClose = new Countdown(items.length, + () => setImmediate(() => server.close())); const maybeClose = common.mustCall((client) => { client.destroy(); - if (--count === 0) { - setImmediate(() => server.close()); - } + serverClose.dec(); }, items.length); items.forEach((i) => {