Skip to content

Commit

Permalink
test: fix flaky test-http2-invalidheaderfield
Browse files Browse the repository at this point in the history
Separate test cases to avoid side effects and race conditions.

Fixes: #34172

PR-URL: #34173
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
  • Loading branch information
Trott committed Jul 3, 2020
1 parent d08334a commit 9b8d317
Showing 1 changed file with 67 additions and 46 deletions.
113 changes: 67 additions & 46 deletions test/parallel/test-http2-invalidheaderfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,77 @@ if (!common.hasCrypto) { common.skip('missing crypto'); }
const http2 = require('http2');
const { throws, strictEqual } = require('assert');

const server = http2.createServer(common.mustCall((req, res) => {
throws(() => {
res.setHeader(':path', '/');
}, {
code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'
});
throws(() => {
res.setHeader('t est', 123);
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
res.setHeader('TEST', 123);
res.setHeader('test_', 123);
res.setHeader(' test', 123);
res.end();
}));
{
const server = http2.createServer(common.mustCall((req, res) => {
throws(() => {
res.setHeader(':path', '/');
}, {
code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'
});
throws(() => {
res.setHeader('t est', 123);
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
res.setHeader('TEST', 123);
res.setHeader('test_', 123);
res.setHeader(' test', 123);
res.end();
}));

server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
session.request({ 'test_': 123, 'TEST': 123 })
.on('end', common.mustCall(() => {
session.close();
server.close();
}));
}));
}

server.listen(0, common.mustCall(() => {
const session1 = http2.connect(`http://localhost:${server.address().port}`);
session1.request({ 'test_': 123, 'TEST': 123 })
.on('end', common.mustCall(() => {
session1.close();
{
const server = http2.createServer();
server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
session.on('error', common.mustCall((e) => {
strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
server.close();
}));

const session2 = http2.connect(`http://localhost:${server.address().port}`);
session2.on('error', common.mustCall((e) => {
strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
throws(() => {
session.request({ 't est': 123 });
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
}));
throws(() => {
session2.request({ 't est': 123 });
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
}

const session3 = http2.connect(`http://localhost:${server.address().port}`);
session3.on('error', common.mustCall((e) => {
strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');

{
const server = http2.createServer();
server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
session.on('error', common.mustCall((e) => {
strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
server.close();
}));
throws(() => {
session.request({ ' test': 123 });
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
}));
throws(() => {
session3.request({ ' test': 123 });
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
}

const session4 = http2.connect(`http://localhost:${server.address().port}`);
throws(() => {
session4.request({ ':test': 123 });
}, {
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
});
session4.close();
}));
{
const server = http2.createServer();
server.listen(0, common.mustCall(() => {
const session4 = http2.connect(`http://localhost:${server.address().port}`);
throws(() => {
session4.request({ ':test': 123 });
}, {
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
});
session4.close();
server.close();
}));
}

0 comments on commit 9b8d317

Please sign in to comment.