From 7b3bb9f95371bd4e05bacc0de6de6476363efa43 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 22 Dec 2017 19:27:38 -0600 Subject: [PATCH 01/12] feat: reworking tests with new ipfsd-ctl --- .aegir.js | 37 ++--- package.json | 2 +- test/cli/pubsub.js | 62 ++++++-- test/cli/swarm.js | 30 +++- test/core/bitswap.spec.js | 44 +++--- test/core/circuit-relay.spec.js | 145 ------------------ test/core/interface/block.js | 13 +- test/core/interface/config.js | 15 +- test/core/interface/dag.js | 14 +- test/core/interface/dht.js | 11 +- test/core/interface/files.js | 13 +- test/core/interface/generic.js | 15 +- test/core/interface/object.js | 14 +- test/core/interface/pubsub.js | 13 +- test/core/interface/swarm.js | 14 +- test/core/kad-dht.node.js | 59 +++++-- test/http-api/interface/block.js | 11 +- test/http-api/interface/config.js | 11 +- test/http-api/interface/files.js | 11 +- test/http-api/interface/object.js | 11 +- test/http-api/interface/pubsub.js | 11 +- test/http-api/interface/swarm.js | 11 +- test/utils/another-daemon-spawner.js | 73 --------- .../ipfs-factory-daemon/default-config.json | 41 ----- test/utils/ipfs-factory-daemon/index.js | 79 ---------- .../ipfs-factory-instance/default-config.json | 29 ---- test/utils/ipfs-factory-instance/index.js | 63 -------- test/utils/on-and-off.js | 17 +- 28 files changed, 223 insertions(+), 646 deletions(-) delete mode 100644 test/core/circuit-relay.spec.js delete mode 100644 test/utils/another-daemon-spawner.js delete mode 100644 test/utils/ipfs-factory-daemon/default-config.json delete mode 100644 test/utils/ipfs-factory-daemon/index.js delete mode 100644 test/utils/ipfs-factory-instance/default-config.json delete mode 100644 test/utils/ipfs-factory-instance/index.js diff --git a/.aegir.js b/.aegir.js index 148ab3fbb8..58b0db3159 100644 --- a/.aegir.js +++ b/.aegir.js @@ -1,41 +1,22 @@ 'use strict' -const parallel = require('async/parallel') -const ads = require('./test/utils/another-daemon-spawner') -const js = ads.spawnJsNode -const stop = ads.stopNodes - -/* - * spawns a daemon with ports numbers starting in 10 and ending in `num` - */ -function start (done) { - const base = '/ip4/127.0.0.1/tcp' - if (!process.env.IPFS_TEST) { - parallel([ - (cb) => js([`${base}/10007`, `${base}/20007/ws`], true, 31007, 32007, cb), - (cb) => js([`${base}/10008`, `${base}/20008/ws`], true, 31008, 32008, cb), - (cb) => js([`${base}/10012`, `${base}/20012/ws`], true, 31012, 32012, cb), - (cb) => js([`${base}/10013`, `${base}/20013/ws`], true, 31013, 32013, cb), - (cb) => js([`${base}/10014`, `${base}/20014/ws`], true, 31014, 32014, cb), - (cb) => js([`${base}/10015`, `${base}/20015/ws`], true, 31015, 32015, cb) - ], done) - } else if (process.env.IPFS_TEST === 'bootstrapers') { - done() - } -} +const createServer = require('ipfsd-ctl').createServer +const server = createServer() module.exports = { karma: { files: [{ pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*', watched: false, served: true, - included: false, - singleRun: false - }] + included: false + }], + singleRun: true }, hooks: { - pre: start, - post: stop + browser: { + pre: server.start.bind(server), + post: server.stop.bind(server) + } } } diff --git a/package.json b/package.json index 937b07c496..0a510674e6 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "build": "aegir build", "test": "aegir test -t node -t browser -t webworker --no-cors", "test:node": "aegir test -t node", - "test:browser": "aegir test -t browser -t webworker --no-cors", + "test:browser": "aegir test -t browser --no-cors", "test:node:core": "aegir test -t node -f test/core/**.js", "test:node:http": "aegir test -t node -f test/http-api/index.js", "test:node:gateway": "aegir test -t node -f test/gateway/index.js", diff --git a/test/cli/pubsub.js b/test/cli/pubsub.js index 3df5bf8417..efca7a31b4 100644 --- a/test/cli/pubsub.js +++ b/test/cli/pubsub.js @@ -8,16 +8,28 @@ const expect = chai.expect chai.use(dirtyChai) const delay = require('delay') const series = require('async/series') -const InstanceFactory = require('../utils/ipfs-factory-instance') -const DaemonFactory = require('../utils/ipfs-factory-daemon') const ipfsExec = require('../utils/ipfs-exec') +const createRepo = require('../utils/create-repo-nodejs') +const IPFS = require('../../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const config = { + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: + false + } + } +} describe('pubsub', function () { - this.timeout(40 * 1000) + this.timeout(80 * 1000) - let instanceFactory - let daemonFactory let node + let ipfsd let cli let httpApi @@ -25,29 +37,51 @@ describe('pubsub', function () { const topicB = 'nonscentsB' const topicC = 'nonscentsC' + let repo = createRepo() before(function (done) { this.timeout(60 * 1000) - instanceFactory = new InstanceFactory() - instanceFactory.spawnNode((err, _node) => { - expect(err).to.not.exist() - node = _node + node = new IPFS({ + repo: createRepo(), + init: { bits: 1024 }, + EXPERIMENTAL: { + pubsub: true + }, + config + }) + + node.once('ready', () => { done() }) + + node.once('error', (err) => { + done(err) + }) }) - after((done) => instanceFactory.dismantle(done)) + after((done) => { + node.stop((err) => { + expect(err).to.not.exist() + repo.teardown(done) + }) + }) before((done) => { - daemonFactory = new DaemonFactory() - daemonFactory.spawnNode((err, _node) => { + df.spawn({ + type: 'js', + args: ['--enable-pubsub-experiment'], + exec: `${process.cwd()}/src/cli/bin.js`, + config + }, (err, _node) => { expect(err).to.not.exist() - httpApi = _node + httpApi = _node.api + ipfsd = _node + httpApi.repoPath = ipfsd.repoPath done() }) }) - after((done) => daemonFactory.dismantle(done)) + after((done) => ipfsd.stop(done)) before((done) => { cli = ipfsExec(httpApi.repoPath) diff --git a/test/cli/swarm.js b/test/cli/swarm.js index d2c69846be..1f67424747 100644 --- a/test/cli/swarm.js +++ b/test/cli/swarm.js @@ -8,34 +8,48 @@ const expect = chai.expect chai.use(dirtyChai) const series = require('async/series') const ipfsExec = require('../utils/ipfs-exec') -const Factory = require('../utils/ipfs-factory-daemon') + +const parallel = require('async/parallel') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const config = { + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: + false + } + } +} describe('swarm', () => { - let factory let bMultiaddr let ipfsA + 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(80 * 1000) - factory = new Factory() - series([ (cb) => { - factory.spawnNode((err, node) => { + df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => { expect(err).to.not.exist() ipfsA = ipfsExec(node.repoPath) + nodes.push(node) cb() }) }, (cb) => { - factory.spawnNode((err, node) => { + df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => { expect(err).to.not.exist() - node.id((err, id) => { + node.api.id((err, id) => { expect(err).to.not.exist() bMultiaddr = id.addresses[0] + nodes.push(node) cb() }) }) @@ -43,7 +57,7 @@ describe('swarm', () => { ], done) }) - after((done) => factory.dismantle(done)) + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) describe('daemon on (through http-api)', function () { this.timeout(60 * 1000) diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index 2dffff99bc..6ee4099fb0 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -10,14 +10,15 @@ const _ = require('lodash') const series = require('async/series') const waterfall = require('async/waterfall') const parallel = require('async/parallel') -const leftPad = require('left-pad') const Block = require('ipfs-block') -const API = require('ipfs-api') const multiaddr = require('multiaddr') const isNode = require('detect-node') const multihashing = require('multihashing-async') const CID = require('cids') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + // This gets replaced by '../utils/create-repo-browser.js' in the browser const createTempRepo = require('../utils/create-repo-nodejs.js') @@ -63,13 +64,14 @@ function connectNodes (remoteNode, inProcNode, callback) { ], callback) } -function addNode (num, inProcNode, callback) { - num = leftPad(num, 3, 0) - - const apiUrl = `/ip4/127.0.0.1/tcp/31${num}` - const remoteNode = new API(apiUrl) +let nodes = [] - connectNodes(remoteNode, inProcNode, (err) => callback(err, remoteNode)) +function addNode (inProcNode, callback) { + df.spawn({ type: 'js', exec: `./src/cli/bin.js` }, (err, ipfsd) => { + expect(err).to.not.exist() + nodes.push(ipfsd) + connectNodes(ipfsd.api, inProcNode, (err) => callback(err, ipfsd.api)) + }) } describe('bitswap', function () { @@ -110,20 +112,26 @@ describe('bitswap', function () { }) afterEach(function (done) { - this.timeout(60 * 1000) - setTimeout(() => inProcNode.stop(() => done()), 500) + this.timeout(80 * 1000) + const tasks = nodes.map((node) => (cb) => node.stop(cb)) + tasks.push((cb) => setTimeout(() => inProcNode.stop(() => cb()), 500)) + parallel(tasks, (err) => { + expect(err).to.not.exist() + nodes = [] + done(err) + }) }) describe('transfer a block between', () => { it('2 peers', function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) let remoteNode let block waterfall([ (cb) => parallel([ (cb) => makeBlock(cb), - (cb) => addNode(13, inProcNode, cb) + (cb) => addNode(inProcNode, cb) ], cb), (res, cb) => { block = res[0] @@ -140,7 +148,7 @@ describe('bitswap', function () { }) it('3 peers', function (done) { - this.timeout(60 * 1000) + this.timeout(80 * 1000) let blocks const remoteNodes = [] @@ -151,11 +159,11 @@ describe('bitswap', function () { blocks = _blocks cb() }), - (cb) => addNode(8, inProcNode, (err, _ipfs) => { + (cb) => addNode(inProcNode, (err, _ipfs) => { remoteNodes.push(_ipfs) cb(err) }), - (cb) => addNode(7, inProcNode, (err, _ipfs) => { + (cb) => addNode(inProcNode, (err, _ipfs) => { remoteNodes.push(_ipfs) cb(err) }), @@ -193,10 +201,10 @@ describe('bitswap', function () { waterfall([ // 0. Start node - (cb) => addNode(12, inProcNode, cb), + (cb) => addNode(inProcNode, cb), // 1. Add file to tmp instance (remote, cb) => { - remote.files.add([{path: 'awesome.txt', content: file}], cb) + remote.files.add([{ path: 'awesome.txt', content: file }], cb) }, // 2. Request file from local instance (filesAdded, cb) => inProcNode.files.cat(filesAdded[0].hash, cb) @@ -247,7 +255,7 @@ describe('bitswap', function () { describe('while online', () => { before(function (done) { - this.timeout(40 * 1000) + this.timeout(80 * 1000) node.start(() => done()) }) diff --git a/test/core/circuit-relay.spec.js b/test/core/circuit-relay.spec.js deleted file mode 100644 index 4934b5cadb..0000000000 --- a/test/core/circuit-relay.spec.js +++ /dev/null @@ -1,145 +0,0 @@ -/* eslint max-nested-callbacks: ["error", 8] */ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) -const parallel = require('async/parallel') -const series = require('async/series') -const waterfall = require('async/waterfall') -const API = require('ipfs-api') -const bl = require('bl') -const PeerInfo = require('peer-info') -const PeerId = require('peer-id') -const multiaddr = require('multiaddr') -const isNode = require('detect-node') -const crypto = require('crypto') -const IPFSFactory = require('../utils/ipfs-factory-instance') - -function peerInfoFromObj (obj, callback) { - waterfall([ - (cb) => PeerInfo.create(PeerId.createFromB58String(obj.id), cb), - (peer, cb) => { - obj.addresses.forEach((a) => peer.multiaddrs.add(multiaddr(a))) - cb(null, peer) - } - ], callback) -} - -describe.skip('circuit', function () { - this.timeout(40 * 1000) - - let factory - - let jsRelay = new API(`/ip4/127.0.0.1/tcp/31015`) - // let goRelay = new API(`/ip4/127.0.0.1/tcp/33031`) - let node1 - let node2 - - let jsRelayId - let goRelayId - - // let nodeId1 - let nodeId2 - - before(function (done) { - this.timeout(40 * 1000) - - factory = new IPFSFactory() - - const base = { - EXPERIMENTAL: { - Relay: { - Enabled: true - } - }, - Addresses: { - Swarm: [] - } - } - - parallel([ - (cb) => factory.spawnNode(null, Object.assign(base, { - Addresses: { - Swarm: [ (isNode ? `/ip4/127.0.0.1/tcp/0` : '') ] - } - }), cb), - (cb) => factory.spawnNode(null, Object.assign(base, { - Addresses: { - Swarm: [ (isNode ? `/ip4/127.0.0.1/tcp/0/ws` : '') ] - } - }), cb) - ], (err, nodes) => { - expect(err).to.not.exist() - node1 = nodes[0] - node2 = nodes[1] - - parallel([ - (cb) => jsRelay.id(cb), - // (cb) => goRelay.id(cb), - (cb) => node1.id(cb), - (cb) => node2.id(cb) - ], (err, res2) => { - expect(err).to.not.exist() - parallel([ - (cb) => peerInfoFromObj(res2[0], cb), - // (cb) => peerInfoFromObj(res2[1], cb), - (cb) => peerInfoFromObj(res2[1], cb), - (cb) => peerInfoFromObj(res2[2], cb) - ], (err, res3) => { - expect(err).to.not.exist() - jsRelayId = res3[0] - // goRelayId = res3[1] - // nodeId1 = res3[2] - nodeId2 = res3[2] - done() - }) - }) - }) - }) - - after((done) => factory.dismantle(done)) - - // TODO: 1) figure out why this test hangs randomly - // TODO: 2) move this test to the interop batch - it.skip('node1 <-> goRelay <-> node2', (done) => { - const data = crypto.randomBytes(128) - - series([ - (cb) => node1.swarm.connect(goRelayId, cb), - (cb) => setTimeout(cb, 1000), - (cb) => node2.swarm.connect(goRelayId, cb), - (cb) => setTimeout(cb, 1000), - (cb) => node1.swarm.connect(nodeId2, cb) - ], (err) => { - expect(err).to.not.exist() - waterfall([ - (cb) => node1.files.add(data, cb), - (filesAdded, cb) => node2.files.cat(filesAdded[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], done) - }) - }) - - it('node1 <-> jsRelay <-> node2', (done) => { - const data = crypto.randomBytes(128) - - series([ - (cb) => node1.swarm.connect(jsRelayId, cb), - (cb) => setTimeout(cb, 1000), - (cb) => node2.swarm.connect(jsRelayId, cb), - (cb) => setTimeout(cb, 1000), - (cb) => node1.swarm.connect(nodeId2, cb) - ], (err) => { - expect(err).to.not.exist() - - waterfall([ - (cb) => node1.files.add(data, cb), - (filesAdded, cb) => node2.files.cat(filesAdded[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], done) - }) - }) -}) diff --git a/test/core/interface/block.js b/test/core/interface/block.js index fafb7f7e70..70526983cf 100644 --- a/test/core/interface/block.js +++ b/test/core/interface/block.js @@ -2,17 +2,14 @@ 'use strict' const test = require('interface-ipfs-core') -const IPFSFactory = require('../../utils/ipfs-factory-instance') +const IPFS = require('../../../src') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ remote: false }) const common = { - setup: function (cb) { - factory = new IPFSFactory() - cb(null, factory) - }, - teardown: function (cb) { - factory.dismantle(cb) + setup: function (callback) { + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/interface/config.js b/test/core/interface/config.js index 80b0c76d9e..9902b5bff5 100644 --- a/test/core/interface/config.js +++ b/test/core/interface/config.js @@ -1,20 +1,15 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const IPFSFactory = require('../../utils/ipfs-factory-instance') +const IPFS = require('../../../src') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ remote: false }) const common = { - setup: function (cb) { - factory = new IPFSFactory() - cb(null, factory) - }, - teardown: function (cb) { - factory.dismantle(cb) + setup: function (callback) { + callback(null, df, 'proc', IPFS) } } - test.config(common) diff --git a/test/core/interface/dag.js b/test/core/interface/dag.js index cab259b00a..bc77df29dd 100644 --- a/test/core/interface/dag.js +++ b/test/core/interface/dag.js @@ -1,19 +1,15 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const IPFSFactory = require('../../utils/ipfs-factory-instance') +const IPFS = require('../../../src') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ remote: false }) const common = { - setup: function (cb) { - factory = new IPFSFactory() - cb(null, factory) - }, - teardown: function (cb) { - factory.dismantle(cb) + setup: function (callback) { + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/interface/dht.js b/test/core/interface/dht.js index 28e6bb7658..848093054f 100644 --- a/test/core/interface/dht.js +++ b/test/core/interface/dht.js @@ -1,20 +1,15 @@ /* eslint-env mocha */ - 'use strict' /* const test = require('interface-ipfs-core') -const IPFSFactory = require('../../utils/ipfs-factory-instance') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - factory = new IPFSFactory() - callback(null, factory) - }, - teardown: function (callback) { - factory.dismantle(callback) + callback(null, df) } } diff --git a/test/core/interface/files.js b/test/core/interface/files.js index 5c7c7f391c..c29be5b2b4 100644 --- a/test/core/interface/files.js +++ b/test/core/interface/files.js @@ -2,17 +2,14 @@ 'use strict' const test = require('interface-ipfs-core') -const IPFSFactory = require('../../utils/ipfs-factory-instance') +const IPFS = require('../../../src') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ remote: false }) const common = { - setup: function (cb) { - factory = new IPFSFactory() - cb(null, factory) - }, - teardown: function (cb) { - factory.dismantle(cb) + setup: function (callback) { + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/interface/generic.js b/test/core/interface/generic.js index d2c8825a11..5908219f13 100644 --- a/test/core/interface/generic.js +++ b/test/core/interface/generic.js @@ -1,20 +1,15 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const IPFSFactory = require('../../utils/ipfs-factory-instance') +const IPFS = require('../../../src') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ remote: false }) const common = { - setup: function (cb) { - factory = new IPFSFactory() - cb(null, factory) - }, - teardown: function (cb) { - factory.dismantle(cb) + setup: function (callback) { + callback(null, df, 'proc', IPFS) } } - test.generic(common) diff --git a/test/core/interface/object.js b/test/core/interface/object.js index 97ac3e3b64..a5ce52107b 100644 --- a/test/core/interface/object.js +++ b/test/core/interface/object.js @@ -1,19 +1,15 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const IPFSFactory = require('../../utils/ipfs-factory-instance') +const IPFS = require('../../../src') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ remote: false }) const common = { - setup: function (cb) { - factory = new IPFSFactory() - cb(null, factory) - }, - teardown: function (cb) { - factory.dismantle(cb) + setup: function (callback) { + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/interface/pubsub.js b/test/core/interface/pubsub.js index 4264b0c96b..dd9905075a 100644 --- a/test/core/interface/pubsub.js +++ b/test/core/interface/pubsub.js @@ -2,17 +2,14 @@ 'use strict' const test = require('interface-ipfs-core') -const IPFSFactory = require('../../utils/ipfs-factory-instance') +const IPFS = require('../../../src') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ remote: false }) const common = { - setup: function (cb) { - factory = new IPFSFactory() - cb(null, factory) - }, - teardown: function (cb) { - factory.dismantle(cb) + setup: function (callback) { + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/interface/swarm.js b/test/core/interface/swarm.js index 15da9f484a..5f84c93c7a 100644 --- a/test/core/interface/swarm.js +++ b/test/core/interface/swarm.js @@ -1,19 +1,15 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const IPFSFactory = require('../../utils/ipfs-factory-instance') +const IPFS = require('../../../src') -let factory +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ remote: false }) const common = { - setup: function (cb) { - factory = new IPFSFactory() - cb(null, factory) - }, - teardown: function (cb) { - factory.dismantle(cb) + setup: function (callback) { + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/kad-dht.node.js b/test/core/kad-dht.node.js index 1bd0123575..dc83973627 100644 --- a/test/core/kad-dht.node.js +++ b/test/core/kad-dht.node.js @@ -7,10 +7,45 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) const parallel = require('async/parallel') -const IPFSFactory = require('../utils/ipfs-factory-instance') +const IPFS = require('../../src') + +const createRepo = require('../utils/create-repo-nodejs') + +const config = { + Addresses: { + Swarm: [`/ip4/127.0.0.1/tcp/0`], + API: `/ip4/127.0.0.1/tcp/0`, + Gateway: `/ip4/127.0.0.1/tcp/0` + }, + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: + false + } + } +} + +function createNode (callback) { + const node = new IPFS({ + repo: createRepo(), + init: { bits: 1024 }, + EXPERIMENTAL: { + pubsub: true + }, + config + }) + + node.once('ready', () => { + callback(null, node) + }) + + node.once('error', (err) => { + callback(err) + }) +} describe('verify that kad-dht is doing its thing', () => { - let factory let nodeA let nodeB let nodeC @@ -18,18 +53,18 @@ describe('verify that kad-dht is doing its thing', () => { let addrB let addrC + let nodes before((done) => { - factory = new IPFSFactory() - parallel([ - (cb) => factory.spawnNode(cb), - (cb) => factory.spawnNode(cb), - (cb) => factory.spawnNode(cb) - ], (err, nodes) => { + (cb) => createNode(cb), + (cb) => createNode(cb), + (cb) => createNode(cb) + ], (err, _nodes) => { expect(err).to.not.exist() - nodeA = nodes[0] - nodeB = nodes[1] - nodeC = nodes[2] + nodes = _nodes + nodeA = _nodes[0] + nodeB = _nodes[1] + nodeC = _nodes[2] parallel([ (cb) => nodeA.id(cb), (cb) => nodeB.id(cb), @@ -47,7 +82,7 @@ describe('verify that kad-dht is doing its thing', () => { }) }) - after((done) => factory.dismantle(done)) + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) it.skip('add a file in C, fetch through B in A', function (done) { this.timeout(10 * 1000) diff --git a/test/http-api/interface/block.js b/test/http-api/interface/block.js index db39d378c6..e948b3c98f 100644 --- a/test/http-api/interface/block.js +++ b/test/http-api/interface/block.js @@ -1,19 +1,14 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('./../../utils/ipfs-factory-daemon') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df) } } diff --git a/test/http-api/interface/config.js b/test/http-api/interface/config.js index 30837f8b86..389b6d9c47 100644 --- a/test/http-api/interface/config.js +++ b/test/http-api/interface/config.js @@ -1,19 +1,14 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('./../../utils/ipfs-factory-daemon') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df, 'js', './src/cli/bin.js') } } diff --git a/test/http-api/interface/files.js b/test/http-api/interface/files.js index 84b150f79f..5bb317771d 100644 --- a/test/http-api/interface/files.js +++ b/test/http-api/interface/files.js @@ -1,19 +1,14 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('./../../utils/ipfs-factory-daemon') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df, 'js', './src/cli/bin.js') } } diff --git a/test/http-api/interface/object.js b/test/http-api/interface/object.js index e00df72564..725602faff 100644 --- a/test/http-api/interface/object.js +++ b/test/http-api/interface/object.js @@ -1,19 +1,14 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('./../../utils/ipfs-factory-daemon') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df, 'js', './src/cli/bin.js') } } diff --git a/test/http-api/interface/pubsub.js b/test/http-api/interface/pubsub.js index ab474fac9f..05d1010349 100644 --- a/test/http-api/interface/pubsub.js +++ b/test/http-api/interface/pubsub.js @@ -1,19 +1,14 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('./../../utils/ipfs-factory-daemon') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df, 'js', './src/cli/bin.js') } } diff --git a/test/http-api/interface/swarm.js b/test/http-api/interface/swarm.js index eeca079124..74e862013f 100644 --- a/test/http-api/interface/swarm.js +++ b/test/http-api/interface/swarm.js @@ -1,19 +1,14 @@ /* eslint-env mocha */ - 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('./../../utils/ipfs-factory-daemon') -let fc +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const common = { setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) + callback(null, df, 'js', './src/cli/bin.js') } } diff --git a/test/utils/another-daemon-spawner.js b/test/utils/another-daemon-spawner.js deleted file mode 100644 index 5d55be3295..0000000000 --- a/test/utils/another-daemon-spawner.js +++ /dev/null @@ -1,73 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const waterfall = require('async/waterfall') -const series = require('async/series') - -const relayConfig = require('./ipfs-factory-daemon/default-config.json') -const Factory = require('./ipfs-factory-daemon') - -const nodes = [] -const factory = new Factory() -exports = module.exports - -exports.spawnJsNode = (addrs, hop, api, gateway, callback) => { - let relayPeer - let relayAddrs - - if (typeof hop === 'function') { - callback = hop - hop = false - } - if (typeof api === 'function') { - callback = api - api = 0 - } - if (typeof gateway === 'function') { - callback = gateway - gateway = 0 - } - - api = api || 0 - gateway = gateway || 0 - - callback = callback || function noop () {} - - waterfall([ - (cb) => factory.spawnNode(null, Object.assign(relayConfig, { - Addresses: { - Swarm: addrs, - API: `/ip4/0.0.0.0/tcp/${api}`, - Gateway: `/ip4/0.0.0.0/tcp/${gateway}` - }, - EXPERIMENTAL: { - Swarm: { - DisableRelay: false, - EnableRelayHop: hop - } - } - }), cb), - (node, cb) => { - relayPeer = node - relayPeer.swarm.localAddrs(cb) - }, - (addrs, cb) => { - relayAddrs = addrs - cb() - } - ], (err) => { - if (err) { - return callback(err) - } - callback(null, relayPeer, relayAddrs) - }) -} - -exports.stopNodes = (callback) => { - series([ - (cb) => factory.dismantle(cb) - ].concat(nodes.map((node) => (cb) => { - setTimeout(() => node.stop(cb), 100) - })), callback) -} diff --git a/test/utils/ipfs-factory-daemon/default-config.json b/test/utils/ipfs-factory-daemon/default-config.json deleted file mode 100644 index f2203594df..0000000000 --- a/test/utils/ipfs-factory-daemon/default-config.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "Identity": { - "PeerID": "", - "PrivKey": "" - }, - "Addresses": { - "Swarm": [ - "/ip4/127.0.0.1/tcp/0" - ], - "API": "/ip4/127.0.0.1/tcp/0", - "Gateway": "/ip4/127.0.0.1/tcp/0" - }, - "Version": { - "Current": "jsipfs-dev", - "Check": "error", - "CheckDate": "0001-01-01T00:00:00Z", - "CheckPeriod": "172800000000000", - "AutoUpdate": "minor" - }, - "Discovery": { - "MDNS": { - "Enabled": false, - "Interval": 10 - }, - "webRTCStar": { - "Enabled": false - } - }, - "Bootstrap": [], - "Gateway": { - "HTTPHeaders": null, - "RootRedirect": "", - "Writable": false - }, - "API": { - "HTTPHeaders": null - }, - "Swarm": { - "AddrFilters": null - } -} diff --git a/test/utils/ipfs-factory-daemon/index.js b/test/utils/ipfs-factory-daemon/index.js deleted file mode 100644 index 2dde6d4eef..0000000000 --- a/test/utils/ipfs-factory-daemon/index.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict' - -const PeerId = require('peer-id') -const IPFSAPI = require('ipfs-api') -const clean = require('../clean') -const HttpApi = require('../../../src/http') -const series = require('async/series') -const eachSeries = require('async/eachSeries') -const defaultConfig = require('./default-config.json') -const os = require('os') -const hat = require('hat') - -class Factory { - constructor () { - this.daemonsSpawned = [] - } - - /* yields a new started node */ - spawnNode (repoPath, suppliedConfig, callback) { - if (typeof repoPath === 'function') { - callback = repoPath - repoPath = undefined - } - if (typeof suppliedConfig === 'function') { - callback = suppliedConfig - suppliedConfig = {} - } - - repoPath = repoPath || os.tmpdir() + '/ipfs-' + hat() - - let daemon - let ctl - let config - - series([ - (cb) => { - // prepare config for node - - config = Object.assign({}, defaultConfig, suppliedConfig) - - PeerId.create({ bits: 1024 }, (err, id) => { - if (err) { return cb(err) } - - const peerId = id.toJSON() - config.Identity.PeerID = peerId.id - config.Identity.PrivKey = peerId.privKey - cb() - }) - }, - (cb) => { - daemon = new HttpApi(repoPath, config, {enablePubsubExperiment: true}) - daemon.repoPath = repoPath - this.daemonsSpawned.push(daemon) - - daemon.start(true, cb) - }, - (cb) => { - ctl = IPFSAPI(daemon.apiMultiaddr) - ctl.repoPath = repoPath - ctl.apiMultiaddr = daemon.apiMultiaddr - cb() - } - ], (err) => callback(err, ctl)) - } - - dismantle (callback) { - eachSeries(this.daemonsSpawned, (d, cb) => { - d.stop((err) => { - clean(d.repoPath) - if (err) { - console.error('error stopping', err) - } - cb(err) - }) - }, callback) - } -} - -module.exports = Factory diff --git a/test/utils/ipfs-factory-instance/default-config.json b/test/utils/ipfs-factory-instance/default-config.json deleted file mode 100644 index 677c7c85d9..0000000000 --- a/test/utils/ipfs-factory-instance/default-config.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "Addresses": { - "Swarm": [ - "/ip4/127.0.0.1/tcp/0" - ], - "API": "/ip4/127.0.0.1/tcp/0", - "Gateway": "/ip4/127.0.0.1/tcp/0" - }, - "Version": { - "Current": "jsipfs-dev", - "Check": "error", - "CheckDate": "0001-01-01T00:00:00Z", - "CheckPeriod": "172800000000000", - "AutoUpdate": "minor" - }, - "Discovery": { - "MDNS": { - "Enabled": false, - "Interval": 10 - }, - "webRTCStar": { - "Enabled": false - } - }, - "Bootstrap": [], - "API": { - "HTTPHeaders": null - } -} diff --git a/test/utils/ipfs-factory-instance/index.js b/test/utils/ipfs-factory-instance/index.js deleted file mode 100644 index 568a1710a7..0000000000 --- a/test/utils/ipfs-factory-instance/index.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict' - -const series = require('async/series') -const each = require('async/each') -const hat = require('hat') -const os = require('os') -const path = require('path') - -const defaultConfig = require('./default-config.json') -const IPFS = require('../../../src/core') -const createTempRepo = require('../create-repo-nodejs') - -module.exports = Factory - -function Factory () { - if (!(this instanceof Factory)) { - return new Factory() - } - - const nodes = [] - - /* yields a new started node instance */ - this.spawnNode = (repoPath, suppliedConfig, callback) => { - if (typeof repoPath === 'function') { - callback = repoPath - repoPath = undefined - } - - if (typeof suppliedConfig === 'function') { - callback = suppliedConfig - suppliedConfig = {} - } - - if (!repoPath) { - repoPath = path.join(os.tmpdir(), '.ipfs-' + hat()) - } - - const config = Object.assign({}, defaultConfig, suppliedConfig) - - const repo = createTempRepo(repoPath) - const node = new IPFS({ - repo: repo, - init: { bits: 1024 }, - config: config, - EXPERIMENTAL: { - pubsub: true, - dht: true - } - }) - - node.once('ready', () => { - nodes.push({ repo: repo, ipfs: node }) - callback(null, node) - }) - } - - this.dismantle = function (callback) { - series([ - (cb) => each(nodes, (el, cb) => el.ipfs.stop(cb), cb), - (cb) => each(nodes, (el, cb) => el.repo.teardown(cb), cb) - ], callback) - } -} diff --git a/test/utils/on-and-off.js b/test/utils/on-and-off.js index 8a79c660ef..4aa6344eeb 100644 --- a/test/utils/on-and-off.js +++ b/test/utils/on-and-off.js @@ -1,7 +1,6 @@ /* eslint-env mocha */ 'use strict' -const Factory = require('../utils/ipfs-factory-daemon') const hat = require('hat') const chai = require('chai') const dirtyChai = require('dirty-chai') @@ -12,6 +11,9 @@ const ipfsExec = require('../utils/ipfs-exec') const clean = require('../utils/clean') const os = require('os') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + function off (tests) { describe('daemon off (directly to core)', () => { let thing = {} @@ -27,7 +29,7 @@ function off (tests) { }) after(function (done) { - this.timeout(26 * 1000) + this.timeout(20 * 1000) clean(repoPath) setImmediate(done) }) @@ -38,19 +40,18 @@ function off (tests) { function on (tests) { describe('daemon on (through http-api)', () => { - let factory let thing = {} + 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) - factory = new Factory() - - factory.spawnNode((err, node) => { + df.spawn({ type: 'js', exec: `./src/cli/bin.js` }, (err, node) => { expect(err).to.not.exist() + ipfsd = node thing.ipfs = ipfsExec(node.repoPath) thing.ipfs.repoPath = node.repoPath done() @@ -58,8 +59,8 @@ function on (tests) { }) after(function (done) { - this.timeout(60 * 1000) - factory.dismantle(done) + this.timeout(15 * 1000) + ipfsd.stop(done) }) tests(thing) From fe5f6d69ef5fb1a45289a680ce6f1b9630a0c67a Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Thu, 28 Dec 2017 16:26:15 -0600 Subject: [PATCH 02/12] chore: add go-ipfs-dep --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0a510674e6..3a15589f46 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "execa": "^0.9.0", "expose-loader": "^0.7.4", "form-data": "^2.3.1", + "go-ipfs-dep": "^0.4.13", "hat": "0.0.3", "interface-ipfs-core": "~0.40.0", "left-pad": "^1.2.0", From 72d79100247ee6c07f2ce523534dfa2f753ac1ae Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Thu, 28 Dec 2017 23:27:45 -0600 Subject: [PATCH 03/12] test: fixing remaining tests --- test/cli/pubsub.js | 54 ++++++++++++++------------------ test/cli/swarm.js | 4 +-- test/core/bitswap.spec.js | 28 ++++++++++++----- test/core/bootstrap.spec.js | 34 +++++++++----------- test/core/files-sharding.spec.js | 36 ++++++++++++++------- test/core/kad-dht.node.js | 32 +++++-------------- test/http-api/interface/block.js | 2 +- 7 files changed, 93 insertions(+), 97 deletions(-) diff --git a/test/cli/pubsub.js b/test/cli/pubsub.js index efca7a31b4..e1ae1b800a 100644 --- a/test/cli/pubsub.js +++ b/test/cli/pubsub.js @@ -9,7 +9,6 @@ chai.use(dirtyChai) const delay = require('delay') const series = require('async/series') const ipfsExec = require('../utils/ipfs-exec') -const createRepo = require('../utils/create-repo-nodejs') const IPFS = require('../../src') const DaemonFactory = require('ipfsd-ctl') @@ -29,7 +28,8 @@ describe('pubsub', function () { this.timeout(80 * 1000) let node - let ipfsd + let ipfsdA + let ipfsdB let cli let httpApi @@ -37,51 +37,43 @@ describe('pubsub', function () { const topicB = 'nonscentsB' const topicC = 'nonscentsC' - let repo = createRepo() before(function (done) { this.timeout(60 * 1000) - node = new IPFS({ - repo: createRepo(), - init: { bits: 1024 }, - EXPERIMENTAL: { - pubsub: true - }, - config - }) - - node.once('ready', () => { - done() - }) - - node.once('error', (err) => { - done(err) - }) + DaemonFactory + .create({ remote: false }) + .spawn({ + type: 'proc', + exec: IPFS, + config, + args: ['--enable-pubsub-experiment'] + }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsdA = _ipfsd + node = _ipfsd.api + done() + }) }) - after((done) => { - node.stop((err) => { - expect(err).to.not.exist() - repo.teardown(done) - }) - }) + after((done) => ipfsdB.stop(done)) before((done) => { df.spawn({ type: 'js', args: ['--enable-pubsub-experiment'], - exec: `${process.cwd()}/src/cli/bin.js`, + exec: `./src/cli/bin.js`, config - }, (err, _node) => { + }, (err, _ipfsd) => { expect(err).to.not.exist() - httpApi = _node.api - ipfsd = _node - httpApi.repoPath = ipfsd.repoPath + httpApi = _ipfsd.api + ipfsdB = _ipfsd + httpApi.repoPath = ipfsdB.repoPath done() }) }) - after((done) => ipfsd.stop(done)) + after((done) => ipfsdA.stop(done)) + after((done) => ipfsdB.stop(done)) before((done) => { cli = ipfsExec(httpApi.repoPath) diff --git a/test/cli/swarm.js b/test/cli/swarm.js index 1f67424747..b514b2aa2c 100644 --- a/test/cli/swarm.js +++ b/test/cli/swarm.js @@ -36,7 +36,7 @@ describe('swarm', () => { series([ (cb) => { - df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => { + df.spawn({ type: 'js', exec: `./src/cli/bin.js`, config }, (err, node) => { expect(err).to.not.exist() ipfsA = ipfsExec(node.repoPath) nodes.push(node) @@ -44,7 +44,7 @@ describe('swarm', () => { }) }, (cb) => { - df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => { + df.spawn({ type: 'js', exec: `./src/cli/bin.js`, config }, (err, node) => { expect(err).to.not.exist() node.api.id((err, id) => { expect(err).to.not.exist() diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index 6ee4099fb0..c843ec1e0e 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -67,7 +67,15 @@ function connectNodes (remoteNode, inProcNode, callback) { let nodes = [] function addNode (inProcNode, callback) { - df.spawn({ type: 'js', exec: `./src/cli/bin.js` }, (err, ipfsd) => { + df.spawn({ + type: 'js', + exec: `./src/cli/bin.js`, + config: { + Addresses: { + Swarm: [`/ip4/127.0.0.1/tcp/0/ws`] + } + } + }, (err, ipfsd) => { expect(err).to.not.exist() nodes.push(ipfsd) connectNodes(ipfsd.api, inProcNode, (err) => callback(err, ipfsd.api)) @@ -82,8 +90,7 @@ describe('bitswap', function () { beforeEach(function (done) { this.timeout(60 * 1000) - let options = { - repo: createTempRepo(), + let config = { config: { Addresses: { Swarm: [] @@ -98,7 +105,7 @@ describe('bitswap', function () { } if (isNode) { - options = Object.assign(options, { + config = Object.assign(config, { config: { Addresses: { Swarm: ['/ip4/127.0.0.1/tcp/0'] @@ -107,18 +114,23 @@ describe('bitswap', function () { }) } - inProcNode = new IPFS(options) - inProcNode.on('ready', () => done()) + DaemonFactory + .create({ remote: false }) + .spawn({ type: 'proc', exec: IPFS, config }, (err, _ipfsd) => { + expect(err).to.not.exist() + nodes.push(_ipfsd) + inProcNode = _ipfsd.api + done() + }) }) afterEach(function (done) { this.timeout(80 * 1000) const tasks = nodes.map((node) => (cb) => node.stop(cb)) - tasks.push((cb) => setTimeout(() => inProcNode.stop(() => cb()), 500)) parallel(tasks, (err) => { expect(err).to.not.exist() nodes = [] - done(err) + done() }) }) diff --git a/test/core/bootstrap.spec.js b/test/core/bootstrap.spec.js index 3f291c5696..7e3433c7d4 100644 --- a/test/core/bootstrap.spec.js +++ b/test/core/bootstrap.spec.js @@ -7,42 +7,38 @@ const expect = chai.expect chai.use(dirtyChai) const isNode = require('detect-node') +const IPFS = require('../../src') -// This gets replaced by `create-repo-browser.js` in the browser -const createTempRepo = require('../utils/create-repo-nodejs.js') - -const IPFS = require('../../src/core') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ remote: false }) describe('bootstrap', () => { - if (!isNode) { return } + if (!isNode) { + return + } let node + let ipfsd before(function (done) { this.timeout(40 * 1000) - node = new IPFS({ - repo: createTempRepo(), - init: { - bits: 1024 - }, - EXPERIMENTAL: { - pubsub: true - }, + df.spawn({ + type: 'proc', + exec: IPFS, config: { Addresses: { Swarm: ['/ip4/127.0.0.1/tcp/0'] } } - }) - - node.on('error', (err) => { + }, (err, _ipfsd) => { expect(err).to.not.exist() + ipfsd = _ipfsd + node = _ipfsd.api + done() }) - - node.on('start', done) }) - after((done) => node.stop(done)) + after((done) => ipfsd.stop(done)) const defaultList = [ '/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ', diff --git a/test/core/files-sharding.spec.js b/test/core/files-sharding.spec.js index aaf97c8b64..32e779ad41 100644 --- a/test/core/files-sharding.spec.js +++ b/test/core/files-sharding.spec.js @@ -9,7 +9,9 @@ chai.use(dirtyChai) const pull = require('pull-stream') const IPFS = require('../../src/core') -const createTempRepo = require('../utils/create-repo-nodejs.js') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ remote: false }) describe('files directory (sharding tests)', () => { function createTestFiles () { @@ -27,12 +29,14 @@ describe('files directory (sharding tests)', () => { describe('without sharding', () => { let ipfs + let ipfsd before(function (done) { this.timeout(40 * 1000) - ipfs = new IPFS({ - repo: createTempRepo(), + df.spawn({ + type: 'proc', + exec: IPFS, config: { Addresses: { Swarm: [] @@ -44,13 +48,17 @@ describe('files directory (sharding tests)', () => { } } } + }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = _ipfsd.api + done() }) - ipfs.once('ready', done) }) after(function (done) { this.timeout(40 * 1000) - ipfs.stop(done) + ipfsd.stop(done) }) it('should be able to add dir without sharding', function (done) { @@ -72,12 +80,15 @@ describe('files directory (sharding tests)', () => { describe('with sharding', () => { let ipfs + let ipfsd before(function (done) { this.timeout(40 * 1000) - ipfs = new IPFS({ - repo: createTempRepo(), + df.spawn({ + type: 'proc', + exec: IPFS, + args: ['--enable-sharding-experiment'], config: { Addresses: { Swarm: [] @@ -88,17 +99,18 @@ describe('files directory (sharding tests)', () => { Enabled: false } } - }, - EXPERIMENTAL: { - sharding: true } + }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = _ipfsd.api + done() }) - ipfs.once('ready', done) }) after(function (done) { this.timeout(40 * 1000) - ipfs.stop(done) + ipfsd.stop(done) }) it('should be able to add dir with sharding', function (done) { diff --git a/test/core/kad-dht.node.js b/test/core/kad-dht.node.js index dc83973627..2c31898454 100644 --- a/test/core/kad-dht.node.js +++ b/test/core/kad-dht.node.js @@ -7,42 +7,26 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) const parallel = require('async/parallel') -const IPFS = require('../../src') -const createRepo = require('../utils/create-repo-nodejs') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() const config = { Addresses: { - Swarm: [`/ip4/127.0.0.1/tcp/0`], + Swarm: [`/ip4/127.0.0.1/tcp/0`, `/ip4/127.0.0.1/tcp/0/ws`], API: `/ip4/127.0.0.1/tcp/0`, Gateway: `/ip4/127.0.0.1/tcp/0` }, Bootstrap: [], Discovery: { MDNS: { - Enabled: - false + Enabled: false } } } function createNode (callback) { - const node = new IPFS({ - repo: createRepo(), - init: { bits: 1024 }, - EXPERIMENTAL: { - pubsub: true - }, - config - }) - - node.once('ready', () => { - callback(null, node) - }) - - node.once('error', (err) => { - callback(err) - }) + df.spawn({ type: 'js', exec: './src/cli/bin.js', config }, callback) } describe('verify that kad-dht is doing its thing', () => { @@ -62,9 +46,9 @@ describe('verify that kad-dht is doing its thing', () => { ], (err, _nodes) => { expect(err).to.not.exist() nodes = _nodes - nodeA = _nodes[0] - nodeB = _nodes[1] - nodeC = _nodes[2] + nodeA = _nodes[0].api + nodeB = _nodes[1].api + nodeC = _nodes[2].api parallel([ (cb) => nodeA.id(cb), (cb) => nodeB.id(cb), diff --git a/test/http-api/interface/block.js b/test/http-api/interface/block.js index e948b3c98f..3e899ca6c2 100644 --- a/test/http-api/interface/block.js +++ b/test/http-api/interface/block.js @@ -8,7 +8,7 @@ const df = DaemonFactory.create() const common = { setup: function (callback) { - callback(null, df) + callback(null, df, 'js', './src/cli/bin.js') } } From e9734ee3984845cf9312c02a9183e020d1ff4ef9 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 2 Jan 2018 11:29:43 -0600 Subject: [PATCH 04/12] tests: adjusting for ipfsd-ctl changes --- test/cli/pubsub.js | 6 ++---- test/cli/swarm.js | 6 +++--- test/core/bitswap.spec.js | 19 +++++++++---------- test/core/bootstrap.spec.js | 7 +++---- test/core/files-sharding.spec.js | 4 +--- test/core/interface/block.js | 4 ++-- test/core/interface/config.js | 4 ++-- test/core/interface/dag.js | 4 ++-- test/core/interface/dht.js | 4 ++-- test/core/interface/files.js | 4 ++-- test/core/interface/generic.js | 4 ++-- test/core/interface/object.js | 4 ++-- test/core/interface/pubsub.js | 4 ++-- test/core/interface/swarm.js | 4 ++-- test/core/kad-dht.node.js | 4 ++-- test/http-api/interface/block.js | 4 ++-- test/http-api/interface/config.js | 4 ++-- test/http-api/interface/files.js | 4 ++-- test/http-api/interface/object.js | 4 ++-- test/http-api/interface/pubsub.js | 4 ++-- test/http-api/interface/swarm.js | 4 ++-- test/utils/on-and-off.js | 4 ++-- 22 files changed, 52 insertions(+), 58 deletions(-) diff --git a/test/cli/pubsub.js b/test/cli/pubsub.js index e1ae1b800a..8bf14731fa 100644 --- a/test/cli/pubsub.js +++ b/test/cli/pubsub.js @@ -12,7 +12,7 @@ const ipfsExec = require('../utils/ipfs-exec') const IPFS = require('../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const config = { Bootstrap: [], @@ -41,9 +41,8 @@ describe('pubsub', function () { this.timeout(60 * 1000) DaemonFactory - .create({ remote: false }) + .create({ type: 'proc' }) .spawn({ - type: 'proc', exec: IPFS, config, args: ['--enable-pubsub-experiment'] @@ -59,7 +58,6 @@ describe('pubsub', function () { before((done) => { df.spawn({ - type: 'js', args: ['--enable-pubsub-experiment'], exec: `./src/cli/bin.js`, config diff --git a/test/cli/swarm.js b/test/cli/swarm.js index b514b2aa2c..424734c194 100644 --- a/test/cli/swarm.js +++ b/test/cli/swarm.js @@ -12,7 +12,7 @@ const ipfsExec = require('../utils/ipfs-exec') const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const config = { Bootstrap: [], @@ -36,7 +36,7 @@ describe('swarm', () => { series([ (cb) => { - df.spawn({ type: 'js', exec: `./src/cli/bin.js`, config }, (err, node) => { + df.spawn({ exec: `./src/cli/bin.js`, config }, (err, node) => { expect(err).to.not.exist() ipfsA = ipfsExec(node.repoPath) nodes.push(node) @@ -44,7 +44,7 @@ describe('swarm', () => { }) }, (cb) => { - df.spawn({ type: 'js', exec: `./src/cli/bin.js`, config }, (err, node) => { + df.spawn({ exec: `./src/cli/bin.js`, config }, (err, node) => { expect(err).to.not.exist() node.api.id((err, id) => { expect(err).to.not.exist() diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index c843ec1e0e..8996330088 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -17,7 +17,9 @@ const multihashing = require('multihashing-async') const CID = require('cids') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) + +const dfProc = DaemonFactory.create({ type: 'proc' }) // This gets replaced by '../utils/create-repo-browser.js' in the browser const createTempRepo = require('../utils/create-repo-nodejs.js') @@ -68,7 +70,6 @@ let nodes = [] function addNode (inProcNode, callback) { df.spawn({ - type: 'js', exec: `./src/cli/bin.js`, config: { Addresses: { @@ -114,14 +115,12 @@ describe('bitswap', function () { }) } - DaemonFactory - .create({ remote: false }) - .spawn({ type: 'proc', exec: IPFS, config }, (err, _ipfsd) => { - expect(err).to.not.exist() - nodes.push(_ipfsd) - inProcNode = _ipfsd.api - done() - }) + dfProc.spawn({ exec: IPFS, config }, (err, _ipfsd) => { + expect(err).to.not.exist() + nodes.push(_ipfsd) + inProcNode = _ipfsd.api + done() + }) }) afterEach(function (done) { diff --git a/test/core/bootstrap.spec.js b/test/core/bootstrap.spec.js index 7e3433c7d4..6abe498cf2 100644 --- a/test/core/bootstrap.spec.js +++ b/test/core/bootstrap.spec.js @@ -10,7 +10,7 @@ const isNode = require('detect-node') const IPFS = require('../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc' }) describe('bootstrap', () => { if (!isNode) { @@ -23,7 +23,6 @@ describe('bootstrap', () => { before(function (done) { this.timeout(40 * 1000) df.spawn({ - type: 'proc', exec: IPFS, config: { Addresses: { @@ -76,7 +75,7 @@ describe('bootstrap', () => { it('add a peer to the bootstrap list', (done) => { node.bootstrap.add('/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT', (err, res) => { expect(err).to.not.exist() - expect(res).to.be.eql({Peers: ['/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT']}) + expect(res).to.be.eql({ Peers: ['/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'] }) node.bootstrap.list((err, list) => { expect(err).to.not.exist() expect(list.Peers).to.deep.equal(updatedList) @@ -88,7 +87,7 @@ describe('bootstrap', () => { it('remove a peer from the bootstrap list', (done) => { node.bootstrap.rm('/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT', (err, res) => { expect(err).to.not.exist() - expect(res).to.be.eql({Peers: ['/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT']}) + expect(res).to.be.eql({ Peers: ['/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'] }) node.bootstrap.list((err, list) => { expect(err).to.not.exist() expect(list.Peers).to.deep.equal(defaultList) diff --git a/test/core/files-sharding.spec.js b/test/core/files-sharding.spec.js index 32e779ad41..156dbf4442 100644 --- a/test/core/files-sharding.spec.js +++ b/test/core/files-sharding.spec.js @@ -11,7 +11,7 @@ const pull = require('pull-stream') const IPFS = require('../../src/core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc' }) describe('files directory (sharding tests)', () => { function createTestFiles () { @@ -35,7 +35,6 @@ describe('files directory (sharding tests)', () => { this.timeout(40 * 1000) df.spawn({ - type: 'proc', exec: IPFS, config: { Addresses: { @@ -86,7 +85,6 @@ describe('files directory (sharding tests)', () => { this.timeout(40 * 1000) df.spawn({ - type: 'proc', exec: IPFS, args: ['--enable-sharding-experiment'], config: { diff --git a/test/core/interface/block.js b/test/core/interface/block.js index 70526983cf..4cd6bd6036 100644 --- a/test/core/interface/block.js +++ b/test/core/interface/block.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc' }) const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, df, IPFS) } } diff --git a/test/core/interface/config.js b/test/core/interface/config.js index 9902b5bff5..28b6fa0600 100644 --- a/test/core/interface/config.js +++ b/test/core/interface/config.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc' }) const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, df, IPFS) } } test.config(common) diff --git a/test/core/interface/dag.js b/test/core/interface/dag.js index bc77df29dd..923e797a4e 100644 --- a/test/core/interface/dag.js +++ b/test/core/interface/dag.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc' }) const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, df, IPFS) } } diff --git a/test/core/interface/dht.js b/test/core/interface/dht.js index 848093054f..c45aa0dd9a 100644 --- a/test/core/interface/dht.js +++ b/test/core/interface/dht.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'proc'}) const common = { setup: function (callback) { - callback(null, df) + callback(null, df, IPFS) } } diff --git a/test/core/interface/files.js b/test/core/interface/files.js index c29be5b2b4..8f0ae7b2d1 100644 --- a/test/core/interface/files.js +++ b/test/core/interface/files.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc' }) const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, df, IPFS) } } diff --git a/test/core/interface/generic.js b/test/core/interface/generic.js index 5908219f13..a396b2375c 100644 --- a/test/core/interface/generic.js +++ b/test/core/interface/generic.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc' }) const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, df, IPFS) } } test.generic(common) diff --git a/test/core/interface/object.js b/test/core/interface/object.js index a5ce52107b..d4391c15ff 100644 --- a/test/core/interface/object.js +++ b/test/core/interface/object.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc' }) const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, df, IPFS) } } diff --git a/test/core/interface/pubsub.js b/test/core/interface/pubsub.js index dd9905075a..93e2588c14 100644 --- a/test/core/interface/pubsub.js +++ b/test/core/interface/pubsub.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc' }) const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, df, IPFS) } } diff --git a/test/core/interface/swarm.js b/test/core/interface/swarm.js index 5f84c93c7a..9fe46d83c5 100644 --- a/test/core/interface/swarm.js +++ b/test/core/interface/swarm.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc' }) const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, df, IPFS) } } diff --git a/test/core/kad-dht.node.js b/test/core/kad-dht.node.js index 2c31898454..db91cdc168 100644 --- a/test/core/kad-dht.node.js +++ b/test/core/kad-dht.node.js @@ -9,7 +9,7 @@ chai.use(dirtyChai) const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const config = { Addresses: { @@ -26,7 +26,7 @@ const config = { } function createNode (callback) { - df.spawn({ type: 'js', exec: './src/cli/bin.js', config }, callback) + df.spawn({ exec: './src/cli/bin.js', config }, callback) } describe('verify that kad-dht is doing its thing', () => { diff --git a/test/http-api/interface/block.js b/test/http-api/interface/block.js index 3e899ca6c2..09ce521f08 100644 --- a/test/http-api/interface/block.js +++ b/test/http-api/interface/block.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, df, './src/cli/bin.js') } } diff --git a/test/http-api/interface/config.js b/test/http-api/interface/config.js index 389b6d9c47..a631a38556 100644 --- a/test/http-api/interface/config.js +++ b/test/http-api/interface/config.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, df, './src/cli/bin.js') } } diff --git a/test/http-api/interface/files.js b/test/http-api/interface/files.js index 5bb317771d..a3866f610e 100644 --- a/test/http-api/interface/files.js +++ b/test/http-api/interface/files.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, df, './src/cli/bin.js') } } diff --git a/test/http-api/interface/object.js b/test/http-api/interface/object.js index 725602faff..8b914f7494 100644 --- a/test/http-api/interface/object.js +++ b/test/http-api/interface/object.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, df, './src/cli/bin.js') } } diff --git a/test/http-api/interface/pubsub.js b/test/http-api/interface/pubsub.js index 05d1010349..94eae94b92 100644 --- a/test/http-api/interface/pubsub.js +++ b/test/http-api/interface/pubsub.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, df, './src/cli/bin.js') } } diff --git a/test/http-api/interface/swarm.js b/test/http-api/interface/swarm.js index 74e862013f..e6483a2f98 100644 --- a/test/http-api/interface/swarm.js +++ b/test/http-api/interface/swarm.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, df, './src/cli/bin.js') } } diff --git a/test/utils/on-and-off.js b/test/utils/on-and-off.js index 4aa6344eeb..9fc4327c5c 100644 --- a/test/utils/on-and-off.js +++ b/test/utils/on-and-off.js @@ -12,7 +12,7 @@ const clean = require('../utils/clean') const os = require('os') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) function off (tests) { describe('daemon off (directly to core)', () => { @@ -49,7 +49,7 @@ function on (tests) { // before step this.timeout(60 * 1000) - df.spawn({ type: 'js', exec: `./src/cli/bin.js` }, (err, node) => { + df.spawn({ exec: `./src/cli/bin.js` }, (err, node) => { expect(err).to.not.exist() ipfsd = node thing.ipfs = ipfsExec(node.repoPath) From b4ad412c0576ec0e60ac9acae6b402963901cd74 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 22 Dec 2017 19:27:38 -0600 Subject: [PATCH 05/12] feat: reworking tests with new ipfsd-ctl --- test/cli/pubsub.js | 56 ++++++++++++++++++------------- test/cli/swarm.js | 6 ++-- test/core/bitswap.spec.js | 29 +++++----------- test/core/interface/block.js | 4 +-- test/core/interface/config.js | 4 +-- test/core/interface/dag.js | 4 +-- test/core/interface/dht.js | 4 +-- test/core/interface/files.js | 4 +-- test/core/interface/generic.js | 4 +-- test/core/interface/object.js | 4 +-- test/core/interface/pubsub.js | 4 +-- test/core/interface/swarm.js | 4 +-- test/core/kad-dht.node.js | 32 +++++++++++++----- test/http-api/interface/block.js | 4 +-- test/http-api/interface/config.js | 4 +-- test/http-api/interface/files.js | 4 +-- test/http-api/interface/object.js | 4 +-- test/http-api/interface/pubsub.js | 4 +-- test/http-api/interface/swarm.js | 4 +-- test/utils/on-and-off.js | 4 +-- 20 files changed, 101 insertions(+), 86 deletions(-) diff --git a/test/cli/pubsub.js b/test/cli/pubsub.js index 8bf14731fa..efca7a31b4 100644 --- a/test/cli/pubsub.js +++ b/test/cli/pubsub.js @@ -9,10 +9,11 @@ chai.use(dirtyChai) const delay = require('delay') const series = require('async/series') const ipfsExec = require('../utils/ipfs-exec') +const createRepo = require('../utils/create-repo-nodejs') const IPFS = require('../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) +const df = DaemonFactory.create() const config = { Bootstrap: [], @@ -28,8 +29,7 @@ describe('pubsub', function () { this.timeout(80 * 1000) let node - let ipfsdA - let ipfsdB + let ipfsd let cli let httpApi @@ -37,41 +37,51 @@ describe('pubsub', function () { const topicB = 'nonscentsB' const topicC = 'nonscentsC' + let repo = createRepo() before(function (done) { this.timeout(60 * 1000) - DaemonFactory - .create({ type: 'proc' }) - .spawn({ - exec: IPFS, - config, - args: ['--enable-pubsub-experiment'] - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsdA = _ipfsd - node = _ipfsd.api - done() - }) + node = new IPFS({ + repo: createRepo(), + init: { bits: 1024 }, + EXPERIMENTAL: { + pubsub: true + }, + config + }) + + node.once('ready', () => { + done() + }) + + node.once('error', (err) => { + done(err) + }) }) - after((done) => ipfsdB.stop(done)) + after((done) => { + node.stop((err) => { + expect(err).to.not.exist() + repo.teardown(done) + }) + }) before((done) => { df.spawn({ + type: 'js', args: ['--enable-pubsub-experiment'], - exec: `./src/cli/bin.js`, + exec: `${process.cwd()}/src/cli/bin.js`, config - }, (err, _ipfsd) => { + }, (err, _node) => { expect(err).to.not.exist() - httpApi = _ipfsd.api - ipfsdB = _ipfsd - httpApi.repoPath = ipfsdB.repoPath + httpApi = _node.api + ipfsd = _node + httpApi.repoPath = ipfsd.repoPath done() }) }) - after((done) => ipfsdA.stop(done)) - after((done) => ipfsdB.stop(done)) + after((done) => ipfsd.stop(done)) before((done) => { cli = ipfsExec(httpApi.repoPath) diff --git a/test/cli/swarm.js b/test/cli/swarm.js index 424734c194..1f67424747 100644 --- a/test/cli/swarm.js +++ b/test/cli/swarm.js @@ -12,7 +12,7 @@ const ipfsExec = require('../utils/ipfs-exec') const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) +const df = DaemonFactory.create() const config = { Bootstrap: [], @@ -36,7 +36,7 @@ describe('swarm', () => { series([ (cb) => { - df.spawn({ exec: `./src/cli/bin.js`, config }, (err, node) => { + df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => { expect(err).to.not.exist() ipfsA = ipfsExec(node.repoPath) nodes.push(node) @@ -44,7 +44,7 @@ describe('swarm', () => { }) }, (cb) => { - df.spawn({ exec: `./src/cli/bin.js`, config }, (err, node) => { + df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => { expect(err).to.not.exist() node.api.id((err, id) => { expect(err).to.not.exist() diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index 8996330088..6ee4099fb0 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -17,9 +17,7 @@ const multihashing = require('multihashing-async') const CID = require('cids') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) - -const dfProc = DaemonFactory.create({ type: 'proc' }) +const df = DaemonFactory.create() // This gets replaced by '../utils/create-repo-browser.js' in the browser const createTempRepo = require('../utils/create-repo-nodejs.js') @@ -69,14 +67,7 @@ function connectNodes (remoteNode, inProcNode, callback) { let nodes = [] function addNode (inProcNode, callback) { - df.spawn({ - exec: `./src/cli/bin.js`, - config: { - Addresses: { - Swarm: [`/ip4/127.0.0.1/tcp/0/ws`] - } - } - }, (err, ipfsd) => { + df.spawn({ type: 'js', exec: `./src/cli/bin.js` }, (err, ipfsd) => { expect(err).to.not.exist() nodes.push(ipfsd) connectNodes(ipfsd.api, inProcNode, (err) => callback(err, ipfsd.api)) @@ -91,7 +82,8 @@ describe('bitswap', function () { beforeEach(function (done) { this.timeout(60 * 1000) - let config = { + let options = { + repo: createTempRepo(), config: { Addresses: { Swarm: [] @@ -106,7 +98,7 @@ describe('bitswap', function () { } if (isNode) { - config = Object.assign(config, { + options = Object.assign(options, { config: { Addresses: { Swarm: ['/ip4/127.0.0.1/tcp/0'] @@ -115,21 +107,18 @@ describe('bitswap', function () { }) } - dfProc.spawn({ exec: IPFS, config }, (err, _ipfsd) => { - expect(err).to.not.exist() - nodes.push(_ipfsd) - inProcNode = _ipfsd.api - done() - }) + inProcNode = new IPFS(options) + inProcNode.on('ready', () => done()) }) afterEach(function (done) { this.timeout(80 * 1000) const tasks = nodes.map((node) => (cb) => node.stop(cb)) + tasks.push((cb) => setTimeout(() => inProcNode.stop(() => cb()), 500)) parallel(tasks, (err) => { expect(err).to.not.exist() nodes = [] - done() + done(err) }) }) diff --git a/test/core/interface/block.js b/test/core/interface/block.js index 4cd6bd6036..70526983cf 100644 --- a/test/core/interface/block.js +++ b/test/core/interface/block.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc' }) +const df = DaemonFactory.create({ remote: false }) const common = { setup: function (callback) { - callback(null, df, IPFS) + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/interface/config.js b/test/core/interface/config.js index 28b6fa0600..9902b5bff5 100644 --- a/test/core/interface/config.js +++ b/test/core/interface/config.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc' }) +const df = DaemonFactory.create({ remote: false }) const common = { setup: function (callback) { - callback(null, df, IPFS) + callback(null, df, 'proc', IPFS) } } test.config(common) diff --git a/test/core/interface/dag.js b/test/core/interface/dag.js index 923e797a4e..bc77df29dd 100644 --- a/test/core/interface/dag.js +++ b/test/core/interface/dag.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc' }) +const df = DaemonFactory.create({ remote: false }) const common = { setup: function (callback) { - callback(null, df, IPFS) + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/interface/dht.js b/test/core/interface/dht.js index c45aa0dd9a..848093054f 100644 --- a/test/core/interface/dht.js +++ b/test/core/interface/dht.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc'}) +const df = DaemonFactory.create() const common = { setup: function (callback) { - callback(null, df, IPFS) + callback(null, df) } } diff --git a/test/core/interface/files.js b/test/core/interface/files.js index 8f0ae7b2d1..c29be5b2b4 100644 --- a/test/core/interface/files.js +++ b/test/core/interface/files.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc' }) +const df = DaemonFactory.create({ remote: false }) const common = { setup: function (callback) { - callback(null, df, IPFS) + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/interface/generic.js b/test/core/interface/generic.js index a396b2375c..5908219f13 100644 --- a/test/core/interface/generic.js +++ b/test/core/interface/generic.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc' }) +const df = DaemonFactory.create({ remote: false }) const common = { setup: function (callback) { - callback(null, df, IPFS) + callback(null, df, 'proc', IPFS) } } test.generic(common) diff --git a/test/core/interface/object.js b/test/core/interface/object.js index d4391c15ff..a5ce52107b 100644 --- a/test/core/interface/object.js +++ b/test/core/interface/object.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc' }) +const df = DaemonFactory.create({ remote: false }) const common = { setup: function (callback) { - callback(null, df, IPFS) + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/interface/pubsub.js b/test/core/interface/pubsub.js index 93e2588c14..dd9905075a 100644 --- a/test/core/interface/pubsub.js +++ b/test/core/interface/pubsub.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc' }) +const df = DaemonFactory.create({ remote: false }) const common = { setup: function (callback) { - callback(null, df, IPFS) + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/interface/swarm.js b/test/core/interface/swarm.js index 9fe46d83c5..5f84c93c7a 100644 --- a/test/core/interface/swarm.js +++ b/test/core/interface/swarm.js @@ -5,11 +5,11 @@ const test = require('interface-ipfs-core') const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'proc' }) +const df = DaemonFactory.create({ remote: false }) const common = { setup: function (callback) { - callback(null, df, IPFS) + callback(null, df, 'proc', IPFS) } } diff --git a/test/core/kad-dht.node.js b/test/core/kad-dht.node.js index db91cdc168..dc83973627 100644 --- a/test/core/kad-dht.node.js +++ b/test/core/kad-dht.node.js @@ -7,26 +7,42 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) const parallel = require('async/parallel') +const IPFS = require('../../src') -const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) +const createRepo = require('../utils/create-repo-nodejs') const config = { Addresses: { - Swarm: [`/ip4/127.0.0.1/tcp/0`, `/ip4/127.0.0.1/tcp/0/ws`], + Swarm: [`/ip4/127.0.0.1/tcp/0`], API: `/ip4/127.0.0.1/tcp/0`, Gateway: `/ip4/127.0.0.1/tcp/0` }, Bootstrap: [], Discovery: { MDNS: { - Enabled: false + Enabled: + false } } } function createNode (callback) { - df.spawn({ exec: './src/cli/bin.js', config }, callback) + const node = new IPFS({ + repo: createRepo(), + init: { bits: 1024 }, + EXPERIMENTAL: { + pubsub: true + }, + config + }) + + node.once('ready', () => { + callback(null, node) + }) + + node.once('error', (err) => { + callback(err) + }) } describe('verify that kad-dht is doing its thing', () => { @@ -46,9 +62,9 @@ describe('verify that kad-dht is doing its thing', () => { ], (err, _nodes) => { expect(err).to.not.exist() nodes = _nodes - nodeA = _nodes[0].api - nodeB = _nodes[1].api - nodeC = _nodes[2].api + nodeA = _nodes[0] + nodeB = _nodes[1] + nodeC = _nodes[2] parallel([ (cb) => nodeA.id(cb), (cb) => nodeB.id(cb), diff --git a/test/http-api/interface/block.js b/test/http-api/interface/block.js index 09ce521f08..e948b3c98f 100644 --- a/test/http-api/interface/block.js +++ b/test/http-api/interface/block.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) +const df = DaemonFactory.create() const common = { setup: function (callback) { - callback(null, df, './src/cli/bin.js') + callback(null, df) } } diff --git a/test/http-api/interface/config.js b/test/http-api/interface/config.js index a631a38556..389b6d9c47 100644 --- a/test/http-api/interface/config.js +++ b/test/http-api/interface/config.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) +const df = DaemonFactory.create() const common = { setup: function (callback) { - callback(null, df, './src/cli/bin.js') + callback(null, df, 'js', './src/cli/bin.js') } } diff --git a/test/http-api/interface/files.js b/test/http-api/interface/files.js index a3866f610e..5bb317771d 100644 --- a/test/http-api/interface/files.js +++ b/test/http-api/interface/files.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) +const df = DaemonFactory.create() const common = { setup: function (callback) { - callback(null, df, './src/cli/bin.js') + callback(null, df, 'js', './src/cli/bin.js') } } diff --git a/test/http-api/interface/object.js b/test/http-api/interface/object.js index 8b914f7494..725602faff 100644 --- a/test/http-api/interface/object.js +++ b/test/http-api/interface/object.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) +const df = DaemonFactory.create() const common = { setup: function (callback) { - callback(null, df, './src/cli/bin.js') + callback(null, df, 'js', './src/cli/bin.js') } } diff --git a/test/http-api/interface/pubsub.js b/test/http-api/interface/pubsub.js index 94eae94b92..05d1010349 100644 --- a/test/http-api/interface/pubsub.js +++ b/test/http-api/interface/pubsub.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) +const df = DaemonFactory.create() const common = { setup: function (callback) { - callback(null, df, './src/cli/bin.js') + callback(null, df, 'js', './src/cli/bin.js') } } diff --git a/test/http-api/interface/swarm.js b/test/http-api/interface/swarm.js index e6483a2f98..74e862013f 100644 --- a/test/http-api/interface/swarm.js +++ b/test/http-api/interface/swarm.js @@ -4,11 +4,11 @@ const test = require('interface-ipfs-core') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) +const df = DaemonFactory.create() const common = { setup: function (callback) { - callback(null, df, './src/cli/bin.js') + callback(null, df, 'js', './src/cli/bin.js') } } diff --git a/test/utils/on-and-off.js b/test/utils/on-and-off.js index 9fc4327c5c..4aa6344eeb 100644 --- a/test/utils/on-and-off.js +++ b/test/utils/on-and-off.js @@ -12,7 +12,7 @@ const clean = require('../utils/clean') const os = require('os') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) +const df = DaemonFactory.create() function off (tests) { describe('daemon off (directly to core)', () => { @@ -49,7 +49,7 @@ function on (tests) { // before step this.timeout(60 * 1000) - df.spawn({ exec: `./src/cli/bin.js` }, (err, node) => { + df.spawn({ type: 'js', exec: `./src/cli/bin.js` }, (err, node) => { expect(err).to.not.exist() ipfsd = node thing.ipfs = ipfsExec(node.repoPath) From 26114ef7b4a08d3672fb1ebb19fdaa380ee77ebe Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 9 Jan 2018 22:59:58 -0600 Subject: [PATCH 06/12] fix: bitswap tests --- test/core/bitswap.spec.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index 6ee4099fb0..8ed002771a 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -16,14 +16,16 @@ const isNode = require('detect-node') const multihashing = require('multihashing-async') const CID = require('cids') +const IPFS = require('../../src/core') + const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js', exec: `./src/cli/bin.js` }) + +const dfProc = DaemonFactory.create({ type: 'proc', exec: IPFS }) // This gets replaced by '../utils/create-repo-browser.js' in the browser const createTempRepo = require('../utils/create-repo-nodejs.js') -const IPFS = require('../../src/core') - function makeBlock (callback) { const d = Buffer.from(`IPFS is awesome ${Math.random()}`) @@ -67,7 +69,13 @@ function connectNodes (remoteNode, inProcNode, callback) { let nodes = [] function addNode (inProcNode, callback) { - df.spawn({ type: 'js', exec: `./src/cli/bin.js` }, (err, ipfsd) => { + df.spawn({ + config: { + Addresses: { + Swarm: [`/ip4/127.0.0.1/tcp/0/ws`] + } + } + }, (err, ipfsd) => { expect(err).to.not.exist() nodes.push(ipfsd) connectNodes(ipfsd.api, inProcNode, (err) => callback(err, ipfsd.api)) @@ -82,8 +90,7 @@ describe('bitswap', function () { beforeEach(function (done) { this.timeout(60 * 1000) - let options = { - repo: createTempRepo(), + let config = { config: { Addresses: { Swarm: [] @@ -98,7 +105,7 @@ describe('bitswap', function () { } if (isNode) { - options = Object.assign(options, { + config = Object.assign(config, { config: { Addresses: { Swarm: ['/ip4/127.0.0.1/tcp/0'] @@ -107,18 +114,21 @@ describe('bitswap', function () { }) } - inProcNode = new IPFS(options) - inProcNode.on('ready', () => done()) + dfProc.spawn({ config }, (err, _ipfsd) => { + expect(err).to.not.exist() + nodes.push(_ipfsd) + inProcNode = _ipfsd.api + done() + }) }) afterEach(function (done) { this.timeout(80 * 1000) const tasks = nodes.map((node) => (cb) => node.stop(cb)) - tasks.push((cb) => setTimeout(() => inProcNode.stop(() => cb()), 500)) parallel(tasks, (err) => { expect(err).to.not.exist() nodes = [] - done(err) + done() }) }) From 8e63934785ed8cf6799b0afba04dd6a1ca9bb21e Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 16 Jan 2018 09:40:35 -0600 Subject: [PATCH 07/12] chore: upping ipfsd-ctl version --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 3a15589f46..3ec9b7579b 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "go-ipfs-dep": "^0.4.13", "hat": "0.0.3", "interface-ipfs-core": "~0.40.0", + "ipfsd-ctl": "^0.27.0", "left-pad": "^1.2.0", "lodash": "^4.17.4", "mocha": "^4.1.0", From fca231454b5e2ef1cda9276fb774b56eec0b7a0f Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 18 Jan 2018 16:38:22 -0800 Subject: [PATCH 08/12] chore: bump interface-ipfs-core --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ec9b7579b..31a2bdb0d2 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "form-data": "^2.3.1", "go-ipfs-dep": "^0.4.13", "hat": "0.0.3", - "interface-ipfs-core": "~0.40.0", + "interface-ipfs-core": "~0.41.0", "ipfsd-ctl": "^0.27.0", "left-pad": "^1.2.0", "lodash": "^4.17.4", From 3c951bf9f30e75a82ae13ce1aaf07d81e3d2c3f5 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 19 Jan 2018 00:29:00 -0600 Subject: [PATCH 09/12] feat: rework interface tests --- test/core/interface/block.js | 21 +++++++++++++++++++-- test/core/interface/config.js | 22 ++++++++++++++++++++-- test/core/interface/dag.js | 21 +++++++++++++++++++-- test/core/interface/dht.js | 21 ++++++++++++++++++--- test/core/interface/files.js | 21 +++++++++++++++++++-- test/core/interface/generic.js | 22 ++++++++++++++++++++-- test/core/interface/object.js | 21 +++++++++++++++++++-- test/core/interface/pubsub.js | 22 ++++++++++++++++++++-- test/core/interface/swarm.js | 31 +++++++++++++++++++++++++++++-- test/http-api/interface/block.js | 20 ++++++++++++++++++-- test/http-api/interface/config.js | 20 ++++++++++++++++++-- test/http-api/interface/files.js | 20 ++++++++++++++++++-- test/http-api/interface/object.js | 20 ++++++++++++++++++-- test/http-api/interface/pubsub.js | 21 +++++++++++++++++++-- test/http-api/interface/swarm.js | 30 ++++++++++++++++++++++++++++-- 15 files changed, 302 insertions(+), 31 deletions(-) diff --git a/test/core/interface/block.js b/test/core/interface/block.js index 70526983cf..5246ce3734 100644 --- a/test/core/interface/block.js +++ b/test/core/interface/block.js @@ -2,14 +2,31 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/core/interface/config.js b/test/core/interface/config.js index 9902b5bff5..1408e2281f 100644 --- a/test/core/interface/config.js +++ b/test/core/interface/config.js @@ -2,14 +2,32 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } + test.config(common) diff --git a/test/core/interface/dag.js b/test/core/interface/dag.js index bc77df29dd..4e384cb105 100644 --- a/test/core/interface/dag.js +++ b/test/core/interface/dag.js @@ -2,14 +2,31 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/core/interface/dht.js b/test/core/interface/dht.js index 848093054f..532f3f4829 100644 --- a/test/core/interface/dht.js +++ b/test/core/interface/dht.js @@ -3,15 +3,30 @@ /* const test = require('interface-ipfs-core') +const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } - test.dht(common) */ diff --git a/test/core/interface/files.js b/test/core/interface/files.js index c29be5b2b4..29fc97c530 100644 --- a/test/core/interface/files.js +++ b/test/core/interface/files.js @@ -2,14 +2,31 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/core/interface/generic.js b/test/core/interface/generic.js index 5908219f13..9af526e58b 100644 --- a/test/core/interface/generic.js +++ b/test/core/interface/generic.js @@ -2,14 +2,32 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } + test.generic(common) diff --git a/test/core/interface/object.js b/test/core/interface/object.js index a5ce52107b..32ef8e0251 100644 --- a/test/core/interface/object.js +++ b/test/core/interface/object.js @@ -2,14 +2,31 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/core/interface/pubsub.js b/test/core/interface/pubsub.js index dd9905075a..2425f862d9 100644 --- a/test/core/interface/pubsub.js +++ b/test/core/interface/pubsub.js @@ -2,14 +2,32 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, { + spawnNode: (cb) => { + df.spawn({ args: ['--enable-pubsub-experiment'] }, + (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/core/interface/swarm.js b/test/core/interface/swarm.js index 5f84c93c7a..d5158701d8 100644 --- a/test/core/interface/swarm.js +++ b/test/core/interface/swarm.js @@ -2,14 +2,41 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + const IPFS = require('../../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ remote: false }) +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'proc', IPFS) + callback(null, { + spawnNode: (repoPath, config, cb) => { + if (typeof repoPath === 'function') { + cb = repoPath + repoPath = undefined + } + + if (typeof config === 'function') { + cb = config + config = undefined + } + + df.spawn({ repoPath, config }, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/http-api/interface/block.js b/test/http-api/interface/block.js index e948b3c98f..9b5af8aa1a 100644 --- a/test/http-api/interface/block.js +++ b/test/http-api/interface/block.js @@ -2,13 +2,29 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df) + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/http-api/interface/config.js b/test/http-api/interface/config.js index 389b6d9c47..2dc5e28c9f 100644 --- a/test/http-api/interface/config.js +++ b/test/http-api/interface/config.js @@ -2,13 +2,29 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/http-api/interface/files.js b/test/http-api/interface/files.js index 5bb317771d..8b67070415 100644 --- a/test/http-api/interface/files.js +++ b/test/http-api/interface/files.js @@ -2,13 +2,29 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/http-api/interface/object.js b/test/http-api/interface/object.js index 725602faff..5db1e53f97 100644 --- a/test/http-api/interface/object.js +++ b/test/http-api/interface/object.js @@ -2,13 +2,29 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/http-api/interface/pubsub.js b/test/http-api/interface/pubsub.js index 05d1010349..b058c1a63c 100644 --- a/test/http-api/interface/pubsub.js +++ b/test/http-api/interface/pubsub.js @@ -2,13 +2,30 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, { + spawnNode: (cb) => { + df.spawn({ args: ['--enable-pubsub-experiment'] }, + (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } diff --git a/test/http-api/interface/swarm.js b/test/http-api/interface/swarm.js index 74e862013f..e2a9b657c7 100644 --- a/test/http-api/interface/swarm.js +++ b/test/http-api/interface/swarm.js @@ -2,13 +2,39 @@ 'use strict' const test = require('interface-ipfs-core') +const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) +const nodes = [] const common = { setup: function (callback) { - callback(null, df, 'js', './src/cli/bin.js') + callback(null, { + spawnNode: (repoPath, config, cb) => { + if (typeof repoPath === 'function') { + cb = repoPath + repoPath = undefined + } + + if (typeof config === 'function') { + cb = config + config = undefined + } + + df.spawn({ repoPath, config }, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) } } From 54d40550d51fc4cf6bffcc4e97982fb32ef45e03 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 19 Jan 2018 21:53:25 -0600 Subject: [PATCH 10/12] chore: add webworker task --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 31a2bdb0d2..c1d688a974 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "test": "aegir test -t node -t browser -t webworker --no-cors", "test:node": "aegir test -t node", "test:browser": "aegir test -t browser --no-cors", + "test:webworker": "aegir test -t webworker --no-cors", "test:node:core": "aegir test -t node -f test/core/**.js", "test:node:http": "aegir test -t node -f test/http-api/index.js", "test:node:gateway": "aegir test -t node -f test/gateway/index.js", From ceafe3e6c6b7947e8a8558753d72d2629f4dc26b Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 23 Jan 2018 17:37:23 -0600 Subject: [PATCH 11/12] fix: bring back reverted changes --- test/cli/pubsub.js | 56 ++++++++++++++++----------------------- test/cli/swarm.js | 6 ++--- test/core/bitswap.spec.js | 11 ++++---- test/core/kad-dht.node.js | 32 ++++++---------------- 4 files changed, 40 insertions(+), 65 deletions(-) diff --git a/test/cli/pubsub.js b/test/cli/pubsub.js index efca7a31b4..8bf14731fa 100644 --- a/test/cli/pubsub.js +++ b/test/cli/pubsub.js @@ -9,11 +9,10 @@ chai.use(dirtyChai) const delay = require('delay') const series = require('async/series') const ipfsExec = require('../utils/ipfs-exec') -const createRepo = require('../utils/create-repo-nodejs') const IPFS = require('../../src') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const config = { Bootstrap: [], @@ -29,7 +28,8 @@ describe('pubsub', function () { this.timeout(80 * 1000) let node - let ipfsd + let ipfsdA + let ipfsdB let cli let httpApi @@ -37,51 +37,41 @@ describe('pubsub', function () { const topicB = 'nonscentsB' const topicC = 'nonscentsC' - let repo = createRepo() before(function (done) { this.timeout(60 * 1000) - node = new IPFS({ - repo: createRepo(), - init: { bits: 1024 }, - EXPERIMENTAL: { - pubsub: true - }, - config - }) - - node.once('ready', () => { - done() - }) - - node.once('error', (err) => { - done(err) - }) + DaemonFactory + .create({ type: 'proc' }) + .spawn({ + exec: IPFS, + config, + args: ['--enable-pubsub-experiment'] + }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsdA = _ipfsd + node = _ipfsd.api + done() + }) }) - after((done) => { - node.stop((err) => { - expect(err).to.not.exist() - repo.teardown(done) - }) - }) + after((done) => ipfsdB.stop(done)) before((done) => { df.spawn({ - type: 'js', args: ['--enable-pubsub-experiment'], - exec: `${process.cwd()}/src/cli/bin.js`, + exec: `./src/cli/bin.js`, config - }, (err, _node) => { + }, (err, _ipfsd) => { expect(err).to.not.exist() - httpApi = _node.api - ipfsd = _node - httpApi.repoPath = ipfsd.repoPath + httpApi = _ipfsd.api + ipfsdB = _ipfsd + httpApi.repoPath = ipfsdB.repoPath done() }) }) - after((done) => ipfsd.stop(done)) + after((done) => ipfsdA.stop(done)) + after((done) => ipfsdB.stop(done)) before((done) => { cli = ipfsExec(httpApi.repoPath) diff --git a/test/cli/swarm.js b/test/cli/swarm.js index 1f67424747..424734c194 100644 --- a/test/cli/swarm.js +++ b/test/cli/swarm.js @@ -12,7 +12,7 @@ const ipfsExec = require('../utils/ipfs-exec') const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const df = DaemonFactory.create({ type: 'js' }) const config = { Bootstrap: [], @@ -36,7 +36,7 @@ describe('swarm', () => { series([ (cb) => { - df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => { + df.spawn({ exec: `./src/cli/bin.js`, config }, (err, node) => { expect(err).to.not.exist() ipfsA = ipfsExec(node.repoPath) nodes.push(node) @@ -44,7 +44,7 @@ describe('swarm', () => { }) }, (cb) => { - df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => { + df.spawn({ exec: `./src/cli/bin.js`, config }, (err, node) => { expect(err).to.not.exist() node.api.id((err, id) => { expect(err).to.not.exist() diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index 8ed002771a..8996330088 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -16,16 +16,16 @@ const isNode = require('detect-node') const multihashing = require('multihashing-async') const CID = require('cids') -const IPFS = require('../../src/core') - const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js', exec: `./src/cli/bin.js` }) +const df = DaemonFactory.create({ type: 'js' }) -const dfProc = DaemonFactory.create({ type: 'proc', exec: IPFS }) +const dfProc = DaemonFactory.create({ type: 'proc' }) // This gets replaced by '../utils/create-repo-browser.js' in the browser const createTempRepo = require('../utils/create-repo-nodejs.js') +const IPFS = require('../../src/core') + function makeBlock (callback) { const d = Buffer.from(`IPFS is awesome ${Math.random()}`) @@ -70,6 +70,7 @@ let nodes = [] function addNode (inProcNode, callback) { df.spawn({ + exec: `./src/cli/bin.js`, config: { Addresses: { Swarm: [`/ip4/127.0.0.1/tcp/0/ws`] @@ -114,7 +115,7 @@ describe('bitswap', function () { }) } - dfProc.spawn({ config }, (err, _ipfsd) => { + dfProc.spawn({ exec: IPFS, config }, (err, _ipfsd) => { expect(err).to.not.exist() nodes.push(_ipfsd) inProcNode = _ipfsd.api diff --git a/test/core/kad-dht.node.js b/test/core/kad-dht.node.js index dc83973627..db91cdc168 100644 --- a/test/core/kad-dht.node.js +++ b/test/core/kad-dht.node.js @@ -7,42 +7,26 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) const parallel = require('async/parallel') -const IPFS = require('../../src') -const createRepo = require('../utils/create-repo-nodejs') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ type: 'js' }) const config = { Addresses: { - Swarm: [`/ip4/127.0.0.1/tcp/0`], + Swarm: [`/ip4/127.0.0.1/tcp/0`, `/ip4/127.0.0.1/tcp/0/ws`], API: `/ip4/127.0.0.1/tcp/0`, Gateway: `/ip4/127.0.0.1/tcp/0` }, Bootstrap: [], Discovery: { MDNS: { - Enabled: - false + Enabled: false } } } function createNode (callback) { - const node = new IPFS({ - repo: createRepo(), - init: { bits: 1024 }, - EXPERIMENTAL: { - pubsub: true - }, - config - }) - - node.once('ready', () => { - callback(null, node) - }) - - node.once('error', (err) => { - callback(err) - }) + df.spawn({ exec: './src/cli/bin.js', config }, callback) } describe('verify that kad-dht is doing its thing', () => { @@ -62,9 +46,9 @@ describe('verify that kad-dht is doing its thing', () => { ], (err, _nodes) => { expect(err).to.not.exist() nodes = _nodes - nodeA = _nodes[0] - nodeB = _nodes[1] - nodeC = _nodes[2] + nodeA = _nodes[0].api + nodeB = _nodes[1].api + nodeC = _nodes[2].api parallel([ (cb) => nodeA.id(cb), (cb) => nodeB.id(cb), From 084c12eee2c92180ec110684d5d057b5d35f4330 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 24 Jan 2018 03:26:26 -0600 Subject: [PATCH 12/12] fix: libp2p uninitialized error --- .aegir.js | 1 + test/core/bitswap.spec.js | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.aegir.js b/.aegir.js index 58b0db3159..6a0af49287 100644 --- a/.aegir.js +++ b/.aegir.js @@ -11,6 +11,7 @@ module.exports = { served: true, included: false }], + browserNoActivityTimeout: 100 * 1000, singleRun: true }, hooks: { diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index 8996330088..b06b4c41f8 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -74,7 +74,13 @@ function addNode (inProcNode, callback) { config: { Addresses: { Swarm: [`/ip4/127.0.0.1/tcp/0/ws`] - } + }, + Discovery: { + MDNS: { + Enabled: false + } + }, + Bootstrap: [] } }, (err, ipfsd) => { expect(err).to.not.exist() @@ -92,21 +98,19 @@ describe('bitswap', function () { this.timeout(60 * 1000) let config = { - config: { - Addresses: { - Swarm: [] - }, - Discovery: { - MDNS: { - Enabled: false - } - }, - Bootstrap: [] - } + Addresses: { + Swarm: [] + }, + Discovery: { + MDNS: { + Enabled: false + } + }, + Bootstrap: [] } if (isNode) { - config = Object.assign(config, { + config = Object.assign({}, config, { config: { Addresses: { Swarm: ['/ip4/127.0.0.1/tcp/0']