diff --git a/lib/common/util.js b/lib/common/util.js index da91181546c..84a4f0d73cb 100644 --- a/lib/common/util.js +++ b/lib/common/util.js @@ -23,7 +23,11 @@ var extend = require('extend'); var GoogleAuth = require('google-auth-library'); -var request = require('request'); +var request = require('request').defaults({ + pool: { + maxSockets: Infinity + } +}); var nodeutil = require('util'); var uuid = require('node-uuid'); diff --git a/lib/datastore/request.js b/lib/datastore/request.js index 1dd01c28773..9c56f83945e 100644 --- a/lib/datastore/request.js +++ b/lib/datastore/request.js @@ -21,7 +21,11 @@ 'use strict'; var streamEvents = require('stream-events'); -var request = require('request'); +var request = require('request').defaults({ + pool: { + maxSockets: Infinity + } +}); var through = require('through2'); /** diff --git a/lib/storage/file.js b/lib/storage/file.js index 11a2fd2bf78..2a9a40e2775 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -27,7 +27,11 @@ var crypto = require('crypto'); var duplexify = require('duplexify'); var fs = require('fs'); var once = require('once'); -var request = require('request'); +var request = require('request').defaults({ + pool: { + maxSockets: Infinity + } +}); var streamEvents = require('stream-events'); var through = require('through2'); diff --git a/test/common/util.js b/test/common/util.js index 9d9c6041a82..12eba95f002 100644 --- a/test/common/util.js +++ b/test/common/util.js @@ -32,10 +32,17 @@ function fakeGoogleAuthLibrary() { .apply(null, arguments); } +var REQUEST_DEFAULT_CONF; var request_Override; function fakeRequest() { return (request_Override || request).apply(null, arguments); } +fakeRequest.defaults = function(defaultConfiguration) { + // Ignore the default values, so we don't have to test for them in every API + // call. + REQUEST_DEFAULT_CONF = defaultConfiguration; + return fakeRequest; +}; describe('common/util', function() { var util; @@ -72,6 +79,10 @@ describe('common/util', function() { utilOverrides = {}; }); + it('should have set correct defaults on Request', function() { + assert.deepEqual(REQUEST_DEFAULT_CONF, { pool: { maxSockets: Infinity } }); + }); + describe('arrayize', function() { it('should arrayize if the input is not an array', function() { assert.deepEqual(util.arrayize('text'), ['text']); diff --git a/test/datastore/request.js b/test/datastore/request.js index bd39a75d512..2e623ceac4a 100644 --- a/test/datastore/request.js +++ b/test/datastore/request.js @@ -29,10 +29,17 @@ var requestModule = require('request'); var stream = require('stream'); var util = require('../../lib/common/util.js'); +var REQUEST_DEFAULT_CONF; var request_Override; function fakeRequest() { return (request_Override || requestModule).apply(null, arguments); } +fakeRequest.defaults = function(defaultConfiguration) { + // Ignore the default values, so we don't have to test for them in every API + // call. + REQUEST_DEFAULT_CONF = defaultConfiguration; + return fakeRequest; +}; // Create a protobuf "FakeMethod" request & response. pb.FakeMethodRequest = function() { @@ -83,6 +90,10 @@ describe('Request', function() { }; }); + it('should have set correct defaults on Request', function() { + assert.deepEqual(REQUEST_DEFAULT_CONF, { pool: { maxSockets: Infinity } }); + }); + describe('get', function() { it('should get by key', function(done) { request.makeReq_ = function(method, req, callback) { diff --git a/test/pubsub/index.js b/test/pubsub/index.js index e8b26ed6e7b..9ec0e5fd31c 100644 --- a/test/pubsub/index.js +++ b/test/pubsub/index.js @@ -26,12 +26,14 @@ var Topic = require('../../lib/pubsub/topic.js'); var request_Cached = request; var request_Override; - function fakeRequest() { - var args = [].slice.apply(arguments); - var results = (request_Override || request_Cached).apply(null, args); - return results; + return (request_Override || request_Cached).apply(null, arguments); } +fakeRequest.defaults = function() { + // Ignore the default values, so we don't have to test for them in every API + // call. + return fakeRequest; +}; describe('PubSub', function() { var PubSub; diff --git a/test/storage/bucket.js b/test/storage/bucket.js index e1dee8d6617..efd8d32f0b8 100644 --- a/test/storage/bucket.js +++ b/test/storage/bucket.js @@ -47,10 +47,14 @@ function FakeFile(bucket, name) { var request_Cached = request; var request_Override; - function fakeRequest() { return (request_Override || request_Cached).apply(null, arguments); } +fakeRequest.defaults = function() { + // Ignore the default values, so we don't have to test for them in every API + // call. + return fakeRequest; +}; var eachLimit_Override; diff --git a/test/storage/file.js b/test/storage/file.js index 76ed3b9b071..b56fab36bd9 100644 --- a/test/storage/file.js +++ b/test/storage/file.js @@ -58,14 +58,18 @@ var fakeUtil = extend({}, util, { } }); +var REQUEST_DEFAULT_CONF; var request_Cached = request; var request_Override; - function fakeRequest() { - var args = util.toArray(arguments); - var results = (request_Override || request_Cached).apply(null, args); - return results; + return (request_Override || request_Cached).apply(null, arguments); } +fakeRequest.defaults = function(defaultConfiguration) { + // Ignore the default values, so we don't have to test for them in every API + // call. + REQUEST_DEFAULT_CONF = defaultConfiguration; + return fakeRequest; +}; var configStoreData = {}; function FakeConfigStore() { @@ -125,6 +129,10 @@ describe('File', function() { request_Override = null; }); + it('should have set correct defaults on Request', function() { + assert.deepEqual(REQUEST_DEFAULT_CONF, { pool: { maxSockets: Infinity } }); + }); + describe('initialization', function() { it('should throw if no name is provided', function() { assert.throws(function() {