diff --git a/js/src/ping/ping-pull-stream.js b/js/src/ping/ping-pull-stream.js index 7ae8e3e9..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,37 +61,23 @@ 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) => { + pull.collect((err, results) => { expect(err).to.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') done() diff --git a/js/src/ping/ping-readable-stream.js b/js/src/ping/ping-readable-stream.js index d6b8baa7..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 @@ -68,31 +68,14 @@ module.exports = (createCommon, options) => { ) }) - it('should fail when pinging an unknown peer over readable stream', (done) => { - let messageNum = 0 + it('should fail when pinging peer that is not available over readable stream', (done) => { 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.exist() @@ -101,12 +84,11 @@ module.exports = (createCommon, options) => { ) }) - 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 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 cf63b65b..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 @@ -51,24 +51,23 @@ 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) => { + ipfsA.ping(notAvailablePeerId, { count }, (err, responses) => { expect(err).to.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() }) })