From 0db58753db9b1fc9379833597cf57b96ba967d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E9=81=93?= Date: Wed, 8 Apr 2020 23:43:30 +0800 Subject: [PATCH] lib: fix return type of setTimeout in net.Socket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Function setTimeout in net.Socket should return this, not undefined, as doc said. PR-URL: https://github.com/nodejs/node/pull/32722 Refs: https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Zeyu Yang Reviewed-By: Gerhard Stöbich Reviewed-By: Luigi Pinca Reviewed-By: Robert Nagy Reviewed-By: Yongsheng Zhang Reviewed-By: James M Snell Reviewed-By: Trivikram Kamat --- lib/internal/stream_base_commons.js | 2 +- test/parallel/test-net-socket-timeout.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js index 2a31221f11d2d6..df26119be0fca4 100644 --- a/lib/internal/stream_base_commons.js +++ b/lib/internal/stream_base_commons.js @@ -233,7 +233,7 @@ function onStreamRead(arrayBuffer) { function setStreamTimeout(msecs, callback) { if (this.destroyed) - return; + return this; this.timeout = msecs; diff --git a/test/parallel/test-net-socket-timeout.js b/test/parallel/test-net-socket-timeout.js index 8b197b44d61281..e01304afe53f01 100644 --- a/test/parallel/test-net-socket-timeout.js +++ b/test/parallel/test-net-socket-timeout.js @@ -70,8 +70,12 @@ for (let i = 0; i < invalidCallbacks.length; i++) { const server = net.Server(); server.listen(0, common.mustCall(() => { const socket = net.createConnection(server.address().port); - socket.setTimeout(1, common.mustCall(() => { - socket.destroy(); - server.close(); - })); + assert.strictEqual( + socket.setTimeout(1, common.mustCall(() => { + socket.destroy(); + assert.strictEqual(socket.setTimeout(1, common.mustNotCall()), socket); + server.close(); + })), + socket + ); }));