From 6e8fa5361abba7e61767abde1e527c822e509ebe Mon Sep 17 00:00:00 2001 From: Robin Drexler Date: Tue, 6 Nov 2018 15:52:49 +0100 Subject: [PATCH] test: add tests for OutgoingMessage setTimeout These tests ensure that OutgoingMessage setTimeout method will call setTimeout on its socket Co-authored-by: ZauberNerd PR-URL: https://github.com/nodejs/node/pull/24148 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig --- .../parallel/test-http-outgoing-settimeout.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/parallel/test-http-outgoing-settimeout.js diff --git a/test/parallel/test-http-outgoing-settimeout.js b/test/parallel/test-http-outgoing-settimeout.js new file mode 100644 index 00000000000000..3dd27686153672 --- /dev/null +++ b/test/parallel/test-http-outgoing-settimeout.js @@ -0,0 +1,30 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); + +const { OutgoingMessage } = require('http'); + +{ + // tests for settimeout method with socket + const expectedMsecs = 42; + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.socket = { + setTimeout: common.mustCall((msecs) => { + assert.strictEqual(msecs, expectedMsecs); + }) + }; + outgoingMessage.setTimeout(expectedMsecs); +} + +{ + // tests for settimeout method without socket + const expectedMsecs = 23; + const outgoingMessage = new OutgoingMessage(); + outgoingMessage.setTimeout(expectedMsecs); + + outgoingMessage.emit('socket', { + setTimeout: common.mustCall((msecs) => { + assert.strictEqual(msecs, expectedMsecs); + }) + }); +}