Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: speedup core smoke test #303

Merged
merged 8 commits into from
Jul 1, 2022
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
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@dashevo/dapi-client": "^0.22.0",
"@dashevo/dashcore-lib": "~0.19.30",
"@dashevo/dashd-rpc": "^2.3.1",
"@dashevo/dashd-rpc": "^2.4.0",
"@dashevo/wallet-lib": "~7.22.0",
"@grpc/grpc-js": "^1.3.7",
"bls-signatures": "^0.2.5",
Expand Down
101 changes: 62 additions & 39 deletions test/smoke/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,50 @@ const allHosts = inventory.masternodes.hosts.concat(

describe.only('Core', () => {
describe('All nodes', () => {
// Set up vars and functions to hold max height and mn responses
const blockchainInfo = {};
let maxBlockHeight = 0;

before(async function before() {
this.slow(allHosts * 2000);
this.timeout(allHosts * 3000);
const networkInfo = {};

before('Collect blockchain and network info', function func() {
this.timeout(60000); // set mocha timeout

const promises = [];
for (const hostName of allHosts) {
const timeout = 15000; // set individual rpc client timeout

const client = createRpcClientFromConfig(hostName);

let result;
client.setTimeout(timeout);

try {
({ result } = await client.getBlockchainInfo());
} catch (e) {
// eslint-disable-next-line no-continue
continue;
}
const requestBlockchainInfoPromise = client.getBlockchainInfo()
// eslint-disable-next-line no-loop-func
.then(({ result }) => {
if (maxBlockHeight < result.blocks) {
maxBlockHeight = result.blocks;
}
blockchainInfo[hostName] = result;
});

if (maxBlockHeight < result.blocks) {
maxBlockHeight = result.blocks;
}
const requestNetworkInfoPromise = client.getNetworkInfo()
.then(({ result }) => {
networkInfo[hostName] = result;
});

blockchainInfo[hostName] = result;
promises.push(requestBlockchainInfoPromise, requestNetworkInfoPromise);
}

return Promise.all(promises).catch(() => Promise.resolve());
});

for (const hostName of allHosts) {
// eslint-disable-next-line no-loop-func
describe(hostName, () => {
let dashdClient;

beforeEach(() => {
dashdClient = createRpcClientFromConfig(hostName);
});

it('should have correct network type', async function it() {
this.slow(2000);

const { result: { networkactive, subversion } } = await dashdClient.getNetworkInfo();
it('should have correct network type', async () => {
if (!blockchainInfo[hostName]) {
expect.fail(null, null, 'no blockchain info');
}

const chainNames = {
testnet: 'test',
Expand All @@ -61,16 +65,16 @@ describe.only('Core', () => {

expect(blockchainInfo[hostName]).to.be.not.empty();
expect(blockchainInfo[hostName].chain).to.equal(chainNames[network.type]);
expect(networkactive).to.be.equal(true);
expect(networkInfo[hostName].networkactive).to.be.equal(true);

if (network.type === 'devnet') {
expect(subversion).to.have.string(`(${network.type}.${network.name})/`);
expect(networkInfo[hostName].subversion).to.have.string(`(${network.type}.${network.name})/`);
}
});

it('should sync blocks', async () => {
if (!blockchainInfo[hostName]) {
expect.fail('Can\'t connect to Core');
expect.fail(null, null, 'no blockchain info');
}

expect(maxBlockHeight - blockchainInfo[hostName].blocks).to.be.below(3);
Expand All @@ -80,23 +84,42 @@ describe.only('Core', () => {
});

describe('Masternodes', () => {
for (const hostName of inventory.masternodes.hosts) {
describe(hostName, () => {
let coreClient;
const masternodeListInfo = {};

beforeEach(() => {
coreClient = createRpcClientFromConfig(hostName);
});
before('Collect masternode list info', function func() {
this.timeout(30000); // set mocha timeout

it('should be in masternodes list', async function it() {
this.slow(2000);
const promises = [];
for (const hostName of inventory.masternodes.hosts) {
const timeout = 15000; // set individual rpc client timeout

const { result: masternodes } = await coreClient.masternodelist();
const client = createRpcClientFromConfig(hostName);

client.setTimeout(timeout);

const requestMasternodeListInfoPromise = client.masternodelist()
.then(({ result }) => {
masternodeListInfo[hostName] = result;
});

promises.push(requestMasternodeListInfoPromise);
}

return Promise.all(promises).catch(() => Promise.resolve());
});

for (const hostName of inventory.masternodes.hosts) {
describe(hostName, () => {
it('should be in masternodes list', async () => {
if (!masternodeListInfo[hostName]) {
expect.fail(null, null, 'no masternode list info');
}

const nodeFromList = Object.values(masternodes).find((node) => (
const nodeFromList = Object.values(masternodeListInfo[hostName])
.find((node) => (
// eslint-disable-next-line no-underscore-dangle
inventory._meta.hostvars[hostName].public_ip === node.address.split(':')[0]
));
inventory._meta.hostvars[hostName].public_ip === node.address.split(':')[0]
));

expect(nodeFromList, `${hostName} is not present in masternode list`).to.exist();

Expand Down