test: ensure assertions are reached on HTTP2 tests

PR-URL: https://github.com/nodejs/node/pull/60730
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Antoine du Hamel committed 2025-11-17 21:34:43 +01:00
1 parent 42187494d3
commit ecbc22dc37
84 files changed
+315 -324

No files matched your search

+1 -1
View File
@@ -195,7 +195,7 @@ export default [
`test/parallel/test-{${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
Array.from({ length: 4 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
},http-*,${
},http-*,http2-*,${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
Array.from({ length: 7 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
}}.{js,mjs,cjs}`,
+2 -2
View File
@@ -34,7 +34,7 @@ const tls = require('tls');
})
);
server.listen(0, function() {
server.listen(0, common.mustCall(() => {
const client = tls.connect({
port: server.address().port,
rejectUnauthorized: false,
@@ -43,5 +43,5 @@ const tls = require('tls');
assert.strictEqual(client.alpnProtocol, 'a');
client.end();
}));
});
}));
}
@@ -25,7 +25,7 @@ server.on('stream', (stream) => {
stream.end('data');
});
server.listen(0, async () => {
server.listen(0, common.mustCall(async () => {
const client = storage.run({ id: 0 }, () => http2.connect(`http://localhost:${server.address().port}`));
async function doReq(id) {
@@ -52,4 +52,4 @@ server.listen(0, async () => {
doReqWith(1);
doReqWith(2);
});
}));
+2 -2
View File
@@ -12,7 +12,7 @@ const { duplexPair } = require('stream');
{
let req;
const server = http2.createServer();
server.on('stream', mustCallAsync(async (stream, headers) => {
server.on('stream', mustCall(async (stream, headers) => {
stream.respond({
'content-type': 'text/html',
':status': 200
@@ -46,7 +46,7 @@ function event(ee, eventName) {
});
}
function mustCallAsync(fn, exact) {
function mustCall(fn, exact) {
return common.mustCall((...args) => {
return Promise.resolve(fn(...args)).then(common.mustCall((val) => val));
}, exact);
@@ -23,7 +23,7 @@ server.on('stream', common.mustCall(function(stream) {
stream.on('error', () => {});
}));
server.listen(0, function() {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`https://localhost:${server.address().port}`,
{ rejectUnauthorized: false }
);
@@ -34,4 +34,4 @@ server.listen(0, function() {
}));
client_stream.resume();
client_stream.write(Buffer.alloc(1024 * 1024));
});
}));
+4 -6
View File
@@ -8,9 +8,7 @@ const {
if (!hasCrypto)
skip('missing crypto');
const {
strictEqual
} = require('assert');
const assert = require('assert');
const {
createServer,
connect
@@ -25,9 +23,9 @@ if (process.argv[2] !== 'child') {
const {
stdout, stderr, status
} = spawnSync(process.execPath, [__filename, 'child'], { encoding: 'utf8' });
strictEqual(stderr, '');
strictEqual(stdout, '');
strictEqual(status, 0);
assert.strictEqual(stderr, '');
assert.strictEqual(stdout, '');
assert.strictEqual(status, 0);
} else {
const server = createServer();
server.listen(0, mustCall(() => {
+2 -3
View File
@@ -10,8 +10,7 @@ const Countdown = require('../common/countdown');
const server = http2.createServer();
server.on('stream', common.mustCall((stream, headers, flags) => {
if (headers[':path'] === '/') {
stream.pushStream({ ':path': '/foobar' }, (err, push, headers) => {
assert.ifError(err);
stream.pushStream({ ':path': '/foobar' }, common.mustSucceed((push, headers) => {
push.respond({
'content-type': 'text/html',
'x-push-data': 'pushed by server',
@@ -19,7 +18,7 @@ server.on('stream', common.mustCall((stream, headers, flags) => {
push.write('pushed by server ');
setImmediate(() => push.end('data'));
stream.end('st');
});
}));
}
stream.respond({ 'content-type': 'text/html' });
stream.write('te');
+2 -2
View File
@@ -86,7 +86,7 @@ const { getEventListeners } = require('events');
// Wait for setImmediate call from destroy() to complete
// so that state.destroyed is set to true
setImmediate(() => {
setImmediate(common.mustCall(() => {
assert.throws(() => client.setNextStreamID(), sessionError);
assert.throws(() => client.setLocalWindowSize(), sessionError);
assert.throws(() => client.ping(), sessionError);
@@ -94,7 +94,7 @@ const { getEventListeners } = require('events');
assert.throws(() => client.goaway(), sessionError);
assert.throws(() => client.request(), sessionError);
client.close(); // Should be a non-op at this point
});
}));
req.resume();
req.on('end', common.mustNotCall());
@@ -39,7 +39,7 @@ server.listen(0, common.mustCall(function() {
host: 'localhost',
port: this.address().port,
ALPNProtocols: ['h2']
}, () => {
}, common.mustCall(() => {
const proxy = new JSSocket(socket);
const client = h2.connect(`https://localhost:${this.address().port}`, {
createConnection: () => proxy
@@ -54,5 +54,5 @@ server.listen(0, common.mustCall(function() {
client.close();
server.close();
}));
});
}));
}));
@@ -32,7 +32,7 @@ server.listen(0, common.mustCall(() => {
const port = server.address().port;
const client = http2.connect(`http://localhost:${port}`);
client.on('connect', () => {
client.on('connect', common.mustCall(() => {
Object.keys(optionsToTest).forEach((option) => {
Object.keys(types).forEach((type) => {
if (type === optionsToTest[option])
@@ -52,5 +52,5 @@ server.listen(0, common.mustCall(() => {
});
server.close();
client.close();
});
}));
}));
@@ -8,7 +8,7 @@ const h2 = require('http2');
let client;
const server = h2.createServer();
server.on('stream', (stream) => {
server.on('stream', common.mustCall((stream) => {
stream.on('close', common.mustCall(() => {
client.close();
server.close();
@@ -18,7 +18,7 @@ server.on('stream', (stream) => {
name: 'Error',
message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR'
}));
});
}));
server.listen(0, common.mustCall(() => {
client = h2.connect(`http://localhost:${server.address().port}`);
@@ -11,7 +11,7 @@ common.expectWarning(
'Priority signaling has been deprecated as of RFC 9113.',
'DEP0194');
const checkWeight = (actual, expect) => {
function checkWeight(actual, expect) {
const server = http2.createServer();
server.on('stream', common.mustCall((stream, headers, flags) => {
assert.strictEqual(stream.state.sumDependencyWeight, 0);
@@ -31,7 +31,7 @@ const checkWeight = (actual, expect) => {
client.close();
}));
}));
};
}
// When client weight is lower than 1, weight is 1
checkWeight(-1, 1);
@@ -26,7 +26,7 @@ const types = {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
client.on('connect', () => {
client.on('connect', common.mustCall(() => {
const outOfRangeNum = 2 ** 32;
assert.throws(
() => client.setNextStreamID(outOfRangeNum),
@@ -57,5 +57,5 @@ server.listen(0, common.mustCall(() => {
server.close();
client.close();
});
}));
}));
@@ -13,18 +13,18 @@ const server = h2.createServer();
// Do not mustCall the server side callbacks, they may or may not be called
// depending on the OS. The determination is based largely on operating
// system specific timings
server.on('stream', (stream) => {
server.on('stream', common.mustCallAtLeast((stream) => {
// Do not wrap in a must call or use common.expectsError (which now uses
// must call). The error may or may not be reported depending on operating
// system specific timings.
stream.on('error', (err) => {
stream.on('error', common.mustCallAtLeast((err) => {
assert.strictEqual(err.code, 'ERR_HTTP2_STREAM_ERROR');
assert.strictEqual(err.message,
'Stream closed with error code NGHTTP2_INTERNAL_ERROR');
});
}, 0));
stream.respond();
stream.end();
});
}, 0));
server.listen(0, common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);
@@ -19,14 +19,14 @@ fs.readFile(loc, common.mustSucceed((data) => {
server.on('stream', common.mustCall((stream) => {
// Wait for some data to come through.
setImmediate(() => {
setImmediate(common.mustCall(() => {
stream.on('close', common.mustCall(() => {
assert.strictEqual(stream.rstCode, 0);
}));
stream.respond({ ':status': 400 });
stream.end();
});
}));
}));
server.listen(0, common.mustCall(() => {
@@ -31,7 +31,7 @@ server.on('session', common.mustCall(function(session) {
}));
}));
server.listen(0, function() {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`https://localhost:${server.address().port}`, {
ca,
maxSessionMemory: 1000
@@ -43,4 +43,4 @@ server.listen(0, function() {
}));
client_stream.resume();
client_stream.write(Buffer.alloc(64 * 1024));
});
}));
@@ -9,7 +9,7 @@ const http2 = require('http2');
const msecs = common.platformTimeout(1);
const server = http2.createServer();
server.on('request', (req, res) => {
server.on('request', common.mustCall((req, res) => {
const request = req.setTimeout(msecs, common.mustCall(() => {
res.end();
}));
@@ -22,7 +22,7 @@ server.on('request', (req, res) => {
server.close();
});
}));
});
}));
server.listen(0, common.mustCall(() => {
const port = server.address().port;
@@ -19,7 +19,7 @@ const server = h2.createServer(common.mustCall((req, res) => {
}));
server.listen(0);
server.on('listening', () => {
server.on('listening', common.mustCall(() => {
const url = `http://localhost:${server.address().port}`;
const client = h2.connect(url, common.mustCall(() => {
const request = client.request();
@@ -28,4 +28,4 @@ server.on('listening', () => {
server.close();
}));
}));
});
}));
@@ -11,7 +11,7 @@ const h2 = require('http2');
const pushExpect = 'This is a server-initiated response';
const servExpect = 'This is a client-initiated response';
const server = h2.createServer((request, response) => {
const server = h2.createServer(common.mustCallAtLeast((request, response) => {
assert.strictEqual(response.stream.id % 2, 1);
response.write(servExpect);
@@ -27,14 +27,14 @@ const server = h2.createServer((request, response) => {
}
);
response.stream.on('close', () => {
response.stream.on('close', common.mustCall(() => {
response.createPushResponse({
':path': '/pushed',
':method': 'GET'
}, common.mustCall((error) => {
assert.strictEqual(error.code, 'ERR_HTTP2_INVALID_STREAM');
}));
});
}));
response.createPushResponse({
':path': '/pushed',
@@ -44,7 +44,7 @@ const server = h2.createServer((request, response) => {
push.end(pushExpect);
response.end();
}));
});
}));
server.listen(0, common.mustCall(() => {
const port = server.address().port;
@@ -9,7 +9,7 @@ const {
} = require('../common');
if (!hasCrypto)
skip('missing crypto');
const { strictEqual } = require('assert');
const assert = require('assert');
const {
createServer,
connect,
@@ -51,7 +51,7 @@ const {
request.setEncoding('utf8');
request.on('data', (chunk) => (data += chunk));
request.on('end', mustCall(() => {
strictEqual(data, 'end');
assert.strictEqual(data, 'end');
client.close();
}));
request.end();
@@ -63,8 +63,8 @@ const {
{
// Http2ServerResponse.end should return self after end
const server = createServer(mustCall((request, response) => {
strictEqual(response, response.end());
strictEqual(response, response.end());
assert.strictEqual(response, response.end());
assert.strictEqual(response, response.end());
server.close();
}));
server.listen(0, mustCall(() => {
@@ -110,7 +110,7 @@ const {
request.setEncoding('utf8');
request.on('data', (chunk) => (data += chunk));
request.on('end', mustCall(() => {
strictEqual(data, 'test\uD83D\uDE00');
assert.strictEqual(data, 'test\uD83D\uDE00');
client.close();
}));
request.end();
@@ -149,13 +149,13 @@ const {
// Http2ServerResponse.end is necessary on HEAD requests in compat
// for http1 compatibility
const server = createServer(mustCall((request, response) => {
strictEqual(response.writableEnded, false);
strictEqual(response.finished, false);
assert.strictEqual(response.writableEnded, false);
assert.strictEqual(response.finished, false);
response.writeHead(HTTP_STATUS_OK, { foo: 'bar' });
strictEqual(response.finished, false);
assert.strictEqual(response.finished, false);
response.end('data', mustCall());
strictEqual(response.writableEnded, true);
strictEqual(response.finished, true);
assert.strictEqual(response.writableEnded, true);
assert.strictEqual(response.finished, true);
}));
server.listen(0, mustCall(() => {
const { port } = server.address();
@@ -169,9 +169,9 @@ const {
};
const request = client.request(headers);
request.on('response', mustCall((headers, flags) => {
strictEqual(headers[HTTP2_HEADER_STATUS], HTTP_STATUS_OK);
strictEqual(flags, 5); // The end of stream flag is set
strictEqual(headers.foo, 'bar');
assert.strictEqual(headers[HTTP2_HEADER_STATUS], HTTP_STATUS_OK);
assert.strictEqual(flags, 5); // The end of stream flag is set
assert.strictEqual(headers.foo, 'bar');
}));
request.on('data', mustNotCall());
request.on('end', mustCall(() => {
@@ -234,9 +234,9 @@ const {
};
const request = client.request(headers);
request.on('response', mustCall((headers, flags) => {
strictEqual(headers[HTTP2_HEADER_STATUS], HTTP_STATUS_OK);
strictEqual(flags, 5); // The end of stream flag is set
strictEqual(headers.foo, 'bar');
assert.strictEqual(headers[HTTP2_HEADER_STATUS], HTTP_STATUS_OK);
assert.strictEqual(flags, 5); // The end of stream flag is set
assert.strictEqual(headers.foo, 'bar');
}));
request.on('data', mustNotCall());
request.on('end', mustCall(() => {
@@ -269,9 +269,9 @@ const {
};
const request = client.request(headers);
request.on('response', mustCall((headers, flags) => {
strictEqual(headers[HTTP2_HEADER_STATUS], HTTP_STATUS_OK);
strictEqual(flags, 5); // The end of stream flag is set
strictEqual(headers.foo, 'bar');
assert.strictEqual(headers[HTTP2_HEADER_STATUS], HTTP_STATUS_OK);
assert.strictEqual(flags, 5); // The end of stream flag is set
assert.strictEqual(headers.foo, 'bar');
}));
request.on('data', mustNotCall());
request.on('end', mustCall(() => {
@@ -293,7 +293,7 @@ const {
finished = false;
}));
response.end('data', mustCall(() => {
strictEqual(finished, false);
assert.strictEqual(finished, false);
response.end('data', mustCall());
}));
}));
@@ -309,9 +309,9 @@ const {
};
const request = client.request(headers);
request.on('response', mustCall((headers, flags) => {
strictEqual(headers[HTTP2_HEADER_STATUS], HTTP_STATUS_OK);
strictEqual(flags, 5); // The end of stream flag is set
strictEqual(headers.foo, 'bar');
assert.strictEqual(headers[HTTP2_HEADER_STATUS], HTTP_STATUS_OK);
assert.strictEqual(flags, 5); // The end of stream flag is set
assert.strictEqual(headers.foo, 'bar');
}));
request.on('data', mustNotCall());
request.on('end', mustCall(() => {
@@ -342,8 +342,8 @@ const {
};
const request = client.request(headers);
request.on('response', mustCall((headers, flags) => {
strictEqual(headers[HTTP2_HEADER_STATUS], HTTP_STATUS_OK);
strictEqual(flags, 5); // The end of stream flag is set
assert.strictEqual(headers[HTTP2_HEADER_STATUS], HTTP_STATUS_OK);
assert.strictEqual(flags, 5); // The end of stream flag is set
}));
request.on('data', mustNotCall());
request.on('end', mustCall(() => {
@@ -8,7 +8,7 @@ const http2 = require('http2');
const msecs = common.platformTimeout(1);
const server = http2.createServer();
server.on('request', (req, res) => {
server.on('request', common.mustCall((req, res) => {
res.setTimeout(msecs, common.mustCall(() => {
res.end();
}));
@@ -20,7 +20,7 @@ server.on('request', (req, res) => {
server.close();
});
}));
});
}));
server.listen(0, common.mustCall(() => {
const port = server.address().port;
@@ -33,7 +33,7 @@ server.listen(0, common.mustCall(() => {
const notCallClose = common.mustNotCall();
setTimeout(() => {
setTimeout(common.mustCall(() => {
req.setEncoding('utf8');
req.removeListener('close', notCallClose);
req.on('close', common.mustCall(() => {
@@ -44,7 +44,7 @@ server.listen(0, common.mustCall(() => {
req.on('end', common.mustCall(() => {
assert.strictEqual(data, 'test');
}));
}, common.platformTimeout(100));
}), common.platformTimeout(100));
req.on('close', notCallClose);
}));
@@ -32,11 +32,11 @@ const testResBody = 'response content';
req.on('headers', common.mustNotCall());
process.on('uncaughtException', (err) => {
process.on('uncaughtException', common.mustCall((err) => {
debug(`Caught an exception: ${JSON.stringify(err)}`);
if (err.name === 'AssertionError') throw err;
assert.strictEqual(err.code, 'ERR_INVALID_ARG_TYPE');
process.exit(0);
});
}));
}));
}
@@ -32,11 +32,11 @@ const testResBody = 'response content';
req.on('headers', common.mustNotCall());
process.on('uncaughtException', (err) => {
process.on('uncaughtException', common.mustCall((err) => {
debug(`Caught an exception: ${JSON.stringify(err)}`);
if (err.name === 'AssertionError') throw err;
assert.strictEqual(err.code, 'ERR_INVALID_ARG_VALUE');
process.exit(0);
});
}));
}));
}
+2 -2
View File
@@ -51,7 +51,7 @@ server.listen(0, common.mustCall(() => {
});
}));
proxy.listen(0, () => {
proxy.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${proxy.address().port}`);
// Confirm that :authority is required and :scheme & :path are forbidden
@@ -104,5 +104,5 @@ server.listen(0, common.mustCall(() => {
server.close();
}));
req.end('hello');
});
}));
}));
+2 -2
View File
@@ -12,7 +12,7 @@ if (!hasMultiLocalhost()) {
const http2 = require('http2');
const assert = require('assert');
const server = http2.createServer((req, res) => {
const server = http2.createServer(common.mustCallAtLeast((req, res) => {
console.log(`Connect from: ${req.connection.remoteAddress}`);
assert.strictEqual(req.connection.remoteAddress, '127.0.0.2');
@@ -21,7 +21,7 @@ const server = http2.createServer((req, res) => {
res.end(`You are from: ${req.connection.remoteAddress}`);
}));
req.resume();
});
}));
server.listen(0, '127.0.0.1', common.mustCall(() => {
const options = { localAddress: '127.0.0.2', family: 4 };
@@ -26,8 +26,8 @@ server.listen(0, '127.0.0.1', common.mustCall(() => {
rejectUnauthorized: false
};
const socket = tls.connect(options, async () => {
socket.once('readable', () => {
const socket = tls.connect(options, common.mustCall(async () => {
socket.once('readable', common.mustCall(() => {
const client = http2.connect(
'https://localhost:' + server.address().port,
{ ...options, createConnection: () => socket }
@@ -45,6 +45,6 @@ server.listen(0, '127.0.0.1', common.mustCall(() => {
}));
req.end();
}));
});
});
}));
}));
}));
+7 -6
View File
@@ -5,7 +5,8 @@ const {
hasCrypto,
hasIPv6,
skip,
expectsError
expectsError,
mustCallAtLeast
} = require('../common');
if (!hasCrypto)
skip('missing crypto');
@@ -21,7 +22,7 @@ const { connect: tlsConnect } = require('tls');
server.listen(0, mustCall(() => {
const authority = `http://localhost:${server.address().port}`;
const options = {};
const listener = () => mustCall();
const listener = mustCallAtLeast(() => mustCall());
const clients = new Set();
// Should not throw.
@@ -48,12 +49,12 @@ const { connect: tlsConnect } = require('tls');
server.listen(0, mustCall(() => {
const { port } = server.address();
const onSocketConnect = () => {
const onSocketConnect = mustCallAtLeast(() => {
const authority = `http://localhost:${port}`;
const createConnection = mustCall(() => socket);
const options = { createConnection };
connect(authority, options, mustCall(onSessionConnect));
};
});
const onSessionConnect = (session) => {
session.close();
@@ -82,12 +83,12 @@ const { connect: tlsConnect } = require('tls');
server.listen(0, mustCall(() => {
const { port } = server.address();
const onSocketConnect = () => {
const onSocketConnect = mustCall(() => {
const authority = `https://localhost:${port}`;
const createConnection = mustCall(() => socket);
const options = { createConnection };
connect(authority, options, mustCall(onSessionConnect));
};
});
const onSessionConnect = (session) => {
session.close();
@@ -46,10 +46,10 @@ server.on('listening', common.mustCall(() => {
assert.strictEqual(client.alpnProtocol, 'h2c');
}));
const countdown = new Countdown(count, () => {
const countdown = new Countdown(count, common.mustCall(() => {
client.close();
server.close(common.mustCall());
});
}));
for (let n = 0; n < count; n++) {
const req = client.request();
@@ -22,7 +22,7 @@ server.on('session', common.mustCall(function(session) {
}));
}));
server.listen(0, function() {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const stream = client.request({ ':method': 'POST' });
stream.on('response', common.mustCall(function(headers) {
@@ -34,4 +34,4 @@ server.listen(0, function() {
}));
stream.resume();
stream.end();
});
}));
+6 -6
View File
@@ -8,7 +8,7 @@ const http2 = require('http2');
const server = http2.createServer();
server.on('stream', (s) => {
server.on('stream', common.mustCall((s) => {
assert(s.pushAllowed);
s.pushStream({ ':path': '/file' }, common.mustSucceed((pushStream) => {
@@ -18,9 +18,9 @@ server.on('stream', (s) => {
s.respond();
s.end('hello world');
});
}));
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
server.unref();
const url = `http://localhost:${server.address().port}`;
@@ -43,7 +43,7 @@ server.listen(0, () => {
assert.strictEqual(pushData, 'a push stream');
// Removing the setImmediate causes the test to pass
setImmediate(function() {
setImmediate(common.mustCall(() => {
let data = '';
req.setEncoding('utf8');
req.on('data', (d) => data += d);
@@ -51,7 +51,7 @@ server.listen(0, () => {
assert.strictEqual(data, 'hello world');
client.close();
}));
});
}));
}));
}));
});
}));
@@ -9,7 +9,7 @@ const { createServer, constants, connect } = require('http2');
const server = createServer();
server.on('stream', (stream, headers) => {
server.on('stream', common.mustCall((stream, headers) => {
stream.respond(undefined, { waitForTrailers: true });
stream.on('data', common.mustNotCall());
@@ -30,9 +30,9 @@ server.on('stream', (stream, headers) => {
stream.on('close', common.mustCall());
stream.end();
});
}));
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const clientSession = connect(`http://localhost:${server.address().port}`);
clientSession.on('frameError', common.mustNotCall());
@@ -52,4 +52,4 @@ server.listen(0, () => {
clientStream.on('frameError', common.mustNotCall());
clientStream.end();
});
}));
@@ -20,8 +20,8 @@ const assert = require('assert');
const server = http2.createServer({ maxSessionMemory: 1 });
server.on('session', function(session) {
session.on('stream', function(stream) {
server.on('session', common.mustCall((session) => {
session.on('stream', common.mustCallAtLeast((stream) => {
stream.on('end', common.mustCall(function() {
this.respond({
':status': 200
@@ -30,10 +30,10 @@ server.on('session', function(session) {
});
}));
stream.resume();
});
});
}));
}));
server.listen(0, function() {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
function next(i) {
@@ -50,4 +50,4 @@ server.listen(0, function() {
}
next(0);
});
}));
@@ -8,7 +8,7 @@ const http2 = require('http2');
const server = http2.createServer();
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
client.on('close', common.mustCall(() => {
server.close();
@@ -19,4 +19,4 @@ server.listen(0, () => {
stream.on('error', common.expectsError({ code: 'ERR_HTTP2_GOAWAY_SESSION' }));
setImmediate(() => client.close());
});
}));
@@ -19,7 +19,7 @@ server.on('stream', common.mustCall((stream) => {
}));
server.on('close', common.mustCall());
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
client.once('goaway', common.mustCall((code, lastStreamID, buf) => {
assert.strictEqual(code, 0);
@@ -33,4 +33,4 @@ server.listen(0, () => {
req.on('end', common.mustCall());
req.on('close', common.mustCall());
req.end();
});
}));
+4 -4
View File
@@ -20,7 +20,7 @@ const {
} = http2.constants;
const server = http2.createServer();
server.on('stream', (stream, headers) => {
server.on('stream', common.mustCall((stream, headers) => {
assert.strictEqual(headers[HTTP2_HEADER_METHOD], HTTP2_METHOD_HEAD);
@@ -29,10 +29,10 @@ server.on('stream', (stream, headers) => {
// Because this is a head request, the outbound stream is closed automatically
stream.on('error', errCheck);
stream.write('data');
});
}));
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
@@ -50,4 +50,4 @@ server.listen(0, () => {
server.close();
client.close();
}));
});
}));
+13 -13
View File
@@ -6,7 +6,7 @@ const fixtures = require('../common/fixtures');
if (!common.hasCrypto)
common.skip('missing crypto');
const { strictEqual, ok } = require('assert');
const assert = require('assert');
const { createSecureContext } = require('tls');
const { createSecureServer, connect } = require('http2');
const { get } = require('https');
@@ -42,16 +42,16 @@ function onSession(session, next) {
const request = session.request(headers);
request.on('response', common.mustCall((headers) => {
strictEqual(headers[':status'], 200);
strictEqual(headers['content-type'], 'application/json');
assert.strictEqual(headers[':status'], 200);
assert.strictEqual(headers['content-type'], 'application/json');
}));
request.setEncoding('utf8');
let raw = '';
request.on('data', (chunk) => { raw += chunk; });
request.on('end', common.mustCall(() => {
const { alpnProtocol, httpVersion } = JSON.parse(raw);
strictEqual(alpnProtocol, 'h2');
strictEqual(httpVersion, '2.0');
assert.strictEqual(alpnProtocol, 'h2');
assert.strictEqual(httpVersion, '2.0');
session.close();
this.cleanup();
@@ -89,17 +89,17 @@ function onSession(session, next) {
get(
Object.assign(parse(origin), clientOptions),
common.mustCall((response) => {
strictEqual(response.statusCode, 200);
strictEqual(response.statusMessage, 'OK');
strictEqual(response.headers['content-type'], 'application/json');
assert.strictEqual(response.statusCode, 200);
assert.strictEqual(response.statusMessage, 'OK');
assert.strictEqual(response.headers['content-type'], 'application/json');
response.setEncoding('utf8');
let raw = '';
response.on('data', (chunk) => { raw += chunk; });
response.on('end', common.mustCall(() => {
const { alpnProtocol, httpVersion } = JSON.parse(raw);
strictEqual(alpnProtocol, false);
strictEqual(httpVersion, '1.1');
assert.strictEqual(alpnProtocol, false);
assert.strictEqual(httpVersion, '1.1');
cleanup();
}));
@@ -116,7 +116,7 @@ function onSession(session, next) {
);
server.once('unknownProtocol', common.mustCall((socket) => {
strictEqual(socket instanceof Duplex, true);
assert.strictEqual(socket instanceof Duplex, true);
socket.destroy();
}));
@@ -152,7 +152,7 @@ function onSession(session, next) {
tls(Object.assign({ port, ALPNProtocols: ['fake'] }, clientOptions))
.on('error', common.mustCall((err) => {
const allowedErrors = ['ECONNRESET', 'ERR_SSL_TLSV1_ALERT_NO_APPLICATION_PROTOCOL'];
ok(allowedErrors.includes(err.code), `'${err.code}' was not one of ${allowedErrors}.`);
assert.ok(allowedErrors.includes(err.code), `'${err.code}' was not one of ${allowedErrors}.`);
cleanup();
testNoALPN();
}));
@@ -165,7 +165,7 @@ function onSession(session, next) {
.setEncoding('utf8')
.on('data', (chunk) => text += chunk)
.on('end', common.mustCall(() => {
ok(/Missing ALPN Protocol, expected `h2` to be available/.test(text));
assert.ok(/Missing ALPN Protocol, expected `h2` to be available/.test(text));
cleanup();
}));
}
@@ -8,16 +8,16 @@ if (!common.hasCrypto) { common.skip('missing crypto'); }
// Capitalized headers
const http2 = require('http2');
const { throws } = require('assert');
const assert = require('assert');
{
const server = http2.createServer(common.mustCall((req, res) => {
throws(() => {
assert.throws(() => {
res.setHeader(':path', '/');
}, {
code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'
});
throws(() => {
assert.throws(() => {
res.setHeader('t est', 123);
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
@@ -42,7 +42,7 @@ const { throws } = require('assert');
const server = http2.createServer();
server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
throws(() => {
assert.throws(() => {
session.request({ 't est': 123 });
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
@@ -56,7 +56,7 @@ const { throws } = require('assert');
const server = http2.createServer();
server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
throws(() => {
assert.throws(() => {
session.request({ ' test': 123 });
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
@@ -70,7 +70,7 @@ const { throws } = require('assert');
const server = http2.createServer();
server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
throws(() => {
assert.throws(() => {
session.request({ ':test': 123 });
}, {
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
+8 -8
View File
@@ -16,10 +16,10 @@ const settings = new h2test.SettingsFrame();
const settingsAck = new h2test.SettingsFrame(true);
const altsvc = new h2test.AltSvcFrame((1 << 14) + 1);
server.listen(0, () => {
const client = net.connect(server.address().port, () => {
client.write(h2test.kClientMagic, () => {
client.write(settings.data, () => {
server.listen(0, common.mustCall(() => {
const client = net.connect(server.address().port, common.mustCall(() => {
client.write(h2test.kClientMagic, common.mustCall(() => {
client.write(settings.data, common.mustCall(() => {
client.write(settingsAck.data);
// Prior to nghttp2 1.31.1, sending this malformed altsvc frame
// would cause a segfault. This test is successful if a segfault
@@ -27,13 +27,13 @@ server.listen(0, () => {
client.write(altsvc.data, common.mustCall(() => {
client.destroy();
}));
});
});
});
}));
}));
}));
// An error may or may not be emitted on the client side, we don't care
// either way if it is, but we don't want to die if it is.
client.on('error', () => {});
client.on('close', common.mustCall(() => server.close()));
client.resume();
});
}));
@@ -10,7 +10,7 @@ const http2 = require('http2');
req.pipe(res);
});
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const url = `http://localhost:${server.address().port}`;
const client = http2.connect(url);
const req = client.request({ ':method': 'POST' });
@@ -26,5 +26,5 @@ const http2 = require('http2');
}));
req.once('data', common.mustCall(() => req.destroy()));
});
}));
}
@@ -21,7 +21,7 @@ server.on('stream', (stream) => {
stream.end('Hello, world!\n');
});
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const h2header = Buffer.alloc(9);
const conn = net.connect({
port: server.address().port,
@@ -86,4 +86,4 @@ server.listen(0, () => {
conn.destroy();
server.close();
}));
});
}));
@@ -55,7 +55,7 @@ const data = Buffer.from([
let client;
const server = h2.createServer({ settings: { initialWindowSize: 36 } });
server.on('stream', (stream) => {
server.on('stream', common.mustCall((stream) => {
// Set the high water mark to zero, since otherwise we still accept
// reads from the source stream (if we can consume them).
stream._readableState.highWaterMark = 0;
@@ -70,7 +70,7 @@ server.on('stream', (stream) => {
client.destroy();
}));
stream.on('end', common.mustNotCall());
});
}));
server.listen(0, () => {
client = net.connect(server.address().port, () => {
@@ -65,7 +65,7 @@ const data = Buffer.from([
let client;
const server = h2.createServer({ settings: { initialWindowSize: 18 } });
server.on('stream', (stream) => {
server.on('stream', common.mustCall((stream) => {
stream.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
name: 'Error',
@@ -78,7 +78,7 @@ server.on('stream', (stream) => {
stream.resume();
stream.respond();
stream.end('ok');
});
}));
server.on('close', common.mustCall());
@@ -56,7 +56,7 @@ const id1 = new h2test.HeadersFrame(1, h2test.kFakeRequestHeaders, 0, true);
const id3 = new h2test.HeadersFrame(3, h2test.kFakeRequestHeaders, 0, true);
const id5 = new h2test.HeadersFrame(5, h2test.kFakeRequestHeaders, 0, true);
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
client = net.connect(server.address().port, () => {
client.write(h2test.kClientMagic, () => {
client.write(settings.data, () => {
@@ -75,4 +75,4 @@ server.listen(0, () => {
client.on('error', () => {});
client.on('close', common.mustCall(() => server.close()));
client.resume();
});
}));
@@ -23,14 +23,14 @@ server.on('stream', common.mustCall((stream) => {
stream.respond({}, { waitForTrailers: true });
stream.on('wantTrailers', () => {
stream.on('wantTrailers', common.mustCall(() => {
assert.throws(() => {
stream.sendTrailers({ ':status': 'bar' });
}, {
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
});
stream.close();
});
}));
stream.end('hello world');
}));
+2 -2
View File
@@ -18,7 +18,7 @@ server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const nextID = 2 ** 31 - 1;
client.on('connect', () => {
client.on('connect', common.mustCall(() => {
client.setNextStreamID(nextID);
assert.strictEqual(client.state.nextStreamID, nextID);
@@ -49,5 +49,5 @@ server.listen(0, common.mustCall(() => {
}));
req.on('error', () => countdown.dec());
}
});
}));
}));
+3 -5
View File
@@ -8,9 +8,7 @@ const {
if (!hasCrypto)
skip('missing crypto');
const {
deepStrictEqual
} = require('assert');
const assert = require('assert');
const {
createServer,
connect
@@ -25,7 +23,7 @@ server.on('stream', mustCall((stream) => {
}));
server.on('session', mustCall((session) => {
session.on('ping', mustCall((payload) => {
deepStrictEqual(check, payload);
assert.deepStrictEqual(check, payload);
}));
session.ping(check, mustCall());
}));
@@ -33,7 +31,7 @@ server.listen(0, mustCall(() => {
const client = connect(`http://localhost:${server.address().port}`);
client.on('ping', mustCall((payload) => {
deepStrictEqual(check, payload);
assert.deepStrictEqual(check, payload);
}));
client.on('connect', mustCall(() => {
client.ping(check, mustCall());
@@ -14,12 +14,12 @@ class MyServerRequest extends h2.Http2ServerRequest {
const server = h2.createServer({
Http2ServerRequest: MyServerRequest
}, (req, res) => {
}, common.mustCallAtLeast((req, res) => {
assert.strictEqual(req.getUserAgent(), 'node-test');
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end();
});
}));
server.listen(0);
server.on('listening', common.mustCall(() => {
+13 -17
View File
@@ -9,11 +9,7 @@ const {
if (!hasCrypto)
skip('missing crypto');
const {
deepStrictEqual,
strictEqual,
throws
} = require('assert');
const assert = require('assert');
const {
createSecureServer,
createServer,
@@ -42,7 +38,7 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
session.origin();
[0, true, {}, []].forEach((input) => {
throws(
assert.throws(
() => session.origin(input),
{
code: 'ERR_INVALID_ARG_TYPE',
@@ -52,7 +48,7 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
});
[new URL('foo://bar'), 'foo://bar'].forEach((input) => {
throws(
assert.throws(
() => session.origin(input),
{
code: 'ERR_HTTP2_INVALID_ORIGIN',
@@ -62,7 +58,7 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
});
['not a valid url'].forEach((input) => {
throws(
assert.throws(
() => session.origin(input),
{
code: 'ERR_INVALID_URL',
@@ -71,7 +67,7 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
);
});
const longInput = `http://foo.bar${'a'.repeat(16383)}`;
throws(
assert.throws(
() => session.origin(longInput),
{
code: 'ERR_HTTP2_ORIGIN_LENGTH',
@@ -96,8 +92,8 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
client.on('origin', mustCall((origins) => {
const check = checks.shift();
originSet.push(...check);
deepStrictEqual(client.originSet, originSet);
deepStrictEqual(origins, check);
assert.deepStrictEqual(client.originSet, originSet);
assert.deepStrictEqual(origins, check);
countdown.dec();
}, 2));
@@ -126,8 +122,8 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
client.on('origin', mustCall((origins) => {
originSet.push(...check);
deepStrictEqual(client.originSet, originSet);
deepStrictEqual(origins, check);
assert.deepStrictEqual(client.originSet, originSet);
assert.deepStrictEqual(origins, check);
countdown.dec();
}));
@@ -152,11 +148,11 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
const client = connect(origin, { ca });
client.on('origin', mustCall((origins) => {
deepStrictEqual(client.originSet, [origin, 'https://foo.org']);
assert.deepStrictEqual(client.originSet, [origin, 'https://foo.org']);
const req = client.request({ ':authority': 'foo.org' });
req.on('response', mustCall((headers) => {
strictEqual(headers[':status'], 421);
deepStrictEqual(client.originSet, [origin]);
assert.strictEqual(headers[':status'], 421);
assert.deepStrictEqual(client.originSet, [origin]);
}));
req.resume();
req.on('close', mustCall(() => {
@@ -180,7 +176,7 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
server.listen(0, mustCall(() => {
const client = connect(`http://localhost:${server.address().port}`);
client.on('origin', mustNotCall());
strictEqual(client.originSet, undefined);
assert.strictEqual(client.originSet, undefined);
const req = client.request();
req.resume();
req.on('close', mustCall(() => {
+2 -2
View File
@@ -20,10 +20,10 @@ const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
const dest = stream.pipe(fs.createWriteStream(fn));
dest.on('finish', () => {
dest.on('finish', common.mustCall(() => {
assert.strictEqual(fs.readFileSync(loc).length,
fs.readFileSync(fn).length);
});
}));
stream.respond();
stream.end();
}));
+2 -2
View File
@@ -24,7 +24,7 @@ server.on('stream', common.mustCall((stream) => {
});
}, 3));
server.on('session', common.mustCall((session) => {
session.on('priority', (id, parent, weight, exclusive) => {
session.on('priority', common.mustCallAtLeast((id, parent, weight, exclusive) => {
assert.strictEqual(weight, 16);
assert.strictEqual(exclusive, false);
switch (id) {
@@ -40,7 +40,7 @@ server.on('session', common.mustCall((session) => {
default:
assert.fail('should not happen');
}
});
}, 0));
}));
server.listen(0, common.mustCall(() => {
@@ -12,7 +12,7 @@ const destroyCode = http2.constants.NGHTTP2_REFUSED_STREAM;
server.on('error', common.mustNotCall());
server.on('session', (session) => {
server.on('session', common.mustCall((session) => {
session.on('close', common.mustCall());
session.on('error', common.mustCall((err) => {
assert.match(err.message, errRegEx);
@@ -30,7 +30,7 @@ server.on('session', (session) => {
session.destroy(destroyCode);
}));
});
}));
server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
@@ -12,9 +12,9 @@ const server = http2.createServer(common.mustCall((request, response) => {
server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
const req = session.request();
req.on('response', (headers, flags) => {
req.on('response', common.mustCall((headers, flags) => {
assert.strictEqual(headers.date, 'snacks o clock');
});
}));
req.on('end', () => {
session.close();
server.close();
+10 -10
View File
@@ -4,41 +4,41 @@ if (!common.hasCrypto) { common.skip('missing crypto'); }
// Test for Http2ServerResponse#[writableCorked,cork,uncork]
const { strictEqual } = require('assert');
const assert = require('assert');
const http2 = require('http2');
{
let corksLeft = 0;
const server = http2.createServer(common.mustCall((req, res) => {
strictEqual(res.writableCorked, corksLeft);
assert.strictEqual(res.writableCorked, corksLeft);
res.write(Buffer.from('1'.repeat(1024)));
res.cork();
corksLeft++;
strictEqual(res.writableCorked, corksLeft);
assert.strictEqual(res.writableCorked, corksLeft);
res.write(Buffer.from('1'.repeat(1024)));
res.cork();
corksLeft++;
strictEqual(res.writableCorked, corksLeft);
assert.strictEqual(res.writableCorked, corksLeft);
res.write(Buffer.from('1'.repeat(1024)));
res.cork();
corksLeft++;
strictEqual(res.writableCorked, corksLeft);
assert.strictEqual(res.writableCorked, corksLeft);
res.write(Buffer.from('1'.repeat(1024)));
res.cork();
corksLeft++;
strictEqual(res.writableCorked, corksLeft);
assert.strictEqual(res.writableCorked, corksLeft);
res.uncork();
corksLeft--;
strictEqual(res.writableCorked, corksLeft);
assert.strictEqual(res.writableCorked, corksLeft);
res.uncork();
corksLeft--;
strictEqual(res.writableCorked, corksLeft);
assert.strictEqual(res.writableCorked, corksLeft);
res.uncork();
corksLeft--;
strictEqual(res.writableCorked, corksLeft);
assert.strictEqual(res.writableCorked, corksLeft);
res.uncork();
corksLeft--;
strictEqual(res.writableCorked, corksLeft);
assert.strictEqual(res.writableCorked, corksLeft);
res.end();
}));
server.listen(0, common.mustCall(() => {
+4 -4
View File
@@ -15,7 +15,7 @@ const {
const fname = fixtures.path('elipses.txt');
const server = http2.createServer();
server.on('stream', (stream) => {
server.on('stream', common.mustCall((stream) => {
assert.throws(() => {
stream.respondWithFile(fname, {
[HTTP2_HEADER_STATUS]: 204,
@@ -28,8 +28,8 @@ server.on('stream', (stream) => {
});
stream.respond({});
stream.end();
});
server.listen(0, () => {
}));
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
req.on('response', common.mustCall());
@@ -39,4 +39,4 @@ server.listen(0, () => {
server.close();
}));
req.end();
});
}));
+2 -2
View File
@@ -26,7 +26,7 @@ server.on('stream', (stream) => {
}
});
});
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
@@ -42,4 +42,4 @@ server.listen(0, () => {
server.close();
}));
req.end();
});
}));
+2 -2
View File
@@ -30,7 +30,7 @@ server.on('stream', (stream) => {
statCheck: common.mustNotCall()
});
});
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
@@ -44,4 +44,4 @@ server.listen(0, () => {
server.close();
}));
req.end();
});
}));
@@ -11,7 +11,7 @@ const fname = fixtures.path('elipses.txt');
const server = http2.createServer(common.mustCall((request, response) => {
response.stream.respondWithFile(fname);
}));
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
req.on('response', common.mustCall());
@@ -21,4 +21,4 @@ server.listen(0, () => {
}));
req.end();
req.resume();
});
}));
@@ -24,7 +24,7 @@ server.on('stream', (stream) => {
statCheck: common.mustNotCall()
});
});
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
@@ -38,4 +38,4 @@ server.listen(0, () => {
server.close();
}));
req.end();
});
}));
@@ -39,7 +39,7 @@ server.on('stream', (stream) => {
statCheck: common.mustNotCall()
});
});
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
@@ -53,7 +53,7 @@ server.listen(0, () => {
server.close();
}));
req.end();
});
}));
fs.writeFile(pipeName, 'Hello, world!\n', common.mustCall((err) => {
// It's possible for the reading end of the pipe to get the expected error
@@ -32,7 +32,7 @@ server.on('stream', (stream) => {
stream.respondWithFD(fd);
stream.on('error', errorCheck);
});
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
@@ -47,4 +47,4 @@ server.listen(0, () => {
server.close();
}));
req.end();
});
}));
@@ -30,7 +30,7 @@ function getOffsetLength(range) {
}
const server = http2.createServer();
server.on('stream', (stream, headers) => {
server.on('stream', common.mustCallAtLeast((stream, headers) => {
const [ offset, length ] = getOffsetLength(headers.range);
@@ -46,10 +46,10 @@ server.on('stream', (stream, headers) => {
offset: offset,
length: length
});
});
}));
server.on('close', common.mustCall(() => fs.closeSync(fd)));
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const countdown = new Countdown(2, () => {
@@ -91,4 +91,4 @@ server.listen(0, () => {
req.end();
}
});
}));
+2 -2
View File
@@ -26,7 +26,7 @@ server.on('stream', (stream) => {
});
});
server.on('close', common.mustCall(() => fs.closeSync(fd)));
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
@@ -44,4 +44,4 @@ server.listen(0, () => {
server.close();
}));
req.end();
});
}));
@@ -22,28 +22,27 @@ const stat = fs.statSync(fname);
const fd = fs.openSync(fname, 'r');
const server = http2.createServer();
server.on('stream', (stream) => {
server.on('stream', common.mustCall((stream) => {
stream.respond({});
stream.end();
stream.pushStream({
':path': '/file.txt',
':method': 'GET'
}, (err, stream) => {
assert.ifError(err);
}, common.mustSucceed((stream) => {
stream.respondWithFD(fd, {
[HTTP2_HEADER_CONTENT_TYPE]: 'text/plain',
[HTTP2_HEADER_CONTENT_LENGTH]: stat.size,
[HTTP2_HEADER_LAST_MODIFIED]: stat.mtime.toUTCString()
});
});
}));
stream.end();
});
}));
server.on('close', common.mustCall(() => fs.closeSync(fd)));
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
@@ -82,4 +81,4 @@ server.listen(0, () => {
req.on('end', maybeClose);
req.end();
});
}));
@@ -19,7 +19,7 @@ const data = fs.readFileSync(fname);
const stat = fs.statSync(fname);
const server = http2.createServer();
server.on('stream', (stream) => {
server.on('stream', common.mustCall((stream) => {
stream.respondWithFile(fname, {
[HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
}, {
@@ -29,8 +29,8 @@ server.on('stream', (stream) => {
offset: 8,
length: 3
});
});
server.listen(0, () => {
}));
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
@@ -50,4 +50,4 @@ server.listen(0, () => {
server.close();
}));
req.end();
});
}));
@@ -21,16 +21,16 @@ if (mkfifo.error && mkfifo.error.code === 'ENOENT') {
}
const server = http2.createServer();
server.on('stream', (stream) => {
server.on('stream', common.mustCall((stream) => {
stream.respondWithFile(pipeName, {
'content-type': 'text/plain'
}, {
onError: common.mustNotCall(),
statCheck: common.mustCall()
});
});
}));
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
@@ -46,7 +46,7 @@ server.listen(0, () => {
server.close();
}));
req.end();
});
}));
fs.open(pipeName, 'w', common.mustSucceed((fd) => {
fs.writeSync(fd, 'Hello, world!\n');
@@ -13,7 +13,7 @@ const {
const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
stream.on('error', (err) => assert.strictEqual(err.code, 'ECONNRESET'));
stream.on('error', common.mustCallAtLeast((err) => assert.strictEqual(err.code, 'ECONNRESET'), 0));
stream.respondWithFile(process.execPath, {
[HTTP2_HEADER_CONTENT_TYPE]: 'application/octet-stream'
});
+2 -2
View File
@@ -20,9 +20,9 @@ server.on('stream', common.mustCall((stream) => {
assert.strictEqual(stream.sentHeaders[':status'], 200);
assert.notStrictEqual(stream.sentHeaders.date, undefined);
stream.end();
stream.on('close', () => {
stream.on('close', common.mustCall(() => {
assert.strictEqual(stream.sentTrailers.xyz, 'abc');
});
}));
}));
server.listen(0, common.mustCall(() => {
+2 -2
View File
@@ -39,7 +39,7 @@ server.on('stream', (stream, headers) => {
});
});
server.listen(0, () => {
server.listen(0, common.mustCall(() => {
const secureContext = tls.createSecureContext({ ca });
const client = http2.connect(`https://localhost:${server.address().port}`,
@@ -76,4 +76,4 @@ server.listen(0, () => {
req2.on('data', common.mustNotCall());
req2.on('end', common.mustCall(() => maybeClose()));
});
}));
@@ -45,7 +45,7 @@ server.listen(0, common.mustCall(() => {
let data = '';
req.on('data', (d) => data += d);
req.on('end', () => {
req.on('end', common.mustCall(() => {
assert.strictEqual(body, data);
client.close();
client.on('close', common.mustCall(() => {
@@ -63,15 +63,15 @@ server.listen(0, common.mustCall(() => {
assert.strictEqual(headers['x-h2-header-3'], 'connection-test ');
}));
req2.on('data', (d) => data2 += d);
req2.on('end', () => {
req2.on('end', common.mustCall(() => {
assert.strictEqual(body, data2);
client2.close();
client2.on('close', common.mustCall(() => {
server2.close();
}));
});
}));
req2.end();
});
}));
req.end();
}));
@@ -8,7 +8,7 @@ const http2 = require('http2');
const body =
'<html><head></head><body><h1>this is some data</h2></body></html>';
const server = http2.createServer((req, res) => {
const server = http2.createServer(common.mustCallAtLeast((req, res) => {
assert.strictEqual(req.headers['x-powered-by'], undefined);
assert.strictEqual(req.headers.foobar, undefined);
assert.strictEqual(req.headers['x-h2-header'], undefined);
@@ -17,9 +17,9 @@ const server = http2.createServer((req, res) => {
assert.strictEqual(req.headers['x-h2-header-4'], undefined);
res.writeHead(200);
res.end(body);
});
}));
const server2 = http2.createServer({ strictFieldWhitespaceValidation: false }, (req, res) => {
const server2 = http2.createServer({ strictFieldWhitespaceValidation: false }, common.mustCallAtLeast((req, res) => {
assert.strictEqual(req.headers.foobar, 'baz ');
assert.strictEqual(req.headers['x-powered-by'], 'node-test\t');
assert.strictEqual(req.headers['x-h2-header'], '\tconnection-test');
@@ -28,7 +28,7 @@ const server2 = http2.createServer({ strictFieldWhitespaceValidation: false }, (
assert.strictEqual(req.headers['x-h2-header-4'], 'connection-test\t');
res.writeHead(200);
res.end(body);
});
}));
server.listen(0, common.mustCall(() => {
server2.listen(0, common.mustCall(() => {
@@ -52,7 +52,7 @@ server.listen(0, common.mustCall(() => {
let data = '';
req.on('data', (d) => data += d);
req.on('end', () => {
req.on('end', common.mustCall(() => {
assert.strictEqual(body, data);
client.close();
client.on('close', common.mustCall(() => {
@@ -66,15 +66,15 @@ server.listen(0, common.mustCall(() => {
assert.strictEqual(headers[':status'], 200);
}));
req2.on('data', (d) => data2 += d);
req2.on('end', () => {
req2.on('end', common.mustCall(() => {
assert.strictEqual(body, data2);
client2.close();
client2.on('close', common.mustCall(() => {
server2.close();
}));
});
}));
req2.end();
});
}));
req.end();
}));
@@ -50,7 +50,7 @@ server.listen(0, common.mustCall(() => {
assert.strictEqual(err.message, 'Session closed with error code 2');
}
}))
.on('close', () => {
.on('close', common.mustCall(() => {
server.removeAllListeners('error');
http2.connect(url)
.on('error', common.mustCall((err) => {
@@ -60,5 +60,5 @@ server.listen(0, common.mustCall(() => {
}
}))
.on('close', () => server.close());
});
}));
}));
@@ -27,11 +27,11 @@ server.listen(0, common.mustCall(() => {
let data = '';
req.on('data', (d) => data += d);
req.on('end', () => {
req.on('end', common.mustCall(() => {
assert.strictEqual(body, data);
server.close();
client.close();
});
}));
req.end();
}));
@@ -8,7 +8,7 @@ const assert = require('assert');
const http2 = require('http2');
// Verify that setTimeout callback verifications work correctly
const verifyCallbacks = (server) => {
const verifyCallbacks = common.mustCall((server) => {
const testTimeout = 10;
[true, 1, {}, [], null, 'test'].forEach((notFunction) => {
@@ -24,7 +24,7 @@ const verifyCallbacks = (server) => {
// No callback
const returnedVal = server.setTimeout(testTimeout);
assert.strictEqual(returnedVal.timeout, testTimeout);
};
}, 2);
// Test with server
{
@@ -25,7 +25,7 @@ server.on('secureConnection', common.mustCall((socket) => {
}));
}));
server.listen(0, function() {
server.listen(0, common.mustCall(() => {
// If the client does not send an ALPN connection, and the server has not been
// configured with allowHTTP1, then the server should destroy the socket
// after unknownProtocolTimeout.
@@ -45,4 +45,4 @@ server.listen(0, function() {
const allowedErrors = ['ECONNRESET', 'ERR_SSL_TLSV1_ALERT_NO_APPLICATION_PROTOCOL'];
assert.ok(allowedErrors.includes(err.code), `'${err.code}' was not one of ${allowedErrors}.`);
}));
});
}));
+2 -2
View File
@@ -21,7 +21,7 @@ const server = h2.createServer({
server.on(
'stream',
common.mustCall((stream) => {
const assertSettings = (settings) => {
const assertSettings = common.mustCall((settings) => {
assert.strictEqual(typeof settings, 'object');
assert.strictEqual(typeof settings.headerTableSize, 'number');
assert.strictEqual(typeof settings.enablePush, 'boolean');
@@ -48,7 +48,7 @@ server.on(
countCustom++;
}
assert.strictEqual(countCustom, 1);
};
}, 2);
const localSettings = stream.session.localSettings;
const remoteSettings = stream.session.remoteSettings;
@@ -33,7 +33,7 @@ server.listen(0, common.mustCall(() => {
// Ensures that the clients settings frames are not sent until the
// servers are received, so that the first ack is actually expected.
client.once('data', (chunk) => {
client.once('data', common.mustCall((chunk) => {
// The very first chunk of data we get from the server should
// be a settings frame.
assert.deepStrictEqual(chunk.slice(0, 9), kSettings.data);
@@ -41,7 +41,7 @@ server.listen(0, common.mustCall(() => {
client.write(kSettingsAck.data, () => countdown.dec());
// The second one is not and will be ignored.
client.write(kSettingsAck.data, () => countdown.dec());
});
}));
client.on('connect', common.mustCall(() => {
client.write(http2util.kClientMagic);
@@ -38,7 +38,7 @@ server.listen(0, common.mustCall(() => {
const notCallClose = common.mustNotCall();
setTimeout(() => {
setTimeout(common.mustCall(() => {
req.setEncoding('utf8');
req.removeListener('close', notCallClose);
req.on('close', common.mustCall(() => {
@@ -49,7 +49,7 @@ server.listen(0, common.mustCall(() => {
req.on('end', common.mustCall(() => {
assert.strictEqual(data, 'test');
}));
}, common.platformTimeout(100));
}), common.platformTimeout(100));
req.on('close', notCallClose);
}));
@@ -16,7 +16,7 @@ for (const prototype of ['maxHeaderListSize', 'maxHeaderSize']) {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
client.on('remoteSettings', () => {
client.on('remoteSettings', common.mustCall(() => {
const req = client.request({ 'foo': 'a'.repeat(1000) });
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
@@ -28,7 +28,7 @@ for (const prototype of ['maxHeaderListSize', 'maxHeaderSize']) {
server.close();
client.close();
}));
});
}));
}));
}
+2 -2
View File
@@ -20,10 +20,10 @@ server.on('stream', common.mustCall((stream) => {
assert.strictEqual(++c, 1);
stream.respond();
// Force some asynchronous stuff.
setImmediate(() => {
setImmediate(common.mustCall(() => {
stream.end('ok');
assert.strictEqual(--c, 0);
});
}));
}, 3));
server.listen(0, common.mustCall(() => {
+2 -2
View File
@@ -24,7 +24,7 @@ function onStream(stream, headers, flags) {
'content-type': 'text/html',
':status': 200
}, { waitForTrailers: true });
stream.on('wantTrailers', () => {
stream.on('wantTrailers', common.mustCall(() => {
stream.sendTrailers({ [trailerKey]: trailerValue });
assert.throws(
() => stream.sendTrailers({}),
@@ -33,7 +33,7 @@ function onStream(stream, headers, flags) {
name: 'Error'
}
);
});
}));
assert.throws(
() => stream.sendTrailers({}),
@@ -2,12 +2,12 @@
'use strict';
require('../common');
const { strictEqual, throws } = require('assert');
const assert = require('assert');
const { NghttpError } = require('internal/http2/util');
throws(() => {
assert.throws(() => {
const err = new NghttpError(-501);
strictEqual(err.errno, -501);
assert.strictEqual(err.errno, -501);
throw err;
}, {
code: 'ERR_HTTP2_ERROR',
@@ -18,5 +18,5 @@ throws(() => {
// Should convert the NghttpError object to string properly
{
const err = new NghttpError(401);
strictEqual(err.toString(), 'Error [ERR_HTTP2_ERROR]: Unknown error code');
assert.strictEqual(err.toString(), 'Error [ERR_HTTP2_ERROR]: Unknown error code');
}
@@ -11,7 +11,7 @@ if (!common.hasCrypto)
const { updateOptionsBuffer } = require('internal/http2/util');
const { internalBinding } = require('internal/test/binding');
const { optionsBuffer } = internalBinding('http2');
const { ok, strictEqual } = require('assert');
const assert = require('assert');
const IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE = 0;
const IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS = 1;
@@ -45,34 +45,34 @@ const IDX_OPTIONS_FLAGS = 13;
strictFieldWhitespaceValidation: false
});
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS], 2);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH], 3);
strictEqual(optionsBuffer[IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS], 4);
strictEqual(optionsBuffer[IDX_OPTIONS_PADDING_STRATEGY], 5);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_HEADER_LIST_PAIRS], 6);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_PINGS], 7);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS], 8);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SESSION_MEMORY], 9);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SETTINGS], 10);
strictEqual(optionsBuffer[IDX_OPTIONS_STREAM_RESET_RATE], 11);
strictEqual(optionsBuffer[IDX_OPTIONS_STREAM_RESET_BURST], 12);
strictEqual(optionsBuffer[IDX_OPTIONS_STRICT_HTTP_FIELD_WHITESPACE_VALIDATION], 1);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS], 2);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH], 3);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS], 4);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_PADDING_STRATEGY], 5);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_HEADER_LIST_PAIRS], 6);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_PINGS], 7);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS], 8);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SESSION_MEMORY], 9);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SETTINGS], 10);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_STREAM_RESET_RATE], 11);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_STREAM_RESET_BURST], 12);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_STRICT_HTTP_FIELD_WHITESPACE_VALIDATION], 1);
const flags = optionsBuffer[IDX_OPTIONS_FLAGS];
ok(flags & (1 << IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE));
ok(flags & (1 << IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS));
ok(flags & (1 << IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH));
ok(flags & (1 << IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS));
ok(flags & (1 << IDX_OPTIONS_PADDING_STRATEGY));
ok(flags & (1 << IDX_OPTIONS_MAX_HEADER_LIST_PAIRS));
ok(flags & (1 << IDX_OPTIONS_MAX_OUTSTANDING_PINGS));
ok(flags & (1 << IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS));
ok(flags & (1 << IDX_OPTIONS_MAX_SETTINGS));
ok(flags & (1 << IDX_OPTIONS_STREAM_RESET_RATE));
ok(flags & (1 << IDX_OPTIONS_STREAM_RESET_BURST));
ok(flags & (1 << IDX_OPTIONS_STRICT_HTTP_FIELD_WHITESPACE_VALIDATION));
assert.ok(flags & (1 << IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE));
assert.ok(flags & (1 << IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS));
assert.ok(flags & (1 << IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH));
assert.ok(flags & (1 << IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS));
assert.ok(flags & (1 << IDX_OPTIONS_PADDING_STRATEGY));
assert.ok(flags & (1 << IDX_OPTIONS_MAX_HEADER_LIST_PAIRS));
assert.ok(flags & (1 << IDX_OPTIONS_MAX_OUTSTANDING_PINGS));
assert.ok(flags & (1 << IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS));
assert.ok(flags & (1 << IDX_OPTIONS_MAX_SETTINGS));
assert.ok(flags & (1 << IDX_OPTIONS_STREAM_RESET_RATE));
assert.ok(flags & (1 << IDX_OPTIONS_STREAM_RESET_BURST));
assert.ok(flags & (1 << IDX_OPTIONS_STRICT_HTTP_FIELD_WHITESPACE_VALIDATION));
}
{
@@ -87,22 +87,22 @@ const IDX_OPTIONS_FLAGS = 13;
maxHeaderListPairs: 6
});
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS], 2);
strictEqual(optionsBuffer[IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS], 4);
strictEqual(optionsBuffer[IDX_OPTIONS_PADDING_STRATEGY], 5);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_HEADER_LIST_PAIRS], 6);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH], 0);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_PINGS], 0);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS], 2);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS], 4);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_PADDING_STRATEGY], 5);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_HEADER_LIST_PAIRS], 6);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH], 0);
assert.strictEqual(optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_PINGS], 0);
const flags = optionsBuffer[IDX_OPTIONS_FLAGS];
ok(flags & (1 << IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE));
ok(flags & (1 << IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS));
ok(flags & (1 << IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS));
ok(flags & (1 << IDX_OPTIONS_PADDING_STRATEGY));
ok(flags & (1 << IDX_OPTIONS_MAX_HEADER_LIST_PAIRS));
assert.ok(flags & (1 << IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE));
assert.ok(flags & (1 << IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS));
assert.ok(flags & (1 << IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS));
assert.ok(flags & (1 << IDX_OPTIONS_PADDING_STRATEGY));
assert.ok(flags & (1 << IDX_OPTIONS_MAX_HEADER_LIST_PAIRS));
ok(!(flags & (1 << IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH)));
ok(!(flags & (1 << IDX_OPTIONS_MAX_OUTSTANDING_PINGS)));
assert.ok(!(flags & (1 << IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH)));
assert.ok(!(flags & (1 << IDX_OPTIONS_MAX_OUTSTANDING_PINGS)));
}
@@ -7,7 +7,7 @@ const assert = require('assert');
const http2 = require('http2');
const server = http2.createServer();
server.on('stream', (stream, headers) => {
server.on('stream', common.mustCall((stream, headers) => {
assert.deepStrictEqual(headers, {
':scheme': 'http',
':authority': `localhost:${server.address().port}`,
@@ -19,7 +19,7 @@ server.on('stream', (stream, headers) => {
});
stream.session.destroy();
server.close();
});
}));
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}/`);
client.request({ ':path': '/', '': 'foo', 'bar': '' }).end();