Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- "4"
- "5"
- "6"
- "8"
env:
- CXX=g++-4.8
addons:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"length-prefixed-message": "^3.0.3",
"length-prefixed-stream": "~1.4.0",
"limitd-protocol": "limitd/protocol#v2.0.1",
"lodash": "~3.7.0",
"ms": "^1.0.0",
"lodash": "^4.17.5",
"ms": "^2.1.1",
"reconnect-net": "^1.1.1",
"retry": "^0.10.1",
"tcp-client-failover": "^1.0.2"
Expand Down
11 changes: 8 additions & 3 deletions shard_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ const defaults = {
port: 9231
};

function ShardClient(options) {
function ShardClient(options, deps) {
deps = deps || {};

if (typeof options !== 'object' || typeof options.shard !== 'object') {
throw new Error('shard is required');
}

EventEmitter.call(this);

this._LimitdClient = deps.LimitdClient || LimitdClient;
this._dns = deps.dns || dns;

this._options = _.extend({}, defaults, options);
this._clientParams = _.omit(this._options, ['shard', 'port']);

Expand Down Expand Up @@ -48,7 +53,7 @@ util.inherits(ShardClient, EventEmitter);


ShardClient.prototype.createClient = function(host) {
const client = new LimitdClient(_.extend(this._clientParams, { host }));
const client = new this._LimitdClient(_.extend(this._clientParams, { host }));
if (client instanceof EventEmitter) {
//map the events from LimitdClient.
//Last parameter is always the underlying client.
Expand All @@ -65,7 +70,7 @@ ShardClient.prototype.createClient = function(host) {
};

ShardClient.prototype.discover = function() {
dns.resolve(this.autodiscover.address, this.autodiscover.type || 'A', (err, ips) => {
this._dns.resolve(this.autodiscover.address, this.autodiscover.type || 'A', (err, ips) => {
setTimeout(() => this.discover(), this.autodiscover.refreshInterval);
if (err) {
return this.emit('error', err);
Expand Down
Loading