diff --git a/package.json b/package.json index aa153d4e..e04bdac4 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "libp2p-websocket-star-rendezvous": "~0.3.0", "lodash": "^4.17.11", "mocha": "^5.2.0", + "multihashes": "~0.4.14", "ncp": "^2.0.0", "pretty-bytes": "^5.1.0", "random-fs": "^1.0.3", diff --git a/test/ipns-pubsub.js b/test/ipns-pubsub.js index 5eeeb57f..d71ae572 100644 --- a/test/ipns-pubsub.js +++ b/test/ipns-pubsub.js @@ -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 }) }) @@ -130,12 +133,14 @@ 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) => { @@ -143,8 +148,7 @@ const subscribeToReceiveByPubsub = (nodeA, nodeB, id, callback) => { 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() }) diff --git a/test/utils/wait-for.js b/test/utils/wait-for.js index 2b4a10d7..60fd9efd 100644 --- a/test/utils/wait-for.js +++ b/test/utils/wait-for.js @@ -20,5 +20,5 @@ module.exports = (predicate, ttl, callback) => { clearInterval(self) return callback(new Error('waitFor time expired')) } - }, 500) + }, 50) }