Skip to content

Commit

Permalink
global: remove socket limit - fixes #522
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed May 5, 2015
1 parent 98a2153 commit 4188eb3
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 12 deletions.
6 changes: 5 additions & 1 deletion lib/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
6 changes: 5 additions & 1 deletion lib/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
11 changes: 11 additions & 0 deletions test/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
Expand Down
11 changes: 11 additions & 0 deletions test/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions test/pubsub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion test/storage/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 12 additions & 4 deletions test/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 4188eb3

Please sign in to comment.