Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
fix: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Jan 3, 2019
1 parent 3c0f3e1 commit 48c5089
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"form-data": "^2.3.3",
"go-ipfs-dep": "~0.4.18",
"hat": "0.0.3",
"ipfs": "ipfs/js-ipfs#feat/ipns-over-pubsub",
"ipfs": "0.34.0-rc.0",
"ipfs-api": "^26.1.2",
"ipfs-unixfs": "~0.1.16",
"ipfsd-ctl": "~0.40.0",
Expand Down
15 changes: 10 additions & 5 deletions test/ipns-pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { fromB58String } = require('multihashes')
const base64url = require('base64url')
const ipns = require('ipns')

const each = require('async/each')
const parallel = require('async/parallel')
const retry = require('async/retry')
const series = require('async/series')
Expand Down Expand Up @@ -87,7 +88,10 @@ describe('ipns-pubsub', () => {
nodeAId = ids[0]
nodeBId = ids[1]

nodes[0].api.swarm.connect(ids[1].addresses[0], () => {
nodes[0].api.swarm.connect(ids[1].addresses[0], (err) => {
expect(err).to.not.exist()

console.log('wait for republish as we can receive the republish message first')
setTimeout(done, 60000) // wait for republish as we can receive the republish message first
})
})
Expand Down Expand Up @@ -130,21 +134,22 @@ const subscribeToReceiveByPubsub = (nodeA, nodeB, id, callback) => {
const keys = ipns.getIdKeys(fromB58String(id))
const topic = `${namespace}${base64url.encode(keys.routingKey.toBuffer())}`

nodeB.api.name.resolve(id, () => {
// try to resolve a unpublished record (will subscribe it)
nodeB.api.name.resolve(id, (err) => {
expect(err).to.exist() // not found

series([
(cb) => waitForPeerToSubscribe(nodeB.api, topic, cb),
(cb) => nodeB.api.pubsub.subscribe(topic, checkMessage, cb),
(cb) => nodeA.api.name.publish(ipfsRef, { resolve: false }, cb),
(cb) => nodeA.api.name.resolve(id, cb),
(cb) => waitFor(() => subscribed === true, (50 * 1000), cb),
(cb) => nodeB.api.name.resolve(id, cb)
], (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()

expect(res[2].name).to.equal(id) // Published to Node A ID
expect(res[3]).to.equal(ipfsRef) // TODO: remove path once not using proc daemon
expect(res[5]).to.equal(ipfsRef)
expect(res[4]).to.equal(ipfsRef)

callback()
})
Expand Down
2 changes: 1 addition & 1 deletion test/utils/wait-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ module.exports = (predicate, ttl, callback) => {
clearInterval(self)
return callback(new Error('waitFor time expired'))
}
}, 500)
}, 50)
}

0 comments on commit 48c5089

Please sign in to comment.