Skip to content

Commit

Permalink
♻️ Fix stub issue
Browse files Browse the repository at this point in the history
sign: Diego Garcia <diego.gm@protonmail.com>
  • Loading branch information
Manu Nelamane Siddalingegowda committed Dec 10, 2019
1 parent 3006793 commit dc50f15
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions elements/lisk-p2p/test/unit/utils/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,17 @@ describe('peer selector', () => {
});

describe('when there are less than 100 peers', () => {
beforeEach(function() {
sinon.stub(Math, 'random').returns(0.499);
let mathRandom: sinon.SinonStub;
before(function() {
mathRandom = sinon.stub(Math, 'random');
});

afterEach(function() {
after(function() {
sandbox.restore();
});

it('should return peers uniformly from both lists', () => {
mathRandom.returns(0.499);
const triedPeers = initPeerInfoListWithSuffix('111.112.113', 25);
const newPeers = initPeerInfoListWithSuffix('111.112.114', 75);

Expand Down Expand Up @@ -390,18 +392,9 @@ describe('peer selector', () => {
expect(triedCount).to.eql(25);
expect(newCount).to.eql(25);
});
});

describe('when math random returns above 50', () => {
beforeEach(function() {
sinon.stub(Math, 'random').returns(0.5);
});

afterEach(function() {
sandbox.restore();
});

it('should return only new peer list', () => {
mathRandom.returns(0.5);
const triedPeers = initPeerInfoListWithSuffix('111.112.113', 25);
const newPeers = initPeerInfoListWithSuffix('111.112.114', 75);

Expand Down

0 comments on commit dc50f15

Please sign in to comment.