From 3e619e1fa94e2f317cd5521252f94b452ee94b94 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 20 Nov 2018 16:20:53 +0000 Subject: [PATCH 1/3] fix: ipns over pubsub tests --- js/src/name-pubsub/cancel.js | 51 ++++++++++++++++-------------------- js/src/name-pubsub/subs.js | 41 ++++++++++------------------- 2 files changed, 37 insertions(+), 55 deletions(-) diff --git a/js/src/name-pubsub/cancel.js b/js/src/name-pubsub/cancel.js index ba7fd2cc..cd18a083 100644 --- a/js/src/name-pubsub/cancel.js +++ b/js/src/name-pubsub/cancel.js @@ -3,15 +3,10 @@ 'use strict' const series = require('async/series') -const loadFixture = require('aegir/fixtures') const { spawnNodeWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') -const fixture = Object.freeze({ - data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core') -}) - module.exports = (createCommon, options) => { const describe = getDescribe(options) const it = getIt(options) @@ -20,7 +15,6 @@ module.exports = (createCommon, options) => { describe('.name.pubsub.cancel', function () { let ipfs let nodeId - let value before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the @@ -36,12 +30,7 @@ module.exports = (createCommon, options) => { ipfs = node nodeId = node.peerId.id - ipfs.add(fixture.data, { pin: false }, (err, res) => { - expect(err).to.not.exist() - - value = res[0].path - done() - }) + done() }) }) }) @@ -63,24 +52,30 @@ module.exports = (createCommon, options) => { it('should cancel a subscription correctly returning true', function (done) { this.timeout(300 * 1000) - const ipnsPath = `/ipns/${nodeId}` - - series([ - (cb) => ipfs.name.pubsub.subs(cb), - (cb) => ipfs.name.publish(value, { resolve: false }, cb), - (cb) => ipfs.name.resolve(nodeId, cb), - (cb) => ipfs.name.pubsub.subs(cb), - (cb) => ipfs.name.pubsub.cancel(ipnsPath, cb), - (cb) => ipfs.name.pubsub.subs(cb) - ], (err, res) => { + const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA' + const ipnsPath = `/ipns/${id}` + + ipfs.name.pubsub.subs((err, res) => { expect(err).to.not.exist() - expect(res).to.exist() - expect(res[0]).to.eql([]) // initally empty - expect(res[4]).to.have.property('canceled') - expect(res[4].canceled).to.eql(true) - expect(res[5]).to.be.an('array').that.does.not.include(ipnsPath) + expect(res).to.eql([]) // initally empty + + ipfs.name.resolve(id, (err) => { + expect(err).to.exist() + series([ + (cb) => ipfs.name.pubsub.subs(cb), + (cb) => ipfs.name.pubsub.cancel(ipnsPath, cb), + (cb) => ipfs.name.pubsub.subs(cb) + ], (err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + expect(res[0]).to.be.an('array').that.does.include(ipnsPath) + expect(res[1]).to.have.property('canceled') + expect(res[1].canceled).to.eql(true) + expect(res[2]).to.be.an('array').that.does.not.include(ipnsPath) - done() + done() + }) + }) }) }) }) diff --git a/js/src/name-pubsub/subs.js b/js/src/name-pubsub/subs.js index 44db46ea..d7a52937 100644 --- a/js/src/name-pubsub/subs.js +++ b/js/src/name-pubsub/subs.js @@ -2,16 +2,9 @@ /* eslint-env mocha */ 'use strict' -const series = require('async/series') -const loadFixture = require('aegir/fixtures') - const { spawnNodeWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') -const fixture = Object.freeze({ - data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core') -}) - module.exports = (createCommon, options) => { const describe = getDescribe(options) const it = getIt(options) @@ -19,8 +12,6 @@ module.exports = (createCommon, options) => { describe('.name.pubsub.subs', function () { let ipfs - let nodeId - let value before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the @@ -34,14 +25,7 @@ module.exports = (createCommon, options) => { expect(err).to.not.exist() ipfs = node - nodeId = node.peerId.id - - ipfs.add(fixture.data, { pin: false }, (err, res) => { - expect(err).to.not.exist() - - value = res[0].path - done() - }) + done() }) }) }) @@ -62,19 +46,22 @@ module.exports = (createCommon, options) => { it('should get the list of subscriptions updated after a resolve', function (done) { this.timeout(300 * 1000) + const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA' - series([ - (cb) => ipfs.name.pubsub.subs(cb), - (cb) => ipfs.name.publish(value, { resolve: false }, cb), - (cb) => ipfs.name.resolve(nodeId, cb), - (cb) => ipfs.name.pubsub.subs(cb) - ], (err, res) => { + ipfs.name.pubsub.subs((err, res) => { expect(err).to.not.exist() - expect(res).to.exist() - expect(res[0]).to.eql([]) // initally empty - expect(res[3]).to.be.an('array').that.does.include(`/ipns/${nodeId}`) + expect(res).to.eql([]) // initally empty - done() + ipfs.name.resolve(id, (err) => { + expect(err).to.exist() + + ipfs.name.pubsub.subs((err, res) => { + expect(err).to.not.exist() + expect(res).to.be.an('array').that.does.include(`/ipns/${id}`) + + done() + }) + }) }) }) }) From d268addc9825fe36034ed6cee9b8785d1fa6d640 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Fri, 30 Nov 2018 18:33:10 +0000 Subject: [PATCH 2/3] fix: code review --- js/src/name-pubsub/cancel.js | 48 ++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/js/src/name-pubsub/cancel.js b/js/src/name-pubsub/cancel.js index cd18a083..9f739794 100644 --- a/js/src/name-pubsub/cancel.js +++ b/js/src/name-pubsub/cancel.js @@ -2,7 +2,8 @@ /* eslint-env mocha */ 'use strict' -const series = require('async/series') +const auto = require('async/auto') +const PeerId = require('peer-id') const { spawnNodeWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') @@ -52,28 +53,33 @@ module.exports = (createCommon, options) => { it('should cancel a subscription correctly returning true', function (done) { this.timeout(300 * 1000) - const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA' - const ipnsPath = `/ipns/${id}` - ipfs.name.pubsub.subs((err, res) => { + PeerId.create({ bits: 512 }, (err, peerId) => { expect(err).to.not.exist() - expect(res).to.eql([]) // initally empty - - ipfs.name.resolve(id, (err) => { - expect(err).to.exist() - series([ - (cb) => ipfs.name.pubsub.subs(cb), - (cb) => ipfs.name.pubsub.cancel(ipnsPath, cb), - (cb) => ipfs.name.pubsub.subs(cb) - ], (err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res[0]).to.be.an('array').that.does.include(ipnsPath) - expect(res[1]).to.have.property('canceled') - expect(res[1].canceled).to.eql(true) - expect(res[2]).to.be.an('array').that.does.not.include(ipnsPath) - - done() + + const id = peerId.toB58String() + const ipnsPath = `/ipns/${id}` + + ipfs.name.pubsub.subs((err, res) => { + expect(err).to.not.exist() + expect(res).to.be.an('array').that.does.not.include(ipnsPath) + + ipfs.name.resolve(id, (err) => { + expect(err).to.exist() + auto({ + subs1: (cb) => ipfs.name.pubsub.subs(cb), + cancel: (cb) => ipfs.name.pubsub.cancel(ipnsPath, cb), + subs2: (cb) => ipfs.name.pubsub.subs(cb) + }, 1, (err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + expect(res.subs1).to.be.an('array').that.does.include(ipnsPath) + expect(res.cancel).to.have.property('canceled') + expect(res.cancel.canceled).to.eql(true) + expect(res.subs2).to.be.an('array').that.does.not.include(ipnsPath) + + done() + }) }) }) }) From c6995d6f671990ad9b7253a5470d81e2b67176e5 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 3 Dec 2018 13:02:05 +0000 Subject: [PATCH 3/3] fix: async auto --- js/src/name-pubsub/cancel.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/src/name-pubsub/cancel.js b/js/src/name-pubsub/cancel.js index 9f739794..b46dcb82 100644 --- a/js/src/name-pubsub/cancel.js +++ b/js/src/name-pubsub/cancel.js @@ -68,9 +68,9 @@ module.exports = (createCommon, options) => { expect(err).to.exist() auto({ subs1: (cb) => ipfs.name.pubsub.subs(cb), - cancel: (cb) => ipfs.name.pubsub.cancel(ipnsPath, cb), - subs2: (cb) => ipfs.name.pubsub.subs(cb) - }, 1, (err, res) => { + cancel: ['subs1', (_, cb) => ipfs.name.pubsub.cancel(ipnsPath, cb)], + subs2: ['cancel', (_, cb) => ipfs.name.pubsub.subs(cb)] + }, (err, res) => { expect(err).to.not.exist() expect(res).to.exist() expect(res.subs1).to.be.an('array').that.does.include(ipnsPath)