diff --git a/src/block.js b/src/block.js index d0cf8af6..54695a43 100644 --- a/src/block.js +++ b/src/block.js @@ -20,23 +20,25 @@ function expectKey (block, expected, callback) { module.exports = (common) => { describe('.block', () => { let ipfs + let ipfsd 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, df, type, exec) => { expect(err).to.not.exist() - factory.spawnNode((err, node) => { + df.spawn({ type, exec }, (err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) }) - after((done) => common.teardown(done)) + after((done) => ipfsd.stop(done)) describe('.put', () => { it('a buffer, using defaults', (done) => { diff --git a/src/config.js b/src/config.js index 1cff56c8..7fc852c6 100644 --- a/src/config.js +++ b/src/config.js @@ -12,23 +12,25 @@ module.exports = (common) => { describe('.config', function () { this.timeout(30 * 1000) let ipfs + let ipfsd 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, df, type, exec) => { expect(err).to.not.exist() - factory.spawnNode((err, node) => { + df.spawn({ type, exec }, (err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api done() }) }) }) - after((done) => common.teardown(done)) + after((done) => ipfsd.stop(done)) describe('.get', () => { it('retrieve the whole config', (done) => { diff --git a/src/dag.js b/src/dag.js index a8a70cac..1304a85e 100644 --- a/src/dag.js +++ b/src/dag.js @@ -17,23 +17,25 @@ const CID = require('cids') module.exports = (common) => { describe('.dag', () => { let ipfs + let ipfsd 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, df, type, exec) => { expect(err).to.not.exist() - factory.spawnNode((err, node) => { + df.spawn({ type, exec }, (err, node) => { expect(err).to.not.exist() - ipfs = node + ipfs = node.api + ipfsd = node done() }) }) }) - after((done) => common.teardown(done)) + after((done) => ipfsd.stop(done)) let pbNode let cborNode diff --git a/src/dht.js b/src/dht.js index 06af6e92..ad3047d3 100644 --- a/src/dht.js +++ b/src/dht.js @@ -10,14 +10,24 @@ const series = require('async/series') const parallel = require('async/parallel') const CID = require('cids') -function spawnWithId (factory, callback) { +function spawnWithId (df, type, exec, callback) { + if (typeof type === 'function') { + callback = type + type = undefined + } + + if (typeof exec === 'function') { + callback = exec + exec = undefined + } + waterfall([ - (cb) => factory.spawnNode(cb), - (node, cb) => node.id((err, peerId) => { + (cb) => df.spawn({ type, exec }, cb), + (node, cb) => node.api.id((err, peerId) => { if (err) { return cb(err) } - node.peerId = peerId + node.api.peerId = peerId cb(null, node) }) ], callback) @@ -31,23 +41,26 @@ module.exports = (common) => { let nodeB let nodeC + let ipfsdNodes 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, df, type) => { expect(err).to.not.exist() series([ - (cb) => spawnWithId(factory, cb), - (cb) => spawnWithId(factory, cb), - (cb) => spawnWithId(factory, cb) + (cb) => spawnWithId(df, type, cb), + (cb) => spawnWithId(df, type, cb), + (cb) => spawnWithId(df, type, cb) ], (err, nodes) => { expect(err).to.not.exist() - nodeA = nodes[0] - nodeB = nodes[1] - nodeC = nodes[2] + ipfsdNodes = nodes + + nodeA = nodes[0].api + nodeB = nodes[1].api + nodeC = nodes[2].api parallel([ (cb) => nodeA.swarm.connect(nodeB.peerId.addresses[0], cb), @@ -58,7 +71,7 @@ module.exports = (common) => { }) }) - after((done) => common.teardown(done)) + after((done) => parallel(ipfsdNodes.map((node) => (cb) => node.stop(cb)), done)) describe('.get and .put', () => { it('errors when getting a non-existent key from the DHT', (done) => { diff --git a/src/files.js b/src/files.js index 41725156..f981bb67 100644 --- a/src/files.js +++ b/src/files.js @@ -24,6 +24,7 @@ module.exports = (common) => { this.timeout(40 * 1000) let ipfs + let ipfsd function fixture (path) { return loadFixture(__dirname, path, 'interface-ipfs-core') @@ -55,17 +56,18 @@ module.exports = (common) => { // timeout for the before step this.timeout(60 * 1000) - common.setup((err, factory) => { + common.setup((err, df, type, exec) => { expect(err).to.not.exist() - factory.spawnNode((err, node) => { + df.spawn({ type, exec }, (err, node) => { expect(err).to.not.exist() - ipfs = node + ipfs = node.api + ipfsd = node done() }) }) }) - after((done) => common.teardown(done)) + after((done) => ipfsd.stop(done)) describe('.add', () => { it('a Buffer', (done) => { diff --git a/src/key.js b/src/key.js index 4e60f72e..43750893 100644 --- a/src/key.js +++ b/src/key.js @@ -12,10 +12,11 @@ const hat = require('hat') module.exports = (common) => { describe('.key', () => { const keyTypes = [ - {type: 'rsa', size: 2048} + { type: 'rsa', size: 2048 } ] const keys = [] let ipfs + let ipfsd let withGo before(function (done) { @@ -23,11 +24,12 @@ module.exports = (common) => { // timeout for the before step this.timeout(60 * 1000) - common.setup((err, factory) => { + common.setup((err, df, type, exec) => { expect(err).to.not.exist() - factory.spawnNode((err, node) => { + df.spawn({ type, exec }, (err, node) => { expect(err).to.not.exist() - ipfs = node + ipfsd = node + ipfs = node.api ipfs.id((err, id) => { expect(err).to.not.exist() withGo = id.agentVersion.startsWith('go-ipfs') @@ -37,7 +39,7 @@ module.exports = (common) => { }) }) - after((done) => common.teardown(done)) + after((done) => ipfsd.stop(done)) describe('.gen', () => { keyTypes.forEach((kt) => { diff --git a/src/miscellaneous.js b/src/miscellaneous.js index 7a7d60c9..56f5a189 100644 --- a/src/miscellaneous.js +++ b/src/miscellaneous.js @@ -11,25 +11,25 @@ chai.use(dirtyChai) module.exports = (common) => { describe('.miscellaneous', () => { let ipfs + let ipfsd 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, df, type, exec) => { expect(err).to.not.exist() - factory.spawnNode((err, node) => { + df.spawn({ type, exec }, (err, node) => { expect(err).to.not.exist() - ipfs = node + ipfs = node.api + ipfsd = node done() }) }) }) - after((done) => { - common.teardown(done) - }) + after((done) => ipfsd.stop(done)) it('.id', (done) => { ipfs.id((err, res) => { diff --git a/src/object.js b/src/object.js index 0ebf3df4..e33736c8 100644 --- a/src/object.js +++ b/src/object.js @@ -17,25 +17,25 @@ module.exports = (common) => { this.timeout(80 * 1000) let ipfs + let ipfsd 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, df, type, exec) => { expect(err).to.not.exist() - factory.spawnNode((err, node) => { + df.spawn({ type, exec }, (err, node) => { expect(err).to.not.exist() - ipfs = node + ipfs = node.api + ipfsd = node done() }) }) }) - after((done) => { - common.teardown(done) - }) + after((done) => ipfsd.stop(done)) describe('callback API', () => { describe('.new', () => { @@ -843,7 +843,7 @@ module.exports = (common) => { return ipfs.object.put(testObj, (err, node) => { expect(err).to.not.exist() - return ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', {enc: 'base58'}) + return ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', { enc: 'base58' }) .then((stats) => { const expected = { Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', diff --git a/src/pin.js b/src/pin.js index 6c76050e..f0cc5cfd 100644 --- a/src/pin.js +++ b/src/pin.js @@ -17,17 +17,19 @@ module.exports = (common) => { this.timeout(50 * 1000) let ipfs + let ipfsd 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, df, type, exec) => { expect(err).to.not.exist() - factory.spawnNode((err, node) => { + df.spawn({ type, exec }, (err, node) => { expect(err).to.not.exist() - ipfs = node + ipfs = node.api + ipfsd = node populate() }) }) @@ -43,7 +45,7 @@ module.exports = (common) => { } }) - after((done) => common.teardown(done)) + after((done) => ipfsd.stop(done)) describe('callback API', () => { // 1st, because ipfs.files.add pins automatically diff --git a/src/pubsub.js b/src/pubsub.js index d9e40f96..d324501a 100644 --- a/src/pubsub.js +++ b/src/pubsub.js @@ -32,14 +32,24 @@ function waitForPeers (ipfs, topic, peersToWait, callback) { }, 500) } -function spawnWithId (factory, callback) { +function spawnWithId (df, type, exec, callback) { + if (typeof type === 'function') { + callback = type + type = undefined + } + + if (typeof exec === 'function') { + callback = exec + exec = undefined + } + waterfall([ - (cb) => factory.spawnNode(cb), - (node, cb) => node.id((err, res) => { + (cb) => df.spawn({ type, exec, args: ['--enable-pubsub-experiment'] }, cb), + (node, cb) => node.api.id((err, res) => { if (err) { return cb(err) } - node.peerId = res + node.api.peerId = res cb(null, node) }) ], callback) @@ -68,36 +78,37 @@ module.exports = (common) => { let ipfs2 let ipfs3 + let ipfsdNodes before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the // timeout for the before step this.timeout(100 * 1000) - common.setup((err, factory) => { + common.setup((err, df) => { if (err) { return done(err) } series([ - (cb) => spawnWithId(factory, cb), - (cb) => spawnWithId(factory, cb), - (cb) => spawnWithId(factory, cb) + (cb) => spawnWithId(df, cb), + (cb) => spawnWithId(df, cb), + (cb) => spawnWithId(df, cb) ], (err, nodes) => { if (err) { return done(err) } - ipfs1 = nodes[0] - ipfs2 = nodes[1] - ipfs3 = nodes[2] + ipfsdNodes = nodes + + ipfs1 = nodes[0].api + ipfs2 = nodes[1].api + ipfs3 = nodes[2].api done() }) }) }) - after((done) => { - common.teardown(done) - }) + after((done) => parallel(ipfsdNodes.map((node) => (cb) => node.stop(cb)), done)) describe('single node', () => { describe('.publish', () => { diff --git a/src/swarm.js b/src/swarm.js index 9c43869a..8ee89314 100644 --- a/src/swarm.js +++ b/src/swarm.js @@ -8,6 +8,7 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) const series = require('async/series') +const parallel = require('async/parallel') const multiaddr = require('multiaddr') const os = require('os') const path = require('path') @@ -19,32 +20,35 @@ module.exports = (common) => { let ipfsA let ipfsB - let factoryInstance + let dfInstance + let nodes = [] before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the // timeout for the before step this.timeout(100 * 1000) - common.setup((err, factory) => { + common.setup((err, df, type, exec) => { expect(err).to.not.exist() - factoryInstance = factory + dfInstance = df series([ - (cb) => factory.spawnNode((err, node) => { + (cb) => df.spawn({ type, exec }, (err, node) => { expect(err).to.not.exist() - ipfsA = node + ipfsA = node.api + nodes.push(node) cb() }), - (cb) => factory.spawnNode((err, node) => { + (cb) => df.spawn((err, node) => { expect(err).to.not.exist() - ipfsB = node + ipfsB = node.api + nodes.push(node) cb() }) ], done) }) }) - after((done) => common.teardown(done)) + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) let ipfsBId @@ -90,7 +94,7 @@ module.exports = (common) => { }) it('verbose', (done) => { - ipfsA.swarm.peers({verbose: true}, (err, peers) => { + ipfsA.swarm.peers({ verbose: true }, (err, peers) => { expect(err).to.not.exist() expect(peers).to.have.length.above(0) @@ -132,6 +136,8 @@ module.exports = (common) => { } it('Connecting two peers with one address each', (done) => { + let nodes = [] + let nodeA let nodeB let nodeBAddress @@ -139,16 +145,18 @@ module.exports = (common) => { const config = getConfig(addresses) series([ (cb) => { - factoryInstance.spawnNode(getRepoPath(), config, (err, node) => { + dfInstance.spawn({ repoPath: getRepoPath(), config }, (err, node) => { expect(err).to.not.exist() - nodeA = node + nodes.push(node) + nodeA = node.api cb() }) }, (cb) => { - factoryInstance.spawnNode(getRepoPath(), config, (err, node) => { + dfInstance.spawn({ repoPath: getRepoPath(), config }, (err, node) => { expect(err).to.not.exist() - nodeB = node + nodes.push(node) + nodeB = node.api cb() }) }, @@ -175,10 +183,15 @@ module.exports = (common) => { cb() }) } - ], done) + ], (err) => { + expect(err).to.not.exist() + parallel(nodes.map((node) => (cb) => node.stop(cb)), done) + }) }) it('Connecting two peers with two addresses each', (done) => { + let nodes = [] + let nodeA let nodeB let nodeBAddress @@ -194,16 +207,18 @@ module.exports = (common) => { ]) series([ (cb) => { - factoryInstance.spawnNode(getRepoPath(), configA, (err, node) => { + dfInstance.spawn({ repoPath: getRepoPath(), config: configA }, (err, node) => { expect(err).to.not.exist() - nodeA = node + nodes.push(node) + nodeA = node.api cb() }) }, (cb) => { - factoryInstance.spawnNode(getRepoPath(), configB, (err, node) => { + dfInstance.spawn({ repoPath: getRepoPath(), config: configB }, (err, node) => { expect(err).to.not.exist() - nodeB = node + nodes.push(node) + nodeB = node.api cb() }) }, @@ -230,7 +245,10 @@ module.exports = (common) => { cb() }) } - ], done) + ], (err) => { + expect(err).to.not.exist() + parallel(nodes.map((node) => (cb) => node.stop(cb)), done) + }) }) }) })