From e9e72763ca62a9333e724d93d2b370b8c4d8a6e1 Mon Sep 17 00:00:00 2001 From: victorbjelkholm Date: Fri, 16 Mar 2018 15:24:17 +0100 Subject: [PATCH 1/3] fix(bitswap): 0.4.14 returns empty array instead of null Since 0.4.14, go-ipfs now returns an empty array rather than null. This should be considered a breaking change for consumers of this library. --- test/bitswap.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bitswap.spec.js b/test/bitswap.spec.js index 2a69a1b06..b878cf67c 100644 --- a/test/bitswap.spec.js +++ b/test/bitswap.spec.js @@ -33,7 +33,7 @@ describe('.bitswap', function () { ipfs.bitswap.wantlist((err, res) => { expect(err).to.not.exist() expect(res).to.have.to.eql({ - Keys: null + Keys: [] }) done() }) From aac6f335318fd2976b9f90e5c579360c48427e14 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 27 Mar 2018 13:04:18 -0700 Subject: [PATCH 2/3] chore: update deps, including ipfsd-ctl --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 04a39b2ad..bdf3bebc5 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "is-ipfs": "^0.3.2", "is-stream": "^1.1.0", "lru-cache": "^4.1.2", - "multiaddr": "^3.0.2", + "multiaddr": "^3.1.0", "multihashes": "~0.4.13", "ndjson": "^1.5.0", "once": "^1.4.0", @@ -68,14 +68,15 @@ "aegir": "^13.0.6", "browser-process-platform": "^0.1.1", "chai": "^4.1.2", + "cross-env": "^5.1.4", "dirty-chai": "^2.0.1", "eslint-plugin-react": "^7.7.0", - "go-ipfs-dep": "^0.4.13", + "go-ipfs-dep": "^0.4.14", "gulp": "^3.9.1", "hapi": "^17.2.3", "interface-ipfs-core": "~0.58.0", "ipfs": "~0.28.2", - "ipfsd-ctl": "~0.30.4", + "ipfsd-ctl": "~0.31.0", "pre-commit": "^1.2.2", "pull-stream": "^3.6.2", "socket.io": "^2.0.4", From 1d9c7b6223def57d6f01fe420c7a1ea5d48dfac7 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 27 Mar 2018 13:24:20 -0700 Subject: [PATCH 3/3] fix(ping): tests were failing and there it was missing to catch when count and n are used at the same time --- src/ping.js | 6 + test/ping.spec.js | 289 +++++++++++++--------------------------------- 2 files changed, 85 insertions(+), 210 deletions(-) diff --git a/src/ping.js b/src/ping.js index 8aca6c09d..2682e9752 100644 --- a/src/ping.js +++ b/src/ping.js @@ -12,10 +12,16 @@ module.exports = (arg) => { callback = opts opts = {} } + + if (opts.n && opts.count) { + return callback(new Error('Use either n or count, not both')) + } + // Default number of packtes to 1 if (!opts.n && !opts.count) { opts.n = 1 } + const request = { path: 'ping', args: id, diff --git a/test/ping.spec.js b/test/ping.spec.js index 09ab34402..2e7c1b820 100644 --- a/test/ping.spec.js +++ b/test/ping.spec.js @@ -34,7 +34,6 @@ describe('.ping', function () { }) }, (cb) => { - console.log('going to spawn second node') f.spawn({ initOptions: { bits: 1024 } }, (err, node) => { expect(err).to.not.exist() other = node.api @@ -66,236 +65,106 @@ describe('.ping', function () { ], done) }) - describe('callback API', () => { - it('ping another peer with default packet count', (done) => { - ipfs.ping(otherId, (err, res) => { - expect(err).to.not.exist() - expect(res).to.be.an('array') - expect(res).to.have.lengthOf(3) - res.forEach(packet => { - expect(packet).to.have.keys('Success', 'Time', 'Text') - expect(packet.Time).to.be.a('number') - }) - const resultMsg = res.find(packet => packet.Text.includes('Average latency')) - expect(resultMsg).to.exist() - done() + it('.ping with default n', (done) => { + ipfs.ping(otherId, (err, res) => { + expect(err).to.not.exist() + expect(res).to.be.an('array') + expect(res).to.have.lengthOf(3) + res.forEach(packet => { + expect(packet).to.have.keys('Success', 'Time', 'Text') + expect(packet.Time).to.be.a('number') }) + const resultMsg = res.find(packet => packet.Text.includes('Average latency')) + expect(resultMsg).to.exist() + done() }) + }) - it('ping another peer with a specifc packet count through parameter count', (done) => { - ipfs.ping(otherId, {count: 3}, (err, res) => { - expect(err).to.not.exist() + it('.ping with count = 2', (done) => { + ipfs.ping(otherId, { count: 2 }, (err, res) => { + expect(err).to.not.exist() + expect(res).to.be.an('array') + expect(res).to.have.lengthOf(4) + res.forEach(packet => { + expect(packet).to.have.keys('Success', 'Time', 'Text') + expect(packet.Time).to.be.a('number') + }) + const resultMsg = res.find(packet => packet.Text.includes('Average latency')) + expect(resultMsg).to.exist() + done() + }) + }) + + it('.ping with n = 2', (done) => { + ipfs.ping(otherId, { n: 2 }, (err, res) => { + expect(err).to.not.exist() + expect(res).to.be.an('array') + expect(res).to.have.lengthOf(4) + res.forEach(packet => { + expect(packet).to.have.keys('Success', 'Time', 'Text') + expect(packet.Time).to.be.a('number') + }) + const resultMsg = res.find(packet => packet.Text.includes('Average latency')) + expect(resultMsg).to.exist() + done() + }) + }) + + it('.ping fails with count & n', function (done) { + this.timeout(20 * 1000) + + ipfs.ping(otherId, {count: 2, n: 2}, (err, res) => { + expect(err).to.exist() + done() + }) + }) + + it('.ping with Promises', () => { + return ipfs.ping(otherId) + .then((res) => { expect(res).to.be.an('array') - expect(res).to.have.lengthOf(5) + expect(res).to.have.lengthOf(3) res.forEach(packet => { expect(packet).to.have.keys('Success', 'Time', 'Text') expect(packet.Time).to.be.a('number') }) const resultMsg = res.find(packet => packet.Text.includes('Average latency')) expect(resultMsg).to.exist() - done() }) - }) + }) - it('ping another peer with a specifc packet count through parameter n', (done) => { - ipfs.ping(otherId, {n: 3}, (err, res) => { + it('.pingPullStream', (done) => { + pull( + ipfs.pingPullStream(otherId), + collect((err, data) => { expect(err).to.not.exist() - expect(res).to.be.an('array') - expect(res).to.have.lengthOf(5) - res.forEach(packet => { + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(3) + data.forEach(packet => { expect(packet).to.have.keys('Success', 'Time', 'Text') expect(packet.Time).to.be.a('number') }) - const resultMsg = res.find(packet => packet.Text.includes('Average latency')) + const resultMsg = data.find(packet => packet.Text.includes('Average latency')) expect(resultMsg).to.exist() done() }) - }) + ) + }) - it('sending both n and count should fail', (done) => { - ipfs.ping(otherId, {count: 10, n: 10}, (err, res) => { - expect(err).to.exist() + it('.pingReadableStream', (done) => { + let packetNum = 0 + ipfs.pingReadableStream(otherId) + .on('data', data => { + packetNum++ + expect(data).to.be.an('object') + expect(data).to.have.keys('Success', 'Time', 'Text') + }) + .on('error', err => { + expect(err).not.to.exist() + }) + .on('end', () => { + expect(packetNum).to.equal(3) done() }) - }) - }) - - describe('promise API', () => { - it('ping another peer with default packet count', () => { - return ipfs.ping(otherId) - .then((res) => { - expect(res).to.be.an('array') - expect(res).to.have.lengthOf(3) - res.forEach(packet => { - expect(packet).to.have.keys('Success', 'Time', 'Text') - expect(packet.Time).to.be.a('number') - }) - const resultMsg = res.find(packet => packet.Text.includes('Average latency')) - expect(resultMsg).to.exist() - }) - }) - - it('ping another peer with a specifc packet count through parameter count', () => { - return ipfs.ping(otherId, {count: 3}) - .then((res) => { - expect(res).to.be.an('array') - expect(res).to.have.lengthOf(5) - res.forEach(packet => { - expect(packet).to.have.keys('Success', 'Time', 'Text') - expect(packet.Time).to.be.a('number') - }) - const resultMsg = res.find(packet => packet.Text.includes('Average latency')) - expect(resultMsg).to.exist() - }) - }) - - it('ping another peer with a specifc packet count through parameter n', () => { - return ipfs.ping(otherId, {n: 3}) - .then((res) => { - expect(res).to.be.an('array') - expect(res).to.have.lengthOf(5) - res.forEach(packet => { - expect(packet).to.have.keys('Success', 'Time', 'Text') - expect(packet.Time).to.be.a('number') - }) - const resultMsg = res.find(packet => packet.Text.includes('Average latency')) - expect(resultMsg).to.exist() - }) - }) - - it('sending both n and count should fail', (done) => { - ipfs.ping(otherId, {n: 3, count: 3}) - .catch(err => { - expect(err).to.exist() - done() - }) - }) - }) - - describe('pull stream API', () => { - it('ping another peer with the default packet count', (done) => { - pull( - ipfs.pingPullStream(otherId), - collect((err, data) => { - expect(err).to.not.exist() - expect(data).to.be.an('array') - expect(data).to.have.lengthOf(3) - data.forEach(packet => { - expect(packet).to.have.keys('Success', 'Time', 'Text') - expect(packet.Time).to.be.a('number') - }) - const resultMsg = data.find(packet => packet.Text.includes('Average latency')) - expect(resultMsg).to.exist() - done() - }) - ) - }) - - it('ping another peer with a specifc packet count through parameter count', (done) => { - pull( - ipfs.pingPullStream(otherId, {count: 3}), - collect((err, data) => { - expect(err).to.not.exist() - expect(data).to.be.an('array') - expect(data).to.have.lengthOf(5) - data.forEach(packet => { - expect(packet).to.have.keys('Success', 'Time', 'Text') - expect(packet.Time).to.be.a('number') - }) - const resultMsg = data.find(packet => packet.Text.includes('Average latency')) - expect(resultMsg).to.exist() - done() - }) - ) - }) - - it('ping another peer with a specifc packet count through parameter n', (done) => { - pull( - ipfs.pingPullStream(otherId, {n: 3}), - collect((err, data) => { - expect(err).to.not.exist() - expect(data).to.be.an('array') - expect(data).to.have.lengthOf(5) - data.forEach(packet => { - expect(packet).to.have.keys('Success', 'Time', 'Text') - expect(packet.Time).to.be.a('number') - }) - const resultMsg = data.find(packet => packet.Text.includes('Average latency')) - expect(resultMsg).to.exist() - done() - }) - ) - }) - - it('sending both n and count should fail', (done) => { - pull( - ipfs.pingPullStream(otherId, {n: 3, count: 3}), - collect(err => { - expect(err).to.exist() - done() - }) - ) - }) - }) - - describe('readable stream API', () => { - it('ping another peer with the default packet count', (done) => { - let packetNum = 0 - ipfs.pingReadableStream(otherId) - .on('data', data => { - packetNum++ - expect(data).to.be.an('object') - expect(data).to.have.keys('Success', 'Time', 'Text') - }) - .on('error', err => { - expect(err).not.to.exist() - }) - .on('end', () => { - expect(packetNum).to.equal(3) - done() - }) - }) - - it('ping another peer with a specifc packet count through parameter count', (done) => { - let packetNum = 0 - ipfs.pingReadableStream(otherId, {count: 3}) - .on('data', data => { - packetNum++ - expect(data).to.be.an('object') - expect(data).to.have.keys('Success', 'Time', 'Text') - }) - .on('error', err => { - expect(err).not.to.exist() - }) - .on('end', () => { - expect(packetNum).to.equal(5) - done() - }) - }) - - it('ping another peer with a specifc packet count through parameter n', (done) => { - let packetNum = 0 - ipfs.pingReadableStream(otherId, {n: 3}) - .on('data', data => { - packetNum++ - expect(data).to.be.an('object') - expect(data).to.have.keys('Success', 'Time', 'Text') - }) - .on('error', err => { - expect(err).not.to.exist() - }) - .on('end', () => { - expect(packetNum).to.equal(5) - done() - }) - }) - - it('sending both n and count should fail', (done) => { - ipfs.pingReadableStream(otherId, {n: 3, count: 3}) - .on('error', err => { - expect(err).to.exist() - done() - }) - }) }) })