Skip to content

Commit 16e9b8d

Browse files
mcollinakjin
authored andcommitted
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: nodejs#18986 PR-URL: nodejs#19093 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 74212aa commit 16e9b8d

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

test/parallel/test-http2-https-fallback.js

+29-16
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function onRequest(request, response) {
3131
}));
3232
}
3333

34-
function onSession(session) {
34+
function onSession(session, next) {
3535
const headers = {
3636
':path': '/',
3737
':method': 'GET',
@@ -54,6 +54,10 @@ function onSession(session) {
5454

5555
session.close();
5656
this.cleanup();
57+
58+
if (typeof next === 'function') {
59+
next();
60+
}
5761
}));
5862
request.end();
5963
}
@@ -126,22 +130,31 @@ function onSession(session) {
126130
connect(
127131
origin,
128132
clientOptions,
129-
common.mustCall(onSession.bind({ cleanup, server }))
133+
common.mustCall(function(session) {
134+
onSession.call({ cleanup, server },
135+
session,
136+
common.mustCall(testNoTls));
137+
})
130138
);
131139

132-
// HTTP/1.1 client
133-
get(Object.assign(parse(origin), clientOptions), common.mustNotCall())
134-
.on('error', common.mustCall(cleanup))
135-
.end();
136-
137-
// Incompatible ALPN TLS client
138-
let text = '';
139-
tls(Object.assign({ port, ALPNProtocols: ['fake'] }, clientOptions))
140-
.setEncoding('utf8')
141-
.on('data', (chunk) => text += chunk)
142-
.on('end', common.mustCall(() => {
143-
ok(/Unknown ALPN Protocol, expected `h2` to be available/.test(text));
144-
cleanup();
145-
}));
140+
function testNoTls() {
141+
// HTTP/1.1 client
142+
get(Object.assign(parse(origin), clientOptions), common.mustNotCall)
143+
.on('error', common.mustCall(cleanup))
144+
.on('error', common.mustCall(testWrongALPN))
145+
.end();
146+
}
147+
148+
function testWrongALPN() {
149+
// Incompatible ALPN TLS client
150+
let text = '';
151+
tls(Object.assign({ port, ALPNProtocols: ['fake'] }, clientOptions))
152+
.setEncoding('utf8')
153+
.on('data', (chunk) => text += chunk)
154+
.on('end', common.mustCall(() => {
155+
ok(/Unknown ALPN Protocol, expected `h2` to be available/.test(text));
156+
cleanup();
157+
}));
158+
}
146159
}));
147160
}

0 commit comments

Comments
 (0)