Skip to content

Commit

Permalink
Added agent idle timeout configuration (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
parthverma1 authored Aug 16, 2024
1 parent 8240bdd commit 835feb0
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/requester/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ module.exports = {
options.agents = defaultOpts.agents;
options.extraCA = defaultOpts.extendedRootCA;
options.ignoreProxyEnvironmentVariables = defaultOpts.ignoreProxyEnvironmentVariables;
options.agentIdleTimeout = defaultOpts.agentIdleTimeout;

// Disable encoding of URL in postman-request in order to use pre-encoded URL object returned from
// toNodeUrl() function of postman-url-encoder
Expand Down
1 change: 1 addition & 0 deletions lib/requester/requester-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ RequesterPool = function (options, callback) {
strictSSL: _.get(options, 'requester.strictSSL'),
maxResponseSize: _.get(options, 'requester.maxResponseSize'),
protocolVersion: _.get(options, 'requester.protocolVersion'),
agentIdleTimeout: _.get(options, 'requester.agentIdleTimeout', 60 * 1000), // 60 seconds
// @todo drop support in v8
useWhatWGUrlParser: _.get(options, 'requester.useWhatWGUrlParser', false),
insecureHTTPParser: _.get(options, 'requester.insecureHTTPParser'),
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"node-oauth1": "1.3.0",
"performance-now": "2.1.0",
"postman-collection": "4.5.0",
"postman-request": "2.88.1-postman.38",
"postman-request": "2.88.1-postman.39",
"postman-sandbox": "5.1.1",
"postman-url-encoder": "3.0.5",
"serialised-error": "1.1.3",
Expand Down
109 changes: 109 additions & 0 deletions test/integration/requester-spec/agentIdleTimout.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
var expect = require('chai').expect;

(typeof window === 'undefined' ? describe : describe.skip)('Requester Spec: agentIdleTimeout', function () {
var testrun,
URL = 'https://postman-echo.com/get',
collection = {
item: [{
request: {
url: URL,
method: 'GET'
}
}, {
request: {
url: URL,
method: 'GET'
}
}]
};

describe('with no time gap between requests', function () {
before(function (done) {
this.run({
collection
}, function (err, results) {
testrun = results;
done(err);
});
});

it('should have secureConnect time as zero', function () {
var response = testrun.response.getCall(1).args[2],
history = testrun.request.getCall(1).args[6],
timings;

expect(history).to.have.property('execution').that.include.property('data');
timings = history.execution.data[0].timings;

expect(response).to.have.property('responseTime');
expect(timings.offset.secureConnect - timings.offset.lookup).to.equal(0);
});
});
describe('with time gap greater than agentIdleTimeout between requests', function () {
before(function (done) {
const newCollection = JSON.parse(JSON.stringify(collection));

newCollection.item[1].event = [{
listen: 'prerequest',
script: { exec: [
'setTimeout(function () {}, 500);'
] }
}];
this.run({
collection: newCollection,
requester: {
agentIdleTimeout: 100
}
}, function (err, results) {
testrun = results;
done(err);
});
});

it('should have secureConnect time greater than zero', function () {
var response = testrun.response.getCall(1).args[2],
history = testrun.request.getCall(1).args[6],
timings;

expect(history).to.have.property('execution').that.include.property('data');
timings = history.execution.data[0].timings;

expect(response).to.have.property('responseTime');
expect(timings.offset.secureConnect - timings.offset.lookup).greaterThan(0);
});
});

describe('with time gap less than agentIdleTimeout between requests', function () {
before(function (done) {
const newCollection = JSON.parse(JSON.stringify(collection));

newCollection.item[1].event = [{
listen: 'prerequest',
script: { exec: [
'setTimeout(function () {}, 100);'
] }
}];
this.run({
collection: newCollection,
requester: {
agentIdleTimeout: 1000
}
}, function (err, results) {
testrun = results;
done(err);
});
});

it('should have secureConnect time zero', function () {
var response = testrun.response.getCall(1).args[2],
history = testrun.request.getCall(1).args[6],
timings;

expect(history).to.have.property('execution').that.include.property('data');
timings = history.execution.data[0].timings;

expect(response).to.have.property('responseTime');
expect(timings.offset.secureConnect - timings.offset.lookup).equal(0);
});
});
});

0 comments on commit 835feb0

Please sign in to comment.