0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

http2: remove unused onTimeout, add timeout tests

Remove unused onTimeout on Http2Session and Http2Stream because
the correct _onTimeout is already declared and in use. Expand
timeout tests to handle edge cases and additional arguments.

PR-URL: https://github.com/nodejs/node/pull/15539
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Anatoli Papirovski 2017-09-21 14:52:09 -04:00 committed by Ruben Bridgewater
parent b2eb98721e
commit 33760ccc18
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
3 changed files with 30 additions and 19 deletions

View File

@ -2138,23 +2138,8 @@ const setTimeout = {
return this;
}
};
const onTimeout = {
configurable: false,
enumerable: false,
value: function() {
process.nextTick(emit.bind(this, 'timeout'));
}
};
Object.defineProperties(Http2Stream.prototype, {
setTimeout,
onTimeout
});
Object.defineProperties(Http2Session.prototype, {
setTimeout,
onTimeout
});
Object.defineProperty(Http2Stream.prototype, 'setTimeout', setTimeout);
Object.defineProperty(Http2Session.prototype, 'setTimeout', setTimeout);
// --------------------------------------------------------------------

View File

@ -54,7 +54,7 @@ assert.doesNotThrow(() => {
if (client)
client.end();
}));
server.setTimeout(common.platformTimeout(1000));
server.setTimeout(common.platformTimeout(1000), common.mustCall());
server.listen(0, common.mustCall(() => {
const port = server.address().port;
client = net.connect(port, common.mustCall());
@ -70,7 +70,7 @@ assert.doesNotThrow(() => {
if (client)
client.end();
}));
server.setTimeout(common.platformTimeout(1000));
server.setTimeout(common.platformTimeout(1000), common.mustCall());
server.listen(0, common.mustCall(() => {
const port = server.address().port;
client = tls.connect({

View File

@ -14,6 +14,32 @@ server.on('stream', common.mustCall((stream) => {
stream.respond({ ':status': 200 });
stream.end('hello world');
}));
// check that expected errors are thrown with wrong args
common.expectsError(
() => stream.setTimeout('100'),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "msecs" argument must be of type number'
}
);
common.expectsError(
() => stream.setTimeout(0, Symbol('test')),
{
code: 'ERR_INVALID_CALLBACK',
type: TypeError,
message: 'Callback must be a function'
}
);
common.expectsError(
() => stream.setTimeout(100, {}),
{
code: 'ERR_INVALID_CALLBACK',
type: TypeError,
message: 'Callback must be a function'
}
);
}));
server.listen(0);