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 Apr 16, 2019
1 parent c59ce77 commit 7fef266
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions test/ipns-pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const spawnGoDaemon = (callback) => {

const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU'

describe('ipns-pubsub', () => {
describe.only('ipns-pubsub', () => {
let nodeAId
let nodeBId
let nodes = []
Expand Down Expand Up @@ -87,7 +87,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 +133,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 7fef266

Please sign in to comment.