Skip to content

Commit

Permalink
Use 0 retryLimit for protocol calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jwolski committed Dec 2, 2015
1 parent 2b93a44 commit bbc0bf6
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 5 deletions.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Config.prototype._seed = function _seed(seed) {
});
}, 'expected to be array of RegExp objects');
seedOrDefault('membershipUpdateRollupEnabled', false);
seedOrDefault('tchannelRetryLimit', 0);

function seedOrDefault(name, defaultVal, validator, reason) {
var seedVal = seed[name];
Expand Down
3 changes: 2 additions & 1 deletion lib/gossip/damper.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ Damper.prototype._fanoutDampReqs = function _fanoutDampReqs(flapperAddrs, dampRe
this.ringpop.stat('increment', 'damp-req.send');
this.ringpop.client.protocolDampReq({
host: dampReqAddr,
timeout: this.ringpop.config.get('dampReqTimeout')
timeout: this.ringpop.config.get('dampReqTimeout'),
retryLimit: this.ringpop.config.get('tchannelRetryLimit')
}, request,
createDampReqHandler(dampReqAddr));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/gossip/joiner.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ Joiner.prototype.joinNode = function joinNode(node, callback) {
var self = this;
self.ringpop.client.protocolJoin({
host: node,
retryLimit: 1,
retryLimit: self.ringpop.config.get('tchannelRetryLimit'),
timeout: this.joinTimeout
}, {
app: this.ringpop.app,
Expand Down
2 changes: 1 addition & 1 deletion lib/gossip/ping-req-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ PingReqSender.prototype.send = function send() {

this.ring.client.protocolPingReq({
host: this.member.address,
retryLimit: 1,
retryLimit: this.ring.config.get('tchannelRetryLimit'),
timeout: this.ring.pingReqTimeout
}, {
checksum: this.ring.membership.checksum,
Expand Down
2 changes: 1 addition & 1 deletion lib/gossip/ping-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ PingSender.prototype.send = function send() {
var self = this;
this.ring.client.protocolPing({
host: this.address,
retryLimit: 1,
retryLimit: this.ring.config.get('tchannelRetryLimit'),
timeout: this.ring.pingTimeout
}, {
checksum: this.ring.membership.checksum,
Expand Down
2 changes: 1 addition & 1 deletion lib/request-proxy/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ RequestProxySend.prototype.send = function send(channelOpts, callback) {
self.ringpop.channel.request(
_.extend({
hasNoParent: true,
retryLimit: 1,
retryLimit: self.ringpop.config.get('tchannelRetryLimit'),
headers: {
'as': 'raw',
'cn': 'ringpop'
Expand Down
106 changes: 106 additions & 0 deletions test/unit/client_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) 2015 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
'use strict';

var Client = require('../../client.js');
var test = require('tape');

test('retryLimit for protocol calls', function t(assert) {
var retryLimit = 99;
var noop = function noop() {};

// Stub client's subchannel. Let it stand in for the request made
// against TChannel and verify the retryLimit that is used.
var subChannel = {
waitForIdentified: function waitForIdentified(opts, callback) {
callback();
},
request: function request(opts) {
assert.equal(opts.retryLimit, retryLimit, 'retry limit is used');
return {
send: noop
};
}
};
var client = new Client(subChannel);

// Iterate over the Client's prototype looking for protocol*
// functions. When found, call it and make sure the retry limit
// is plumbed through correctly.
var protocolFns = [];
var clientPrototype = Client.prototype;
for (var propertyName in clientPrototype) {
if (clientPrototype.hasOwnProperty(propertyName)) {
var property = client[propertyName];
if (typeof property === 'function' &&
property.name.indexOf('protocol') === 0) {
protocolFns.push(property);
}
}
}

// Assert that at least one protocol* function is called on
// the Client object and that 1 assertion is made per protocol
// function called.
assert.plan(protocolFns.length + 1);
assert.true(protocolFns.length > 0, 'at least one protocol function');

// opts, body and callback are arguments to the procotol* functions
var opts = {
host: '127.0.0.1:3000',
retryLimit: retryLimit
};
var body = {};
var callback = noop;
protocolFns.forEach(function eachFn(fn) {
fn.call(client, opts, body, callback);
});

client.destroy();
assert.end();
});

test('retryLimit defaults to 0', function t(assert) {
assert.plan(1);

// Stub client's subchannel. Let it stand in for the request made
// against TChannel and verify the retryLimit that is used.
var subChannel = {
waitForIdentified: function waitForIdentified(opts, callback) {
callback();
},
request: function request(opts) {
assert.equal(opts.retryLimit, 0, 'retry limit defaults to 0');
return {
send: noop
};
}
};
var client = new Client(subChannel);

var nobody = {};
var noop = function noop() {};
client.protocolPing({
host: '127.0.0.1:3000',
retryLimit: null
}, nobody, noop);
client.destroy();
assert.end();
});

0 comments on commit bbc0bf6

Please sign in to comment.