node/test/parallel/test-http2-server-timeout.js
Andrey Pechkurov 51e8f28dcc
doc,test: add server.timeout property to http2 public API
Both http and https modules have server.timeout property
in public API. This commit adds documentation section and test
for server.timeout in http2 module, so it becomes consistent
with http and https.

Also improves description of callback argument in documentation
for server.setTimeout().

PR-URL: https://github.com/nodejs/node/pull/31693
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-03-11 19:33:48 +01:00

32 lines
899 B
JavaScript
Executable File

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
function testServerTimeout(setTimeoutFn) {
const server = http2.createServer();
setTimeoutFn(server);
const onServerTimeout = common.mustCall((session) => {
session.close();
});
server.on('stream', common.mustNotCall());
server.once('timeout', onServerTimeout);
server.listen(0, common.mustCall(() => {
const url = `http://localhost:${server.address().port}`;
const client = http2.connect(url);
client.on('close', common.mustCall(() => {
const client2 = http2.connect(url);
client2.on('close', common.mustCall(() => server.close()));
}));
}));
}
const timeout = common.platformTimeout(50);
testServerTimeout((server) => server.setTimeout(timeout));
testServerTimeout((server) => server.timeout = timeout);