Skip to content

Commit

Permalink
call the callback with an error if admin join fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed Jan 22, 2015
1 parent fcef1d1 commit 4c08fdd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ RingPop.prototype.bootstrap = function bootstrap(bootstrapFile, callback) {
err: err.message,
address: self.hostPort
});
if (callback) callback(new Error(failedMsg));
if (callback) callback(err);
return;
}

Expand Down
14 changes: 14 additions & 0 deletions lib/swim.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
// 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.
var TypedError = require('error/typed');

var NoHostsError = TypedError({
message: 'Could not find any hosts in bootstrap to join.\n' +
'Try adding more bootstrapHosts.\n',
type: 'ringpop.swim.no-hosts',
bootstrapHosts: null
});

var safeParse = require('./util').safeParse;

function AdminJoiner(params) {
Expand Down Expand Up @@ -50,6 +59,11 @@ AdminJoiner.prototype.selectCandidateHosts = function selectCandidateHosts() {
AdminJoiner.prototype.sendJoin = function sendJoin() {
if (this.candidateHosts.length === 0) {
this.ringpop.logger.warn('no hosts in bootstrap set to join');
if (this.callback) {
this.callback(NoHostsError({
bootstrapHosts: this.ringpop.bootstrapHosts
}));
}
return;
}

Expand Down
17 changes: 17 additions & 0 deletions test/integration/admin_join_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var test = require('tape');

var allocRingpop = require('../lib/alloc-ringpop.js');

test('bootstrap with self', function t(assert) {
var ringpop = allocRingpop();

ringpop.bootstrap([ringpop.hostPort], onBootstrap);

function onBootstrap(err) {
assert.ok(err);
assert.equal(err.type, 'ringpop.swim.no-hosts');

ringpop.destroy();
assert.end();
}
});
1 change: 1 addition & 0 deletions test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ require('./handle_or_proxy_test.js');
require('./lookup_self_test.js');
require('./proxy_req_test.js');
require('./request_proxy_test.js');
require('./admin_join_test.js');

0 comments on commit 4c08fdd

Please sign in to comment.