summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatteo Collina <hello@matteocollina.com>2018-03-02 20:38:51 +0100
committerMatteo Collina <hello@matteocollina.com>2018-03-03 13:10:31 +0100
commitbbc9807b207b08759b447672fa638c9ec96d4c17 (patch)
tree190d16215859e088287a48b42650916dbb4906f2 /test
parent96b2d8d3dc59f057622175eac0c57423964165c7 (diff)
downloadandroid-node-v8-bbc9807b207b08759b447672fa638c9ec96d4c17.tar.gz
android-node-v8-bbc9807b207b08759b447672fa638c9ec96d4c17.tar.bz2
android-node-v8-bbc9807b207b08759b447672fa638c9ec96d4c17.zip
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 PR-URL: https://github.com/nodejs/node/pull/19093 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http2-https-fallback.js45
1 files changed, 29 insertions, 16 deletions
diff --git a/test/parallel/test-http2-https-fallback.js b/test/parallel/test-http2-https-fallback.js
index 5d9a7e1710..a872d686d3 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,31 @@ function onSession(session) {
connect(
origin,
clientOptions,
- common.mustCall(onSession.bind({ cleanup, server }))
+ common.mustCall(function(session) {
+ onSession.call({ cleanup, server },
+ session,
+ common.mustCall(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();
+ }));
+ }
}));
}