Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

Add integration tests for identities #92

Merged
merged 5 commits into from
Dec 15, 2016
Merged
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
84 changes: 84 additions & 0 deletions test/identity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) 2016 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.

var _ = require('lodash');

var dsl = require('./ringpop-assert');
var events = require('./events');
var getClusterSizes = require('./it-tests').getClusterSizes;
var prepareCluster = require('./test-util').prepareCluster;
var prepareWithStatus = require('./test-util').prepareWithStatus;
var test2 = require('./test-util').test2;

test2('ringpop should set it\'s identity during bootstrap', getClusterSizes(2), 20000, function init(t, tc, callback) {
tc.sutIdentity = 'identity';

callback();
}, prepareCluster(function(t, tc, n) {
return [
dsl.assertStats(t, tc, n + 1, 0, 0, {
'sut': {
labels: {"__identity": "identity"}
}
})
];
})
);

test2('ringpop - with identity - full lookup returns correct values', getClusterSizes(1), 20000, function init(t, tc, callback) {
tc.sutIdentity = 'sut';
tc.fakeNodes[0].labels = {'__identity' : 'fake-node'}

callback();
}, prepareCluster(function(t, tc, n) {
return dsl.assertFullHashring(t, tc, {0: 'fake-node', 'sut': 'sut'});
}));

test2('ringpop - when identity changes, hashring is updated', getClusterSizes(1), 20000, prepareCluster(function(t, tc, n) {
return [
dsl.assertFullHashring(t, tc),
dsl.changeStatus(t, tc, 0, 0, {
subjectIncNoDelta: +1,
status: 'alive',
labels: {
'__identity': 'identity'
}
}),
dsl.waitForPingResponse(t, tc, 0),
dsl.assertFullHashring(t, tc, {0: 'identity'}), // validate change from no identity to 'identity'
dsl.changeStatus(t, tc, 0, 0, {
subjectIncNoDelta: +1,
status: 'alive',
labels: {
'__identity': 'identity2'
}
}),
dsl.waitForPingResponse(t, tc, 0),
dsl.assertFullHashring(t, tc, {0: 'identity2'}), // validate change from 'identity' to 'identity2'

dsl.changeStatus(t, tc, 0, 0, {
subjectIncNoDelta: +1,
status: 'alive',
labels: {}
}),
dsl.waitForPingResponse(t, tc, 0),
dsl.assertFullHashring(t, tc) // validate change from 'identity2' to no identity
]
}));
6 changes: 6 additions & 0 deletions test/it-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ var features = {
tests: [
'./lookup-tests'
]
},
'identity': {
mandatory: false,
tests: [
'./identity'
]
}
};

Expand Down
16 changes: 1 addition & 15 deletions test/lookup-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,7 @@ var prepareCluster = require('./test-util').prepareCluster;
var test2 = require('./test-util').test2;

test2('ringpop full lookup returns correct values', getClusterSizes(1), 20000, prepareCluster(function(t, tc, n) {
var membership = tc.getMembership();
var hostPorts = _.map(membership, function(member) {
return member.host + ':' + member.port;
});

// Loop through all hostPorts
return _.map(hostPorts, function eachHostPort(hostPort) {
// And all replica points
return _.times(tc.replicaPoints, function eachReplicaPoint(index) {
var replicaPoint = hostPort + index;

// And validate if a lookup on it results in the right hostPort
return dsl.assertLookup(t, tc, replicaPoint, hostPort);
});
});
return dsl.assertFullHashring(t, tc);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is extracted so it can be re-used by the identity tests.

}));

test2('ringpop lookup of faulty member should return different member', getClusterSizes(2), 20000, prepareCluster(function(t, tc){
Expand Down
58 changes: 53 additions & 5 deletions test/ringpop-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,13 @@ function callEndpoint(t, tc, endpoint, body, validateEvent) {
*/
function assertLookup(t, tc, key, expected) {
return [
callEndpoint(t, tc, '/admin/lookup', {key: key}),
callEndpoint(t, tc, '/admin/lookup', {key: key}, function validate(body) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By adding the validate-callback we fail earlier; without it we fail by timeout.

if(typeof expected === 'function') {
expected(body);
} else {
t.equals(body.dest, expected);
}
}),
validateLookupResponse
];

Expand All @@ -454,6 +460,41 @@ function assertLookup(t, tc, key, expected) {
}
}

function assertLookups(t, tc, mapping) {
return _.map(mapping, function(expected, key) {
return assertLookup(t, tc, key, expected);
});
}

function assertFullHashring(t, tc, identities) {
var identityMapping = _.reduce(identities, function(mapping, value, index) {
var hostPort;
if (index === 'sut') {
hostPort = tc.getSUTHostPort();
} else {
hostPort = tc.fakeNodes[index].getHostPort();
}
mapping[hostPort] = value;
return mapping;
}, {});

var membership = tc.getMembership();
var mapping = _.reduce(membership, function(mapping, member) {
// and all replica points
_.times(tc.replicaPoints, function eachReplicaPoint(index) {
var hostPort = member.host + ':' + member.port;

var identity = identityMapping[hostPort] || hostPort;
var replicaPoint = identity + index;
// and add a mapping for the replica-point to the hostPort
mapping[replicaPoint] = hostPort;
});
return mapping;
}, {});

return assertLookups(t, tc, mapping);
}

function assertCorrectIncarnationNumbers(t, tc) {
return [
requestAdminStats(tc),
Expand Down Expand Up @@ -531,9 +572,14 @@ function waitForStatsAssertMembership(t, tc, members) {
var stats = safeJSONParse(list[ix].arg3);
var statsMembers = stats.membership.members;
_.forEach(members, function(member, i) {
// find member i in statsMembers
var ix = _.findIndex(statsMembers, {address: tc.fakeNodes[i].getHostPort()});
var received = statsMembers[ix];
var hostPort;
if (i === 'sut') {
hostPort = tc.getSUTHostPort();
} else {
// find member i in statsMembers
hostPort = tc.fakeNodes[i].getHostPort();
}
var received = _.find(statsMembers, {address: hostPort});

if (typeof member === 'function') {
// use the function to test the received member object
Expand All @@ -542,7 +588,7 @@ function waitForStatsAssertMembership(t, tc, members) {
// test the received object to the expected object field by field
var expected = member;
_.forEach(member, function(value, field) {
t.deepEqual(statsMembers[ix][field], value, 'assert membership', errDetails({ expected: expected, received: received}));
t.deepEqual(received[field], value, 'assert membership', errDetails({ expected: expected, received: received}));
});
}
});
Expand Down Expand Up @@ -1045,6 +1091,8 @@ module.exports = {
assertCorrectIncarnationNumbers: assertCorrectIncarnationNumbers,
assertBumpedIncarnationNumber: assertBumpedIncarnationNumber,
assertLookup: assertLookup,
assertLookups: assertLookups,
assertFullHashring: assertFullHashring,

disableNode: disableNode,
disableAllNodes: disableAllNodes,
Expand Down
6 changes: 6 additions & 0 deletions test/test-coordinator.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function TestCoordinator(options) {
this.sutHostPort = makeHostPort('127.0.0.1', _.random(10000, 30000));
this.sutProgram = options.sut.program;
this.sutInterpreter = options.sut.interpreter;
this.sutIdentity = undefined;
this.suspectPeriod = 5000;
this.faultyPeriod = 5000;
this.tombstonePeriod = 5000;
Expand Down Expand Up @@ -172,6 +173,11 @@ TestCoordinator.prototype.startSUT = function startSUT() {
program = this.sutInterpreter
args.push(this.sutProgram)
}

if (this.sutIdentity) {
args.push(util.format('--identity=%s', this.sutIdentity));
}

args.push(util.format('--hosts=%s', this.hostsFile));
args.push(util.format('--listen=%s', this.sutHostPort));
args.push(util.format('--suspect-period=%d', this.suspectPeriod));
Expand Down