Skip to content

Commit 551d975

Browse files
mcollinaaddaleax
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: #18986 PR-URL: #19093 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent cc90bbd commit 551d975

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

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

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

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

5555
session.close();
5656
this.cleanup();
57+
58+
if(typeofnext==='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-
lettext='';
139-
tls(Object.assign({ port,ALPNProtocols: ['fake']},clientOptions))
140-
.setEncoding('utf8')
141-
.on('data',(chunk)=>text+=chunk)
142-
.on('end',common.mustCall(()=>{
143-
ok(/UnknownALPNProtocol,expected`h2`tobeavailable/.test(text));
144-
cleanup();
145-
}));
140+
functiontestNoTls(){
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+
functiontestWrongALPN(){
149+
// Incompatible ALPN TLS client
150+
lettext='';
151+
tls(Object.assign({ port,ALPNProtocols: ['fake']},clientOptions))
152+
.setEncoding('utf8')
153+
.on('data',(chunk)=>text+=chunk)
154+
.on('end',common.mustCall(()=>{
155+
ok(/UnknownALPNProtocol,expected`h2`tobeavailable/.test(text));
156+
cleanup();
157+
}));
158+
}
146159
}));
147160
}

0 commit comments

Comments
(0)