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 May 13, 2019
1 parent 3f43521 commit d63ee61
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"lodash": "^4.17.11",
"merge-options": "^1.0.1",
"mocha": "^5.2.0",
"multihashes": "~0.4.14",
"ncp": "^2.0.0",
"pretty-bytes": "^5.1.0",
"random-fs": "^1.0.3",
Expand Down
16 changes: 9 additions & 7 deletions test/ipns-pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const spawnJsDaemon = (callback) => {
DaemonFactory.create({ type: 'js' })
.spawn({
disposable: true,
initOptions: { bits: 512 },
args: ['--enable-namesys-pubsub'], // enable ipns over pubsub
config
}, callback)
Expand All @@ -42,7 +41,6 @@ const spawnGoDaemon = (callback) => {
DaemonFactory.create()
.spawn({
disposable: true,
initOptions: { bits: 1024 },
args: ['--enable-namesys-pubsub'], // enable ipns over pubsub
config
}, callback)
Expand Down Expand Up @@ -87,7 +85,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 +131,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 d63ee61

Please sign in to comment.