From dc50f157538883eded7ec72ecb9a8b8ef47821c8 Mon Sep 17 00:00:00 2001 From: Manu Nelamane Siddalingegowda Date: Tue, 10 Dec 2019 12:04:35 +0100 Subject: [PATCH] :recycle: Fix stub issue sign: Diego Garcia --- elements/lisk-p2p/test/unit/utils/select.ts | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/elements/lisk-p2p/test/unit/utils/select.ts b/elements/lisk-p2p/test/unit/utils/select.ts index d84337b4873..27d82e7eccd 100644 --- a/elements/lisk-p2p/test/unit/utils/select.ts +++ b/elements/lisk-p2p/test/unit/utils/select.ts @@ -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); @@ -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);