From 33760ccc18e4be10cce3d39f59d374881c49ee2e Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Thu, 21 Sep 2017 14:52:09 -0400 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater --- lib/internal/http2/core.js | 19 ++-------------- test/parallel/test-http2-server-startup.js | 4 ++-- test/parallel/test-http2-timeouts.js | 26 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 0ea3ca75f4d..bc41cd4bf91 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -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); // -------------------------------------------------------------------- diff --git a/test/parallel/test-http2-server-startup.js b/test/parallel/test-http2-server-startup.js index 1d236d2e65f..ba7c3f1f251 100644 --- a/test/parallel/test-http2-server-startup.js +++ b/test/parallel/test-http2-server-startup.js @@ -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({ diff --git a/test/parallel/test-http2-timeouts.js b/test/parallel/test-http2-timeouts.js index a45b13826f6..e1382e6e03e 100644 --- a/test/parallel/test-http2-timeouts.js +++ b/test/parallel/test-http2-timeouts.js @@ -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);