Compare commits

...

1 Commits

Author SHA1 Message Date
Ashcon Partovi
f6278eccfe fix: test-http-outgoing-settimeout.js 2025-03-21 14:38:46 -07:00
2 changed files with 45 additions and 3 deletions

View File

@@ -1697,6 +1697,10 @@ const OutgoingMessagePrototype = {
// even if it will be rescheduled we don't want to leak an existing timer.
clearTimeout(this[timeoutTimerSymbol]);
if (callback) {
this.on('timeout', callback);
}
if (msecs === 0) {
if (callback != null) {
if (!$isCallable(callback)) validateFunction(callback, "callback");
@@ -1707,9 +1711,13 @@ const OutgoingMessagePrototype = {
} else {
this[timeoutTimerSymbol] = setTimeout(onTimeout.bind(this), msecs).unref();
if (callback != null) {
if (!$isCallable(callback)) validateFunction(callback, "callback");
this.once("timeout", callback);
// Node.js compatibility: also delegate to socket if available
if (!this[fakeSocketSymbol]) {
this.once('socket', function socketSetTimeoutOnConnect(socket) {
socket.setTimeout(msecs);
});
} else {
this[fakeSocketSymbol].setTimeout(msecs);
}
}
@@ -1726,7 +1734,11 @@ const OutgoingMessagePrototype = {
},
set socket(value) {
const prev = this[fakeSocketSymbol];
this[fakeSocketSymbol] = value;
if (!prev && value) {
this.emit('socket', value);
}
},
get chunkedEncoding() {

View File

@@ -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);
})
});
}