From 85d2cd57d0de0d84af90d6149015c20f60741025 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Fri, 2 Mar 2018 20:38:51 +0100 Subject: [PATCH 1/2] http2: fix flaky test-http2-https-fallback The test was flaky because it relied on a specific order of asynchronous operation that were fired paralellely. This was true on most platform and conditions, but not all the time. See: https://github.com/nodejs/node/pull/18986 --- test/parallel/test-http2-https-fallback.js | 43 ++++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/test/parallel/test-http2-https-fallback.js b/test/parallel/test-http2-https-fallback.js index 5d9a7e17103e56..d39b8a3f2f5209 100644 --- a/test/parallel/test-http2-https-fallback.js +++ b/test/parallel/test-http2-https-fallback.js @@ -31,7 +31,7 @@ function onRequest(request, response) { })); } -function onSession(session) { +function onSession(session, next) { const headers = { ':path': '/', ':method': 'GET', @@ -54,6 +54,10 @@ function onSession(session) { session.close(); this.cleanup(); + + if (typeof next === 'function') { + next(); + } })); request.end(); } @@ -126,22 +130,29 @@ function onSession(session) { connect( origin, clientOptions, - common.mustCall(onSession.bind({ cleanup, server })) + common.mustCall(function (session) { + onSession.call({ cleanup, server }, session, testNoTls); + }) ); - // HTTP/1.1 client - get(Object.assign(parse(origin), clientOptions), common.mustNotCall()) - .on('error', common.mustCall(cleanup)) - .end(); - - // Incompatible ALPN TLS client - let text = ''; - tls(Object.assign({ port, ALPNProtocols: ['fake'] }, clientOptions)) - .setEncoding('utf8') - .on('data', (chunk) => text += chunk) - .on('end', common.mustCall(() => { - ok(/Unknown ALPN Protocol, expected `h2` to be available/.test(text)); - cleanup(); - })); + function testNoTls () { + // HTTP/1.1 client + get(Object.assign(parse(origin), clientOptions), common.mustNotCall) + .on('error', common.mustCall(cleanup)) + .on('error', common.mustCall(testWrongALPN)) + .end(); + } + + function testWrongALPN() { + // Incompatible ALPN TLS client + let text = ''; + tls(Object.assign({ port, ALPNProtocols: ['fake'] }, clientOptions)) + .setEncoding('utf8') + .on('data', (chunk) => text += chunk) + .on('end', common.mustCall(() => { + ok(/Unknown ALPN Protocol, expected `h2` to be available/.test(text)); + cleanup(); + })); + } })); } From 185989fe219a3c0396a60917fc273e4e7322209c Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Fri, 2 Mar 2018 20:51:00 +0100 Subject: [PATCH 2/2] squash: linting --- test/parallel/test-http2-https-fallback.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-http2-https-fallback.js b/test/parallel/test-http2-https-fallback.js index d39b8a3f2f5209..a872d686d34f85 100644 --- a/test/parallel/test-http2-https-fallback.js +++ b/test/parallel/test-http2-https-fallback.js @@ -130,12 +130,14 @@ function onSession(session, next) { connect( origin, clientOptions, - common.mustCall(function (session) { - onSession.call({ cleanup, server }, session, testNoTls); + common.mustCall(function(session) { + onSession.call({ cleanup, server }, + session, + common.mustCall(testNoTls)); }) ); - function testNoTls () { + function testNoTls() { // HTTP/1.1 client get(Object.assign(parse(origin), clientOptions), common.mustNotCall) .on('error', common.mustCall(cleanup))