Skip to content

Commit

Permalink
SMC-3989: All tests now using sequential ports, base ports configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
JancoHY committed Sep 17, 2021
1 parent 62a9dc8 commit 9208832
Show file tree
Hide file tree
Showing 31 changed files with 615 additions and 458 deletions.
14 changes: 8 additions & 6 deletions test/_lib/base-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const PORT_CONSTANTS = require('./helpers/port-constants');
module.exports = function(
seq,
extendedSeq,
minPeers,
secure,
requestTimeout,
Expand All @@ -8,16 +9,17 @@ module.exports = function(
joinTimeout,
replicate
) {
let [first, seq] = extendedSeq;
var clusterRequestTimeout = requestTimeout ? requestTimeout : 10 * 1000;
var clusterResponseTimeout = responseTimeout ? responseTimeout : 20 * 1000;

hosts = hosts ? hosts.split(',') : ['127.0.0.1:56001'];
hosts = hosts ? hosts.split(',') : ['127.0.0.1:' + (PORT_CONSTANTS.SWIM_BASE + first).toString()];
joinTimeout = joinTimeout || 300;

return {
name: 'MESH_' + seq,
domain: 'DOMAIN_NAME',
port: 57000 + seq,
port: PORT_CONSTANTS.HAPPN_BASE + seq,
ignoreDependenciesOnStartup: true,
cluster: {
requestTimeout: clusterRequestTimeout,
Expand All @@ -39,16 +41,16 @@ module.exports = function(
membership: {
config: {
host: '127.0.0.1',
port: 56000 + seq,
seed: seq === 1,
port: PORT_CONSTANTS.SWIM_BASE + seq,
seed: seq === first,
seedWait: 1000,
hosts,
joinTimeout
}
},
proxy: {
config: {
port: 55000 + seq
port: PORT_CONSTANTS.PROXY_BASE + seq
}
},
orchestrator: {
Expand Down
23 changes: 15 additions & 8 deletions test/_lib/helpers/configuration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const PORT_CONSTANTS = require('./port-constants');
const _ = require('lodash');
const getSeq = require('./getSeq');
module.exports = class Configuration extends require('./helper') {
constructor() {
super();
Expand Down Expand Up @@ -26,20 +28,25 @@ module.exports = class Configuration extends require('./helper') {
return require(`../configurations/${test}/${index}`);
}

construct(test, index, secure = true, minPeers, hosts, joinTimeout, replicate) {
const base = this.base(index, secure, minPeers, hosts, joinTimeout, replicate);
construct(test, extendedIndex, secure = true, minPeers, hosts, joinTimeout, replicate) {
let [seqIndex, index] = extendedIndex;
const base = this.base(index, seqIndex, secure, minPeers, hosts, joinTimeout, replicate);
return _.defaultsDeep(base, this.get(test, index));
}

base(index, secure = true, minPeers, hosts, joinTimeout, replicate) {
hosts = hosts || [`${this.address.self()}:9600`, `${this.address.self()}:9601`];
base(index, seqIndex, secure = true, minPeers, hosts, joinTimeout, replicate) {
let [first, portIndex] = seqIndex;
hosts = hosts || [
`${this.address.self()}:` + getSeq.getSwimPort(1).toString(),
`${this.address.self()}:` + getSeq.getSwimPort(2).toString()
];
joinTimeout = joinTimeout || 1000;
replicate = replicate || ['*'];

return {
name: 'MESH_' + index,
domain: 'DOMAIN_NAME',
port: 9700 + index,
port: PORT_CONSTANTS.HAPPN_BASE + portIndex,
cluster: {
requestTimeout: 10000,
responseTimeout: 20000
Expand All @@ -60,16 +67,16 @@ module.exports = class Configuration extends require('./helper') {
membership: {
config: {
host: `${this.address.self()}`,
port: 9600 + index,
seed: index === 0,
port: PORT_CONSTANTS.SWIM_BASE + portIndex,
seed: portIndex === first,
seedWait: 1000,
hosts,
joinTimeout
}
},
proxy: {
config: {
port: 9500 + index
port: PORT_CONSTANTS.PROXY_BASE + portIndex
}
},
orchestrator: {
Expand Down
2 changes: 2 additions & 0 deletions test/_lib/helpers/getSeq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const GetSeq = require('./getSeqClass');
module.exports = new GetSeq(0);
48 changes: 48 additions & 0 deletions test/_lib/helpers/getSeqClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const PORT_CONSTANTS = require('./port-constants');
module.exports = class GetSeq {
constructor(num, first = null, constants = null) {
if (first) this.first = first;
this.num = num || 1;
this.constants = constants || PORT_CONSTANTS;
}
getNext() {
return [this.first, this.num++];
}

getFirst() {
this.first = this.num;
return [this.first, this.num++];
}
getLast() {
this.last = this.num;
return [this.first, this.num++];
}

getCurrent() {
return [this.first, this.num - 1];
}

getPort(num) {
return this.constants.PROXY_BASE + this.first + num - 1;
}
getHappnPort(num) {
return this.constants.HAPPN_BASE + this.first + num - 1;
}
getSwimPort(num) {
return this.constants.SWIM_BASE + this.first + num - 1;
}
getProxyPort(num) {
return this.constants.PROXY_BASE + this.first + num - 1;
}

getMeshName(num) {
let meshNum = this.first + num - 1;
return 'MESH_' + meshNum.toString();
}
lookupFirst() {
return this.first;
}
lookupLast() {
return this.last;
}
};
5 changes: 5 additions & 0 deletions test/_lib/helpers/port-constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
PROXY_BASE: 6000,
HAPPN_BASE: 7000,
SWIM_BASE: 9000
};
15 changes: 12 additions & 3 deletions test/_lib/test-25-sub-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ const libDir = require('./lib-dir');
const HappnerCluster = require('../..');
const users = require('./users');
let localInstance;
const GetSeq = require('./helpers/getSeqClass');
let getSeq;

let inputArgs = process.argv.slice(2).map(num => parseInt(num));

(async () => {
if (process.argv[2] === '2') {
await startInternal(2, 2);
if (inputArgs[0] === 2) {
getSeq = new GetSeq(inputArgs[1] + 1, inputArgs[1]);
let next = getSeq.getNext();
await startInternal(next, 2);
await users.add(localInstance, 'username', 'password');
await users.allowMethod(localInstance, 'username', 'breakingComponent', 'happyMethod');
await users.allowMethod(localInstance, 'username', 'breakingComponent', 'breakingMethod');
} else {
await startInternal(3, 2);
getSeq = new GetSeq(inputArgs[1] + inputArgs[0] - 1, inputArgs[1]);
let next = getSeq.getNext();
await startInternal(next, 2);
}
})();
async function startInternal(id, clusterMin) {
Expand Down

0 comments on commit 9208832

Please sign in to comment.