Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Shorten the code related to the done callback in network tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jondubois committed Sep 10, 2018
1 parent 8e82426 commit 55fc17d
Showing 1 changed file with 8 additions and 28 deletions.
36 changes: 8 additions & 28 deletions test/network/scenarios/p2p/peer_disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ module.exports = function(
before(done => {
common
.stopNode('node_1')
.then(() => {
done();
})
.catch(err => {
done(err.message);
});
.then(done)
.catch(done);
});

it(`peer manager should remove peer from the list and there should be ${EXPECTED_TOTAL_CONNECTIONS_AFTER_REMOVING_PEER} established connections from 500[0-9] ports`, done => {
Expand Down Expand Up @@ -91,12 +87,8 @@ module.exports = function(
before(done => {
common
.startNode('node_1')
.then(() => {
done();
})
.catch(err => {
done(err.message);
});
.then(done)
.catch(done);
});

it(`there should be ${EXPECTED_TOTAL_CONNECTIONS} established connections from 500[0-9] ports`, done => {
Expand All @@ -123,34 +115,22 @@ module.exports = function(
// To validate peers holding socket connection
// Need to keep one peer so that we can validate
// Duplicate socket connection exists or not
it('stop all the nodes in the network except node_0', done => {
it('stop all the nodes in the network except node_0', () => {
const peersPromises = [];
for (let i = 1; i < TOTAL_PEERS; i++) {
peersPromises.push(common.stopNode(`node_${i}`));
}
console.info('Wait for nodes to be stopped');
Promise.all(peersPromises)
.then(() => {
done();
})
.catch(err => {
done(err.message);
});
return Promise.all(peersPromises);
});

it('start all nodes that were stopped', done => {
it('start all nodes that were stopped', () => {
const peersPromises = [];
for (let i = 1; i < TOTAL_PEERS; i++) {
peersPromises.push(common.startNode(`node_${i}`));
}
console.info('Wait for nodes to be started');
Promise.all(peersPromises)
.then(() => {
done();
})
.catch(err => {
done(err.message);
});
return Promise.all(peersPromises);
});

describe('after all the node restarts', () => {
Expand Down

0 comments on commit 55fc17d

Please sign in to comment.