From 7804a201ca5caf8218790609d2219a96b1beb213 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 6 Aug 2018 15:54:56 +0100 Subject: [PATCH] fix: ensure test for resolve recursive has another node The resolve IPNS link recursively test uses name.publish to publish an IPNS link as the value for the peer. It then uses resolve to resolve the peer ID and recursively then resolve the IPNS link. This fixes the test so that when name.publish is called there is another connected node to publish to so that we do not get the error "failed to find any peer in table", in the case that the node has not yet connected to any other peers. License: MIT Signed-off-by: Alan Shaw --- js/src/miscellaneous/resolve.js | 39 +++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/js/src/miscellaneous/resolve.js b/js/src/miscellaneous/resolve.js index 9ad2bcc13..be0516908 100644 --- a/js/src/miscellaneous/resolve.js +++ b/js/src/miscellaneous/resolve.js @@ -4,6 +4,9 @@ const isIpfs = require('is-ipfs') const loadFixture = require('aegir/fixtures') const hat = require('hat') +const waterfall = require('async/waterfall') +const { spawnNodeWithId } = require('../utils/spawn') +const { connect } = require('../utils/swarm') const { getDescribe, getIt, expect } = require('../utils/mocha') module.exports = (createCommon, options) => { @@ -12,15 +15,16 @@ module.exports = (createCommon, options) => { const common = createCommon() describe('.resolve', () => { - let ipfs + let factory, ipfs before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the // timeout for the before step this.timeout(60 * 1000) - common.setup((err, factory) => { + common.setup((err, f) => { expect(err).to.not.exist() + factory = f factory.spawnNode((err, node) => { expect(err).to.not.exist() ipfs = node @@ -97,18 +101,25 @@ module.exports = (createCommon, options) => { // Test resolve turns /ipns/QmPeerHash into /ipns/domain.com into /ipfs/QmHash it('should resolve IPNS link recursively', function (done) { - this.timeout(4 * 60 * 1000) - - ipfs.name.publish('/ipns/ipfs.io', { resolve: false }, (err, res) => { - expect(err).to.not.exist() - - ipfs.resolve(`/ipns/${res.name}`, { recursive: true }, (err, res) => { - expect(err).to.not.exist() - expect(res).to.not.equal('/ipns/ipfs.io') - expect(isIpfs.ipfsPath(res)).to.be.true() - done() - }) - }) + this.timeout(5 * 60 * 1000) + + waterfall([ + // Ensure node has another node to publish a name to + (cb) => spawnNodeWithId(factory, cb), + (ipfsB, cb) => { + const addr = ipfsB.peerId.addresses.find((a) => a.includes('127.0.0.1')) + connect(ipfs, addr, cb) + }, + (cb) => ipfs.name.publish('/ipns/ipfs.io', { resolve: false }, cb), + (res, cb) => { + ipfs.resolve(`/ipns/${res.name}`, { recursive: true }, (err, res) => { + expect(err).to.not.exist() + expect(res).to.not.equal('/ipns/ipfs.io') + expect(isIpfs.ipfsPath(res)).to.be.true() + cb() + }) + } + ], done) }) }) }