Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: fix flaky test-http2-https-fallback #19093

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions test/parallel/test-http2-https-fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function onRequest(request, response) {
}));
}

function onSession(session) {
function onSession(session, next) {
const headers = {
':path': '/',
':method': 'GET',
Expand All @@ -54,6 +54,10 @@ function onSession(session) {

session.close();
this.cleanup();

if (typeof next === 'function') {
next();
}
}));
request.end();
}
Expand Down Expand Up @@ -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();
}));
}
}));
}