From adc416ce09254c9a282e23ce494def7ef3952b14 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 31 Oct 2018 13:46:04 +0000 Subject: [PATCH 1/2] fix: remove antipattern from ping tests --- js/src/ping/ping-pull-stream.js | 7 ++++--- js/src/ping/ping-readable-stream.js | 6 +++--- js/src/ping/ping.js | 11 ++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/js/src/ping/ping-pull-stream.js b/js/src/ping/ping-pull-stream.js index 7ae8e3e9..167c95cb 100644 --- a/js/src/ping/ping-pull-stream.js +++ b/js/src/ping/ping-pull-stream.js @@ -80,20 +80,21 @@ module.exports = (createCommon, options) => { expect(res.success).to.be.false() } }, (err) => { - expect(err).to.exist() + expect(err).to.not.exist() done() }) ) }) - it('should fail when pinging an invalid peer over pull stream', (done) => { + it('should fail when pinging an invalid peer id over pull stream', (done) => { const invalidPeerId = 'not a peer ID' const count = 2 pull( ipfsA.pingPullStream(invalidPeerId, { count }), - pull.collect((err) => { + pull.collect((err, results) => { expect(err).to.exist() expect(err.message).to.include('failed to parse peer address') + expect(results).to.not.exist() done() }) ) diff --git a/js/src/ping/ping-readable-stream.js b/js/src/ping/ping-readable-stream.js index d6b8baa7..e3805729 100644 --- a/js/src/ping/ping-readable-stream.js +++ b/js/src/ping/ping-readable-stream.js @@ -68,7 +68,7 @@ module.exports = (createCommon, options) => { ) }) - it('should fail when pinging an unknown peer over readable stream', (done) => { + it('should fail when pinging peer that is not available over readable stream', (done) => { let messageNum = 0 const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn' const count = 2 @@ -95,13 +95,13 @@ module.exports = (createCommon, options) => { } }), (err) => { - expect(err).to.exist() + expect(err).to.not.exist() done() } ) }) - it('should fail when pinging an invalid peer over readable stream', (done) => { + it('should fail when pinging an invalid peer id over readable stream', (done) => { const invalidPeerId = 'not a peer ID' const count = 2 diff --git a/js/src/ping/ping.js b/js/src/ping/ping.js index cf63b65b..85445267 100644 --- a/js/src/ping/ping.js +++ b/js/src/ping/ping.js @@ -51,24 +51,25 @@ module.exports = (createCommon, options) => { }) }) - it('should fail when pinging an unknown peer', (done) => { - const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn' + it('should fail when pinging a peer that is not available', (done) => { + const notAvailablePeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn' const count = 2 - ipfsA.ping(unknownPeerId, { count }, (err, responses) => { - expect(err).to.exist() + ipfsA.ping(notAvailablePeerId, { count }, (err, responses) => { + expect(err).to.not.exist() expect(responses[0].text).to.include('Looking up') expect(responses[1].success).to.be.false() done() }) }) - it('should fail when pinging an invalid peer', (done) => { + it('should fail when pinging an invalid peer Id', (done) => { const invalidPeerId = 'not a peer ID' const count = 2 ipfsA.ping(invalidPeerId, { count }, (err, responses) => { expect(err).to.exist() expect(err.message).to.include('failed to parse peer address') + expect(responses).to.not.exist() done() }) }) From 579d073dcfb7972df58519a33a96a84e171eceb7 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 31 Oct 2018 14:03:57 +0000 Subject: [PATCH 2/2] fix: ping tests --- js/src/ping/ping-pull-stream.js | 21 +++------------------ js/src/ping/ping-readable-stream.js | 28 +++++----------------------- js/src/ping/ping.js | 6 ++---- 3 files changed, 10 insertions(+), 45 deletions(-) diff --git a/js/src/ping/ping-pull-stream.js b/js/src/ping/ping-pull-stream.js index 167c95cb..7a072124 100644 --- a/js/src/ping/ping-pull-stream.js +++ b/js/src/ping/ping-pull-stream.js @@ -14,7 +14,7 @@ module.exports = (createCommon, options) => { const common = createCommon() describe('.pingPullStream', function () { - this.timeout(60 * 1000) + this.timeout(30 * 1000) let ipfsA let ipfsB @@ -61,26 +61,12 @@ module.exports = (createCommon, options) => { }) it('should fail when pinging an unknown peer over pull stream', (done) => { - let messageNum = 0 const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn' const count = 2 pull( ipfsA.pingPullStream(unknownPeerId, { count }), - pull.drain((res) => { - expectIsPingResponse(res) - messageNum++ - - // First message should be "looking up" response - if (messageNum === 1) { - expect(res.text).to.include('Looking up') - } - - // Second message should be a failure response - if (messageNum === 2) { - expect(res.success).to.be.false() - } - }, (err) => { - expect(err).to.not.exist() + pull.collect((err, results) => { + expect(err).to.exist() done() }) ) @@ -94,7 +80,6 @@ module.exports = (createCommon, options) => { pull.collect((err, results) => { expect(err).to.exist() expect(err.message).to.include('failed to parse peer address') - expect(results).to.not.exist() done() }) ) diff --git a/js/src/ping/ping-readable-stream.js b/js/src/ping/ping-readable-stream.js index e3805729..a0cd462b 100644 --- a/js/src/ping/ping-readable-stream.js +++ b/js/src/ping/ping-readable-stream.js @@ -15,7 +15,7 @@ module.exports = (createCommon, options) => { const common = createCommon() describe('.pingReadableStream', function () { - this.timeout(60 * 1000) + this.timeout(30 * 1000) let ipfsA let ipfsB @@ -69,33 +69,16 @@ module.exports = (createCommon, options) => { }) it('should fail when pinging peer that is not available over readable stream', (done) => { - let messageNum = 0 const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn' - const count = 2 pump( - ipfsA.pingReadableStream(unknownPeerId, { count }), + ipfsA.pingReadableStream(unknownPeerId, {}), new Writable({ objectMode: true, - write (res, enc, cb) { - expectIsPingResponse(res) - messageNum++ - - // First message should be "looking up" response - if (messageNum === 1) { - expect(res.text).to.include('Looking up') - } - - // Second message should be a failure response - if (messageNum === 2) { - expect(res.success).to.be.false() - } - - cb() - } + write: (res, enc, cb) => cb() }), (err) => { - expect(err).to.not.exist() + expect(err).to.exist() done() } ) @@ -103,10 +86,9 @@ module.exports = (createCommon, options) => { it('should fail when pinging an invalid peer id over readable stream', (done) => { const invalidPeerId = 'not a peer ID' - const count = 2 pump( - ipfsA.pingReadableStream(invalidPeerId, { count }), + ipfsA.pingReadableStream(invalidPeerId, {}), new Writable({ objectMode: true, write: (chunk, enc, cb) => cb() diff --git a/js/src/ping/ping.js b/js/src/ping/ping.js index 85445267..e68c3976 100644 --- a/js/src/ping/ping.js +++ b/js/src/ping/ping.js @@ -13,7 +13,7 @@ module.exports = (createCommon, options) => { const common = createCommon() describe('.ping', function () { - this.timeout(60 * 1000) + this.timeout(30 * 1000) let ipfsA let ipfsB @@ -56,9 +56,7 @@ module.exports = (createCommon, options) => { const count = 2 ipfsA.ping(notAvailablePeerId, { count }, (err, responses) => { - expect(err).to.not.exist() - expect(responses[0].text).to.include('Looking up') - expect(responses[1].success).to.be.false() + expect(err).to.exist() done() }) })