From 4a3e3449945f3752141bed271b558220eefc426e Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Sat, 17 Aug 2019 12:26:15 +0200 Subject: [PATCH 01/12] tests: update ipfsd-ctl This new version of ipfsd-ctl is using async/await instead of callbacks. Hence some rather mechanical changes are needed for tests. --- package.json | 2 +- test/bootstrapers.js | 14 +---- test/cli/dht.js | 25 +++----- test/cli/name-pubsub.js | 78 ++++++++++--------------- test/cli/ping.js | 61 ++++++++----------- test/cli/pubsub.js | 55 ++++++++--------- test/cli/swarm.js | 50 ++++++---------- test/core/bitswap.spec.js | 24 +++----- test/core/block.spec.js | 16 ++--- test/core/bootstrap.spec.js | 16 ++--- test/core/circuit-relay.js | 81 +++++++++++--------------- test/core/dag.spec.js | 16 ++--- test/core/dht.spec.js | 36 ++++-------- test/core/files-sharding.spec.js | 36 +++++------- test/core/files.spec.js | 16 ++--- test/core/interface.spec.js | 5 +- test/core/kad-dht.node.js | 14 ++--- test/core/name-pubsub.js | 69 ++++++++++------------ test/core/name.spec.js | 67 ++++++++++----------- test/core/object.spec.js | 16 ++--- test/core/pin.spec.js | 16 ++--- test/core/ping.spec.js | 55 ++++++----------- test/core/stats.spec.js | 16 ++--- test/core/swarm.spec.js | 16 ++--- test/http-api/block.js | 12 ++-- test/http-api/bootstrap.js | 12 ++-- test/http-api/config.js | 55 +++++++---------- test/http-api/dns.js | 12 ++-- test/http-api/files.js | 16 ++--- test/http-api/id.js | 45 +++++--------- test/http-api/interface.js | 5 +- test/http-api/object.js | 12 ++-- test/http-api/version.js | 12 ++-- test/utils/interface-common-factory.js | 7 ++- test/utils/on-and-off.js | 24 +++----- 35 files changed, 397 insertions(+), 615 deletions(-) diff --git a/package.json b/package.json index 4f8eecb9b2..fd55192aba 100644 --- a/package.json +++ b/package.json @@ -191,7 +191,7 @@ "form-data": "^2.5.0", "hat": "0.0.3", "interface-ipfs-core": "^0.109.1", - "ipfsd-ctl": "^0.43.0", + "ipfsd-ctl": "^0.44.1", "libp2p-websocket-star": "~0.10.2", "ncp": "^2.0.0", "qs": "^6.5.2", diff --git a/test/bootstrapers.js b/test/bootstrapers.js index afc3b7fc0c..6ba8879390 100644 --- a/test/bootstrapers.js +++ b/test/bootstrapers.js @@ -1,10 +1,6 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) const IPFS = require('..') const IPFSFactory = require('ipfsd-ctl') const bootstrapList = require('../src/core/runtime/config-browser.js')().Bootstrap @@ -17,25 +13,21 @@ const waitFor = require('./utils/wait-for') describe('Check that a js-ipfs node can indeed contact the bootstrappers', () => { let ipfsd - before(function (done) { + before(async () => { this.timeout(30 * 1000) const factory = IPFSFactory.create({ type: 'proc', exec: IPFS }) - factory.spawn({ + ipfsd = await factory.spawn({ config: { Addresses: { Swarm: [] } } - }, (err, node) => { - expect(err).to.not.exist() - ipfsd = node - done() }) }) - after(done => ipfsd.stop(done)) + after(() => ipfsd.stop()) it('a node connects to bootstrappers', function (done) { this.timeout(2 * 60 * 1000) diff --git a/test/cli/dht.js b/test/cli/dht.js index a74a387b89..2c89acc26e 100644 --- a/test/cli/dht.js +++ b/test/cli/dht.js @@ -7,7 +7,6 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const series = require('async/series') const parallel = require('async/parallel') const path = require('path') const DaemonFactory = require('ipfsd-ctl') @@ -41,24 +40,16 @@ describe.skip('dht', () => { let multiaddrB // spawn daemons - before(function (done) { + before(async function () { this.timeout(80 * 1000) - series([ - (cb) => df.spawn(daemonOpts, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsA = ipfsExec(_ipfsd.repoPath) - nodes.push(_ipfsd) - cb() - }), - (cb) => df.spawn(daemonOpts, (err, _ipfsd) => { - expect(err).to.not.exist() + const ipfsdA = await df.spawn(daemonOpts) + ipfsA = ipfsExec(ipfsdA.repoPath) + nodes.push(ipfsdA) - ipfsB = ipfsExec(_ipfsd.repoPath) - nodes.push(_ipfsd) - cb() - }) - ], done) + const ipfsdB = await df.spawn(daemonOpts) + ipfsB = ipfsExec(ipfsdB.repoPath) + nodes.push(ipfsdB) }) // get ids @@ -88,7 +79,7 @@ describe.skip('dht', () => { nodes[0].api.swarm.connect(multiaddrB, done) }) - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + after(() => Promise.all(nodes.map((node) => node.stop()))) it('should be able to put a value to the dht and get it afterwards', function () { this.timeout(60 * 1000) diff --git a/test/cli/name-pubsub.js b/test/cli/name-pubsub.js index 4f08b2598d..1c665ea492 100644 --- a/test/cli/name-pubsub.js +++ b/test/cli/name-pubsub.js @@ -8,30 +8,27 @@ const expect = chai.expect chai.use(dirtyChai) const path = require('path') const parallel = require('async/parallel') -const series = require('async/series') const ipfsExec = require('../utils/ipfs-exec') const DaemonFactory = require('ipfsd-ctl') const df = DaemonFactory.create({ type: 'js' }) -const spawnDaemon = (callback) => { - df.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - args: ['--enable-namesys-pubsub'], - initOptions: { bits: 512 }, - config: { - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: false - }, - webRTCStar: { - Enabled: false - } +const spawnDaemon = () => df.spawn({ + exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), + args: ['--enable-namesys-pubsub'], + initOptions: { bits: 512 }, + config: { + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: false + }, + webRTCStar: { + Enabled: false } } - }, callback) -} + } +}) describe('name-pubsub', () => { describe('enabled', () => { @@ -43,29 +40,18 @@ describe('name-pubsub', () => { const nodes = [] // Spawn daemons - before(function (done) { + before(async function () { // CI takes longer to instantiate the daemon, so we need to increase the // timeout for the before step this.timeout(80 * 1000) - series([ - (cb) => { - spawnDaemon((err, node) => { - expect(err).to.not.exist() - ipfsA = ipfsExec(node.repoPath) - nodes.push(node) - cb() - }) - }, - (cb) => { - spawnDaemon((err, node) => { - expect(err).to.not.exist() - ipfsB = ipfsExec(node.repoPath) - nodes.push(node) - cb() - }) - } - ], done) + const nodeA = await spawnDaemon() + ipfsA = ipfsExec(nodeA.repoPath) + nodes.push(nodeA) + + const nodeB = await spawnDaemon() + ipfsB = ipfsExec(nodeB.repoPath) + nodes.push(nodeB) }) // Get node ids @@ -97,7 +83,7 @@ describe('name-pubsub', () => { }) }) - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + after(() => Promise.all(nodes.map((node) => node.stop()))) describe('pubsub commands', () => { it('should get enabled state of pubsub', function () { @@ -166,27 +152,27 @@ describe('name-pubsub', () => { describe('disabled', () => { let ipfsA - const nodes = [] + let node // Spawn daemons - before(function (done) { + before(async function () { // CI takes longer to instantiate the daemon, so we need to increase the // timeout for the before step this.timeout(80 * 1000) - df.spawn({ + node = await df.spawn({ exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), config: {}, initOptions: { bits: 512 } - }, (err, node) => { - expect(err).to.not.exist() - ipfsA = ipfsExec(node.repoPath) - nodes.push(node) - done() }) + ipfsA = ipfsExec(node.repoPath) }) - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + after(() => { + if (node) { + return node.stop() + } + }) it('should get disabled state of pubsub', function () { return ipfsA('name pubsub state') diff --git a/test/cli/ping.js b/test/cli/ping.js index 05d9b709ab..6ea6f4ce09 100644 --- a/test/cli/ping.js +++ b/test/cli/ping.js @@ -4,7 +4,6 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') -const series = require('async/series') const DaemonFactory = require('ipfsd-ctl') const ipfsExec = require('../utils/ipfs-exec') const path = require('path') @@ -30,44 +29,29 @@ describe('ping', function () { let ipfsdBId let cli - before((done) => { + before(async function () { this.timeout(60 * 1000) - series([ - (cb) => { - df.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config, - initOptions: { bits: 512 } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsdB = _ipfsd - cb() - }) - }, - (cb) => { - ipfsdB.api.id((err, peerInfo) => { - expect(err).to.not.exist() - ipfsdBId = peerInfo.id - bMultiaddr = peerInfo.addresses[0] - cb() - }) - } - ], done) + + ipfsdB = await df.spawn({ + exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), + config, + initOptions: { bits: 512 } + }) + const peerInfo = await ipfsdB.api.id() + ipfsdBId = peerInfo.id + bMultiaddr = peerInfo.addresses[0] }) - before(function (done) { + before(async function () { this.timeout(60 * 1000) - df.spawn({ + ipfsdA = await df.spawn({ exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), config, - initoptions: { bits: 512 } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsdA = _ipfsd - // Without DHT we need to have an already established connection - ipfsdA.api.swarm.connect(bMultiaddr, done) + initOptions: { bits: 512 } }) + // Without DHT we need to have an already established connection + await ipfsdA.api.swarm.connect(bMultiaddr) }) before((done) => { @@ -76,14 +60,15 @@ describe('ping', function () { done() }) - after((done) => { - if (!ipfsdA) return done() - ipfsdA.stop(done) + after(() => { + if (ipfsdA) { + return ipfsdA.stop() + } }) - - after((done) => { - if (!ipfsdB) return done() - ipfsdB.stop(done) + after(() => { + if (ipfsdB) { + return ipfsdB.stop() + } }) it('ping host', (done) => { diff --git a/test/cli/pubsub.js b/test/cli/pubsub.js index fcc231331c..89ae432bcd 100644 --- a/test/cli/pubsub.js +++ b/test/cli/pubsub.js @@ -12,7 +12,6 @@ const ipfsExec = require('../utils/ipfs-exec') const IPFS = require('../../src') const path = require('path') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create({ type: 'js' }) const config = { Bootstrap: [], @@ -37,43 +36,47 @@ describe('pubsub', function () { const topicB = 'nonscentsB' const topicC = 'nonscentsC' - before(function (done) { + before(async function () { this.timeout(60 * 1000) - DaemonFactory - .create({ type: 'proc' }) - .spawn({ - exec: IPFS, - initOptions: { bits: 512 }, - config, - args: ['--enable-pubsub-experiment'] - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsdA = _ipfsd - node = _ipfsd.api - done() - }) + const df = DaemonFactory.create({ type: 'proc' }) + ipfsdA = await df.spawn({ + exec: IPFS, + initOptions: { bits: 512 }, + config, + args: ['--enable-pubsub-experiment'] + }) + node = ipfsdA.api }) - after((done) => ipfsdB.stop(done)) + after(() => { + if (ipfsdB) { + return ipfsdB.stop() + } + }) - before((done) => { - df.spawn({ + before(async () => { + const df = DaemonFactory.create({ type: 'js' }) + ipfsdB = await df.spawn({ initOptions: { bits: 512 }, args: ['--enable-pubsub-experiment'], exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), config - }, (err, _ipfsd) => { - expect(err).to.not.exist() - httpApi = _ipfsd.api - ipfsdB = _ipfsd - httpApi.repoPath = ipfsdB.repoPath - done() }) + httpApi = ipfsdB.api + httpApi.repoPath = ipfsdB.repoPath }) - after((done) => ipfsdA.stop(done)) - after((done) => ipfsdB.stop(done)) + after(() => { + if (ipfsdA) { + return ipfsdA.stop() + } + }) + after(() => { + if (ipfsdB) { + return ipfsdB.stop() + } + }) before((done) => { cli = ipfsExec(httpApi.repoPath) diff --git a/test/cli/swarm.js b/test/cli/swarm.js index 9642424930..137661f84e 100644 --- a/test/cli/swarm.js +++ b/test/cli/swarm.js @@ -9,7 +9,6 @@ chai.use(dirtyChai) const sinon = require('sinon') const ipfsExec = require('../utils/ipfs-exec') const path = require('path') -const parallel = require('async/parallel') const addrsCommand = require('../../src/cli/commands/swarm/addrs') const multiaddr = require('multiaddr') @@ -41,43 +40,30 @@ describe('swarm', () => { let ipfsA const nodes = [] - before(function (done) { + before(async function () { // CI takes longer to instantiate the daemon, so we need to increase the // timeout for the before step this.timeout(80 * 1000) - parallel([ - (cb) => { - df.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config, - initOptions: { bits: 512 } - }, (err, node) => { - expect(err).to.not.exist() - ipfsA = ipfsExec(node.repoPath) - nodes.push(node) - cb() - }) - }, - (cb) => { - df.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config, - initOptions: { bits: 512 } - }, (err, node) => { - expect(err).to.not.exist() - node.api.id((err, id) => { - expect(err).to.not.exist() - bMultiaddr = id.addresses[0] - nodes.push(node) - cb() - }) - }) - } - ], done) + const res = await Promise.all([ + df.spawn({ + exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), + config, + initOptions: { bits: 512 } + }), + df.spawn({ + exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), + config, + initOptions: { bits: 512 } + }) + ]) + ipfsA = ipfsExec(res[0].repoPath) + const id = await res[1].api.id() + bMultiaddr = id.addresses[0] + nodes.push(...res) }) - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + after(() => Promise.all(nodes.map((node) => node.stop()))) it('connect', () => { return ipfsA('swarm', 'connect', bMultiaddr).then((out) => { diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index 9809393bb0..a2e0d038b6 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -17,6 +17,7 @@ const multihashing = require('multihashing-async') const CID = require('cids') const path = require('path') const IPFSFactory = require('ipfsd-ctl') +const callbackify = require('callbackify') const IPFS = require('../../src/core') @@ -63,7 +64,7 @@ function connectNodes (remoteNode, inProcNode, callback) { let nodes = [] function addNode (fDaemon, inProcNode, callback) { - fDaemon.spawn({ + callbackify.variadic(fDaemon.spawn.bind(fDaemon))({ exec: isNode ? path.resolve(`${__dirname}/../../src/cli/bin.js`) : './src/cli/bin.js', initOptions: { bits: 512 }, config: { @@ -97,7 +98,7 @@ describe('bitswap', function () { fInProc = IPFSFactory.create({ type: 'proc' }) }) - beforeEach(function (done) { + beforeEach(async function () { this.timeout(60 * 1000) let config = { @@ -120,26 +121,19 @@ describe('bitswap', function () { }) } - fInProc.spawn({ + const ipfsd = await fInProc.spawn({ exec: IPFS, config: config, initOptions: { bits: 512 } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - nodes.push(_ipfsd) - inProcNode = _ipfsd.api - done() }) + nodes.push(ipfsd) + inProcNode = ipfsd.api }) - afterEach(function (done) { + afterEach(async function () { this.timeout(80 * 1000) - const tasks = nodes.map((node) => (cb) => node.stop(cb)) - parallel(tasks, (err) => { - expect(err).to.not.exist() - nodes = [] - done() - }) + await Promise.all(nodes.map((node) => node.stop())) + nodes = [] }) describe('transfer a block between', () => { diff --git a/test/core/block.spec.js b/test/core/block.spec.js index 64b6c7f385..dcee896de3 100644 --- a/test/core/block.spec.js +++ b/test/core/block.spec.js @@ -14,29 +14,23 @@ const IPFS = require('../../src/core') describe('block', () => { let ipfsd, ipfs - before(function (done) { + before(async function () { this.timeout(20 * 1000) const factory = IPFSFactory.create({ type: 'proc' }) - factory.spawn({ + ipfsd = await factory.spawn({ exec: IPFS, initOptions: { bits: 512 }, config: { Bootstrap: [] }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => { + after(() => { if (ipfsd) { - ipfsd.stop(done) - } else { - done() + return ipfsd.stop() } }) diff --git a/test/core/bootstrap.spec.js b/test/core/bootstrap.spec.js index 57bd73bad2..0081958d95 100644 --- a/test/core/bootstrap.spec.js +++ b/test/core/bootstrap.spec.js @@ -20,9 +20,9 @@ describe('bootstrap', () => { let node let ipfsd - before(function (done) { + before(async function () { this.timeout(40 * 1000) - df.spawn({ + ipfsd = await df.spawn({ exec: IPFS, initOptions: { bits: 512 }, config: { @@ -31,15 +31,15 @@ describe('bootstrap', () => { } }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - node = _ipfsd.api - done() }) + node = ipfsd.api }) - after((done) => ipfsd.stop(done)) + after(() => { + if (ipfsd) { + return ipfsd.stop() + } + }) const defaultList = [ '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z', diff --git a/test/core/circuit-relay.js b/test/core/circuit-relay.js index a649f258c9..c23e75faa2 100644 --- a/test/core/circuit-relay.js +++ b/test/core/circuit-relay.js @@ -7,8 +7,6 @@ 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 multiaddr = require('multiaddr') const crypto = require('crypto') @@ -31,13 +29,8 @@ const baseConf = { } } -function setupInProcNode (addrs, hop, callback) { - if (typeof hop === 'function') { - callback = hop - hop = false - } - - procDf.spawn({ +const setupInProcNode = async (addrs, hop) => { + const ipfsd = await procDf.spawn({ libp2p: { config: { relay: { @@ -54,12 +47,10 @@ function setupInProcNode (addrs, hop, callback) { } }), preload: { enabled: false } - }, (err, ipfsd) => { - expect(err).to.not.exist() - ipfsd.api.id((err, id) => { - callback(err, { ipfsd, addrs: id.addresses }) - }) }) + const id = await ipfsd.api.id() + + return { ipfsd, addrs: id.addresses } } const wsAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/ws')) @@ -78,43 +69,39 @@ describe('circuit relay', () => { let relayNode let nodes - before('create and connect', function (done) { - parallel([ - (cb) => setupInProcNode([ + before('create and connect', async () => { + const res = await Promise.all([ + setupInProcNode([ '/ip4/0.0.0.0/tcp/0', '/ip4/0.0.0.0/tcp/0/ws' - ], true, cb), - (cb) => setupInProcNode(['/ip4/0.0.0.0/tcp/0'], cb), - (cb) => setupInProcNode(['/ip4/0.0.0.0/tcp/0/ws'], cb) - ], function (err, res) { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - relayNode = res[0].ipfsd - - nodeAAddr = tcpAddr(res[1].addrs) - nodeA = res[1].ipfsd.api - - nodeBAddr = wsAddr(res[2].addrs) - - nodeB = res[2].ipfsd.api - nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeBAddr).getPeerId()}` - - // ensure we have an address string - expect(nodeAAddr).to.be.a('string') - expect(nodeBAddr).to.be.a('string') - expect(nodeBCircuitAddr).to.be.a('string') - - series([ - (cb) => relayNode.api.swarm.connect(nodeAAddr, cb), - (cb) => relayNode.api.swarm.connect(nodeBAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) - ], done) - }) + ], true), + setupInProcNode(['/ip4/0.0.0.0/tcp/0']), + setupInProcNode(['/ip4/0.0.0.0/tcp/0/ws']) + ]) + nodes = res.map((node) => node.ipfsd) + + relayNode = res[0].ipfsd + + nodeAAddr = tcpAddr(res[1].addrs) + nodeA = res[1].ipfsd.api + + nodeBAddr = wsAddr(res[2].addrs) + + nodeB = res[2].ipfsd.api + nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeBAddr).getPeerId()}` + + // ensure we have an address string + expect(nodeAAddr).to.be.a('string') + expect(nodeBAddr).to.be.a('string') + expect(nodeBCircuitAddr).to.be.a('string') + + await relayNode.api.swarm.connect(nodeAAddr) + await relayNode.api.swarm.connect(nodeBAddr) + await new Promise(resolve => setTimeout(resolve, 1000)) + await nodeA.swarm.connect(nodeBCircuitAddr) }) - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + after(() => Promise.all(nodes.map((node) => node.stop()))) it('should transfer', function (done) { const data = crypto.randomBytes(128) diff --git a/test/core/dag.spec.js b/test/core/dag.spec.js index 55c4bad299..3fcbe11f5a 100644 --- a/test/core/dag.spec.js +++ b/test/core/dag.spec.js @@ -14,27 +14,21 @@ describe('dag', function () { this.timeout(10 * 1000) let ipfsd, ipfs - before(function (done) { + before(async () => { const factory = IPFSFactory.create({ type: 'proc' }) - factory.spawn({ + ipfsd = await factory.spawn({ exec: IPFS, initOptions: { bits: 512 }, config: { Bootstrap: [] }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after(function (done) { + after(() => { if (ipfsd) { - ipfsd.stop(done) - } else { - done() + return ipfsd.stop() } }) diff --git a/test/core/dht.spec.js b/test/core/dht.spec.js index 2eedd6205e..c58c3ba467 100644 --- a/test/core/dht.spec.js +++ b/test/core/dht.spec.js @@ -17,31 +17,23 @@ describe.skip('dht', () => { describe('enabled', () => { let ipfsd, ipfs - before(function (done) { + before(async function () { this.timeout(30 * 1000) const factory = IPFSFactory.create({ type: 'proc' }) - factory.spawn({ + ipfsd = await factory.spawn({ exec: IPFS, initOptions: { bits: 512 }, - config: { - Bootstrap: [] - }, + config: { Bootstrap: [] }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => { + after(() => { if (ipfsd) { - ipfsd.stop(done) - } else { - done() + return ipfsd.stop() } }) @@ -61,30 +53,24 @@ describe.skip('dht', () => { let ipfsd, ipfs - before(function (done) { + before(async function (done) { this.timeout(30 * 1000) const factory = IPFSFactory.create({ type: 'proc' }) - factory.spawn({ + ipfsd = await factory.spawn({ exec: IPFS, initOptions: { bits: 512 }, config: { Bootstrap: [] } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => { + after(() => { if (ipfsd) { - ipfsd.stop(done) - } else { - done() + return ipfsd.stop() } }) diff --git a/test/core/files-sharding.spec.js b/test/core/files-sharding.spec.js index c34213b465..4c9c53c073 100644 --- a/test/core/files-sharding.spec.js +++ b/test/core/files-sharding.spec.js @@ -31,10 +31,10 @@ describe('files directory (sharding tests)', () => { let ipfs let ipfsd - before(function (done) { + before(async function () { this.timeout(40 * 1000) - df.spawn({ + ipfsd = await df.spawn({ exec: IPFS, initOptions: { bits: 512 }, config: { @@ -49,17 +49,15 @@ describe('files directory (sharding tests)', () => { } }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after(function (done) { - this.timeout(40 * 1000) - ipfsd.stop(done) + after(function () { + if (ipfsd) { + this.timeout(40 * 1000) + return ipfsd.stop() + } }) it('should be able to add dir without sharding', function (done) { @@ -83,10 +81,10 @@ describe('files directory (sharding tests)', () => { let ipfs let ipfsd - before(function (done) { + before(async function () { this.timeout(40 * 1000) - df.spawn({ + ipfsd = await df.spawn({ exec: IPFS, initOptions: { bits: 512 }, args: ['--enable-sharding-experiment'], @@ -102,17 +100,15 @@ describe('files directory (sharding tests)', () => { } }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after(function (done) { - this.timeout(40 * 1000) - ipfsd.stop(done) + after(function () { + if (ipfsd) { + this.timeout(40 * 1000) + return ipfsd.stop() + } }) it('should be able to add dir with sharding', function (done) { diff --git a/test/core/files.spec.js b/test/core/files.spec.js index 6d7e496706..e46c7955d7 100644 --- a/test/core/files.spec.js +++ b/test/core/files.spec.js @@ -15,27 +15,21 @@ describe('files', function () { this.timeout(10 * 1000) let ipfsd, ipfs - before(function (done) { + before(async () => { const factory = IPFSFactory.create({ type: 'proc' }) - factory.spawn({ + ipfsd = await factory.spawn({ exec: IPFS, initOptions: { bits: 512 }, config: { Bootstrap: [] }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => { + after(() => { if (ipfsd) { - ipfsd.stop(done) - } else { - done() + return ipfsd.stop() } }) diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index e1dba42bbe..3cdacf1baa 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -4,6 +4,7 @@ const tests = require('interface-ipfs-core') const CommonFactory = require('../utils/interface-common-factory') const isNode = require('detect-node') +const callbackify = require('callbackify') describe('interface-ipfs-core tests', function () { this.timeout(20 * 1000) @@ -171,6 +172,8 @@ describe('interface-ipfs-core tests', function () { tests.swarm(CommonFactory.create({ createSetup ({ ipfsFactory, nodes }) { + const callbackifiedSpawn = callbackify.variadic( + ipfsFactory.spawn.bind(ipfsFactory)) return callback => { callback(null, { spawnNode (repoPath, config, cb) { @@ -198,7 +201,7 @@ describe('interface-ipfs-core tests', function () { const spawnOptions = { repoPath, config, initOptions: { bits: 512 } } - ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => { + callbackifiedSpawn(spawnOptions, (err, _ipfsd) => { if (err) { return cb(err) } diff --git a/test/core/kad-dht.node.js b/test/core/kad-dht.node.js index b7cc90896e..ad88dac668 100644 --- a/test/core/kad-dht.node.js +++ b/test/core/kad-dht.node.js @@ -24,14 +24,12 @@ const config = { } } -function createNode (callback) { - f.spawn({ - exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), - config, - initOptions: { bits: 512 }, - args: ['--preload-enabled=false'] - }, callback) -} +const createNode = () => f.spawn({ + exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), + config, + initOptions: { bits: 512 }, + args: ['--preload-enabled=false'] +}) describe.skip('kad-dht is routing content and peers correctly', () => { let nodeA diff --git a/test/core/name-pubsub.js b/test/core/name-pubsub.js index 571416911e..208cc2be1e 100644 --- a/test/core/name-pubsub.js +++ b/test/core/name-pubsub.js @@ -10,7 +10,6 @@ chai.use(dirtyChai) const base64url = require('base64url') const { fromB58String } = require('multihashes') -const parallel = require('async/parallel') const retry = require('async/retry') const series = require('async/series') @@ -38,52 +37,46 @@ describe('name-pubsub', function () { let idA let idB - const createNode = (callback) => { - df.spawn({ - exec: IPFS, - args: [`--pass ${hat()}`, '--enable-namesys-pubsub'], - config: { - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: false - }, - webRTCStar: { - Enabled: false - } + const createNode = () => df.spawn({ + exec: IPFS, + args: [`--pass ${hat()}`, '--enable-namesys-pubsub'], + config: { + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: false + }, + webRTCStar: { + Enabled: false } - }, - preload: { enabled: false } - }, callback) - } + } + }, + preload: { enabled: false } + }) - before(function (done) { + before(async function () { this.timeout(40 * 1000) - parallel([ - (cb) => createNode(cb), - (cb) => createNode(cb) - ], (err, _nodes) => { - expect(err).to.not.exist() + nodes = await Promise.all([ + createNode(), + createNode() + ]) - nodes = _nodes - nodeA = _nodes[0].api - nodeB = _nodes[1].api + nodeA = nodes[0].api + nodeB = nodes[1].api - parallel([ - (cb) => nodeA.id(cb), - (cb) => nodeB.id(cb) - ], (err, ids) => { - expect(err).to.not.exist() + const ids = await Promise.all([ + nodeA.id(), + nodeB.id() + ]) - idA = ids[0] - idB = ids[1] - nodeA.swarm.connect(ids[1].addresses[0], done) - }) - }) + idA = ids[0] + idB = ids[1] + + await nodeA.swarm.connect(idB.addresses[0]) }) - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + after(() => Promise.all(nodes.map((node) => node.stop()))) it('should publish and then resolve correctly', function (done) { this.timeout(80 * 1000) diff --git a/test/core/name.spec.js b/test/core/name.spec.js index 0db5a90bf2..12561bfda0 100644 --- a/test/core/name.spec.js +++ b/test/core/name.spec.js @@ -42,27 +42,26 @@ describe('name', function () { let node let ipfsd - before(function (done) { + before(async function () { this.timeout(40 * 1000) - df.spawn({ + ipfsd = await df.spawn({ exec: IPFS, args: [`--pass ${hat()}`, '--offline'], config: { Bootstrap: [] }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - node = _ipfsd.api - - done() }) + node = ipfsd.api }) afterEach(() => { sinon.restore() }) - after((done) => ipfsd.stop(done)) + after(() => { + if (ipfsd) { + return ipfsd.stop() + } + }) it('should republish entries after 60 seconds', function (done) { this.timeout(120 * 1000) @@ -181,9 +180,9 @@ describe('name', function () { let nodeId let ipfsd - before(function (done) { + before(async function () { this.timeout(40 * 1000) - df.spawn({ + ipfsd = await df.spawn({ exec: IPFS, args: [`--pass ${hat()}`], config: { @@ -198,21 +197,18 @@ describe('name', function () { } }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - node = _ipfsd.api - - node.id().then((res) => { - expect(res.id).to.exist() - - nodeId = res.id - done() - }) }) + node = ipfsd.api + + const res = await node.id() + nodeId = res.id }) - after((done) => ipfsd.stop(done)) + after(() => { + if (ipfsd) { + return ipfsd.stop() + } + }) it('should error to publish if does not receive private key', function (done) { node._ipns.publisher.publish(null, ipfsRef, (err) => { @@ -358,9 +354,9 @@ describe('name', function () { let ipfsd let nodeId - before(function (done) { + before(async function () { this.timeout(40 * 1000) - df.spawn({ + ipfsd = await df.spawn({ exec: IPFS, args: [`--pass ${hat()}`, '--offline'], config: { @@ -375,21 +371,18 @@ describe('name', function () { } }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - node = _ipfsd.api - ipfsd = _ipfsd - - node.id().then((res) => { - expect(res.id).to.exist() - - nodeId = res.id - done() - }) }) + node = ipfsd.api + + const res = await node.id() + nodeId = res.id }) - after((done) => ipfsd.stop(done)) + after(() => { + if (ipfsd) { + return ipfsd.stop() + } + }) it('should resolve an ipfs path correctly', function (done) { node.add(fixture, (err, res) => { diff --git a/test/core/object.spec.js b/test/core/object.spec.js index 0d931c6961..a1655b8646 100644 --- a/test/core/object.spec.js +++ b/test/core/object.spec.js @@ -16,27 +16,21 @@ describe('object', function () { this.timeout(10 * 1000) let ipfsd, ipfs - before(function (done) { + before(async function () { const factory = IPFSFactory.create({ type: 'proc' }) - factory.spawn({ + ipfsd = await factory.spawn({ exec: IPFS, initOptions: { bits: 512 }, config: { Bootstrap: [] }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => { + after(() => { if (ipfsd) { - ipfsd.stop(done) - } else { - done() + return ipfsd.stop() } }) diff --git a/test/core/pin.spec.js b/test/core/pin.spec.js index c03b62ef29..e9b88fa090 100644 --- a/test/core/pin.spec.js +++ b/test/core/pin.spec.js @@ -14,27 +14,21 @@ describe('pin', function () { this.timeout(10 * 1000) let ipfsd, ipfs - before(function (done) { + before(async () => { const factory = IPFSFactory.create({ type: 'proc' }) - factory.spawn({ + ipfsd = await factory.spawn({ exec: IPFS, initOptions: { bits: 512 }, config: { Bootstrap: [] }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => { + after(() => { if (ipfsd) { - ipfsd.stop(done) - } else { - done() + return ipfsd.stop() } }) diff --git a/test/core/ping.spec.js b/test/core/ping.spec.js index 009d7ec595..5ccd1354f0 100644 --- a/test/core/ping.spec.js +++ b/test/core/ping.spec.js @@ -28,15 +28,15 @@ const config = { } } -function spawnNode ({ dht = false, type = 'js' }, cb) { +const spawnNode = ({ dht = false, type = 'js' }) => { const args = dht ? [] : ['--offline'] const factory = type === 'js' ? df : dfProc - factory.spawn({ + return factory.spawn({ args, config, initOptions: { bits: 512 }, preload: { enabled: false } - }, cb) + }) } // Determine if a ping response object is a pong, or something else, like a status message @@ -56,18 +56,11 @@ describe('ping', function () { let ipfsdBId // Spawn nodes - before(function (done) { + before(async function () { this.timeout(60 * 1000) - series([ - spawnNode.bind(null, { dht: false, type: 'proc' }), - spawnNode.bind(null, { dht: false }) - ], (err, ipfsd) => { - expect(err).to.not.exist() - ipfsdA = ipfsd[0] - ipfsdB = ipfsd[1] - done() - }) + ipfsdA = await spawnNode({ dht: false, type: 'proc' }) + ipfsdB = await spawnNode({ dht: false }) }) // Get the peer info object @@ -112,30 +105,20 @@ describe('ping', function () { let ipfsdBId // Spawn nodes - before(function (done) { + before(async function () { this.timeout(60 * 1000) - series([ - spawnNode.bind(null, { dht: false }), - spawnNode.bind(null, { dht: false }) - ], (err, ipfsd) => { - expect(err).to.not.exist() - ipfsdA = ipfsd[0] - ipfsdB = ipfsd[1] - done() - }) + ipfsdA = await spawnNode({ dht: false }) + ipfsdB = await spawnNode({ dht: false }) }) // Get the peer info object - before(function (done) { + before(async function () { this.timeout(60 * 1000) - ipfsdB.api.id((err, peerInfo) => { - expect(err).to.not.exist() - ipfsdBId = peerInfo.id - bMultiaddr = peerInfo.addresses[0] - done() - }) + const peerInfo = await ipfsdB.api.id() + ipfsdBId = peerInfo.id + bMultiaddr = peerInfo.addresses[0] }) // Connect the nodes @@ -144,14 +127,14 @@ describe('ping', function () { ipfsdA.api.swarm.connect(bMultiaddr, done) }) - after((done) => { - if (!ipfsdA) return done() - ipfsdA.stop(done) + after(async () => { + if (!ipfsdA) return + await ipfsdA.stop() }) - after((done) => { - if (!ipfsdB) return done() - ipfsdB.stop(done) + after(async () => { + if (!ipfsdB) return + await ipfsdB.stop() }) it('sends the specified number of packets', (done) => { diff --git a/test/core/stats.spec.js b/test/core/stats.spec.js index df29295678..680d8a0e23 100644 --- a/test/core/stats.spec.js +++ b/test/core/stats.spec.js @@ -15,27 +15,21 @@ describe('stats', function () { this.timeout(10 * 1000) let ipfsd, ipfs - before(function (done) { + before(async () => { const factory = IPFSFactory.create({ type: 'proc' }) - factory.spawn({ + ipfsd = await factory.spawn({ exec: IPFS, initOptions: { bits: 512 }, config: { Bootstrap: [] }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => { + after(() => { if (ipfsd) { - ipfsd.stop(done) - } else { - done() + return ipfsd.stop() } }) diff --git a/test/core/swarm.spec.js b/test/core/swarm.spec.js index b6a774a2a2..c037092a1b 100644 --- a/test/core/swarm.spec.js +++ b/test/core/swarm.spec.js @@ -14,27 +14,21 @@ describe('swarm', function () { this.timeout(10 * 1000) let ipfsd, ipfs - before(function (done) { + before(async () => { const factory = IPFSFactory.create({ type: 'proc' }) - factory.spawn({ + ipfsd = await factory.spawn({ exec: IPFS, initOptions: { bits: 512 }, config: { Bootstrap: [] }, preload: { enabled: false } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = _ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => { + after(() => { if (ipfsd) { - ipfsd.stop(done) - } else { - done() + return ipfsd.stop() } }) diff --git a/test/http-api/block.js b/test/http-api/block.js index a0e2c5363a..f2242a6cd6 100644 --- a/test/http-api/block.js +++ b/test/http-api/block.js @@ -16,22 +16,18 @@ describe('block endpoint', () => { let ipfs = null let ipfsd = null - before(function (done) { + before(async function () { this.timeout(20 * 1000) - df.spawn({ + ipfsd = await df.spawn({ initOptions: { bits: 512 }, config: { Bootstrap: [] }, args: [] - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => ipfsd.stop(done)) + after(() => ipfsd.stop()) describe('.block', () => { describe('.put', () => { diff --git a/test/http-api/bootstrap.js b/test/http-api/bootstrap.js index b53ba29fdf..07d675b67c 100644 --- a/test/http-api/bootstrap.js +++ b/test/http-api/bootstrap.js @@ -13,10 +13,10 @@ const df = DaemonFactory.create({ exec: path.resolve(`${__dirname}/../../src/cli describe('bootstrap endpoint', () => { let ipfs = null let ipfsd = null - before(function (done) { + before(async function () { this.timeout(20 * 1000) - df.spawn({ + ipfsd = await df.spawn({ initOptions: { bits: 512 }, config: { Bootstrap: [], @@ -29,15 +29,11 @@ describe('bootstrap endpoint', () => { } } } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => ipfsd.stop(done)) + after(() => ipfsd.stop()) describe('.bootstrap', () => { const invalidArg = 'this/Is/So/Invalid/' diff --git a/test/http-api/config.js b/test/http-api/config.js index 51eb3e6e01..bed3701419 100644 --- a/test/http-api/config.js +++ b/test/http-api/config.js @@ -6,9 +6,9 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const ncp = require('ncp').ncp -const rimraf = require('rimraf') -const waterfall = require('async/waterfall') +const promisify = require('promisify-es6') +const ncp = promisify(require('ncp').ncp) +const rimraf = promisify(require('rimraf')) const isWindows = require('../utils/platforms').isWindows const skipOnWindows = isWindows() ? describe.skip : describe @@ -35,44 +35,31 @@ skipOnWindows('config endpoint', () => { setTimeout(done, 5 * 1000) }) - before(function (done) { + before(async function () { this.timeout(20 * 1000) - ncp(repoExample, repoPath, (err) => { - expect(err).to.not.exist() - - waterfall([ - (cb) => df.spawn({ - repoPath: repoPath, - initOptions: { bits: 512 }, - config: { Bootstrap: [] }, - disposable: false, - start: true - }, cb), - (_ipfsd, cb) => { - ipfsd = _ipfsd - ipfsd.start(cb) - } - ], (err) => { - expect(err).to.not.exist() - ipfs = ipfsd.api - - updatedConfig = () => { - const config = fs.readFileSync(path.join(__dirname, '../repo-tests-run/config')) - return JSON.parse(config, 'utf8') - } + await ncp(repoExample, repoPath) - done() - }) + ipfsd = await df.spawn({ + repoPath: repoPath, + initOptions: { bits: 512 }, + config: { Bootstrap: [] }, + disposable: false, + start: true }) + await ipfsd.start() + ipfs = ipfsd.api + + updatedConfig = () => { + const config = fs.readFileSync(path.join(__dirname, '../repo-tests-run/config')) + return JSON.parse(config, 'utf8') + } }) - after(function (done) { + after(async function () { this.timeout(50 * 1000) - rimraf(repoPath, (err) => { - expect(err).to.not.exist() - ipfsd.stop(done) - }) + await rimraf(repoPath) + await ipfsd.stop() }) describe('.config', () => { diff --git a/test/http-api/dns.js b/test/http-api/dns.js index f27e5ee217..60d35afc15 100644 --- a/test/http-api/dns.js +++ b/test/http-api/dns.js @@ -12,20 +12,16 @@ const df = DaemonFactory.create({ exec: path.resolve(`${__dirname}/../../src/cli describe('dns endpoint', () => { let ipfs = null let ipfsd = null - before(function (done) { + before(async function () { this.timeout(20 * 1000) - df.spawn({ + ipfsd = await df.spawn({ initOptions: { bits: 512 }, config: { Bootstrap: [] } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => ipfsd.stop(done)) + after(() => ipfsd.stop()) describe('.dns', () => { it('resolve ipfs.io dns', function (done) { diff --git a/test/http-api/files.js b/test/http-api/files.js index 66a508c34e..34b0eeb0f1 100644 --- a/test/http-api/files.js +++ b/test/http-api/files.js @@ -16,25 +16,19 @@ const df = DaemonFactory.create({ exec: path.resolve(`${__dirname}/../../src/cli describe('.files', () => { let ipfs = null let ipfsd = null - before(function (done) { + before(async function () { this.timeout(20 * 1000) - df.spawn({ + ipfsd = await df.spawn({ initOptions: { bits: 512 }, config: { Bootstrap: [] } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = ipfsd.api - done() }) + ipfs = ipfsd.api }) - after(function (done) { + after(function () { this.timeout(20 * 1000) if (ipfsd) { - ipfsd.stop(done) - } else { - done() + return ipfsd.stop() } }) diff --git a/test/http-api/id.js b/test/http-api/id.js index 05052d83fe..88e44f9ed9 100644 --- a/test/http-api/id.js +++ b/test/http-api/id.js @@ -6,9 +6,9 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const ncp = require('ncp').ncp -const rimraf = require('rimraf') -const waterfall = require('async/waterfall') +const promisify = require('promisify-es6') +const ncp = promisify(require('ncp').ncp) +const rimraf = promisify(require('rimraf')) const path = require('path') const isWindows = require('../utils/platforms').isWindows @@ -23,37 +23,24 @@ skipOnWindows('id endpoint', () => { let ipfs = null let ipfsd = null - before(function (done) { + before(async function () { this.timeout(20 * 1000) - ncp(repoExample, repoPath, (err) => { - expect(err).to.not.exist() - - waterfall([ - (cb) => df.spawn({ - repoPath: repoPath, - initOptions: { bits: 512 }, - config: { Bootstrap: [] }, - disposable: false, - start: true - }, cb), - (_ipfsd, cb) => { - ipfsd = _ipfsd - ipfsd.start(cb) - } - ], (err) => { - expect(err).to.not.exist() - ipfs = ipfsd.api - done() - }) + await ncp(repoExample, repoPath) + ipfsd = await df.spawn({ + repoPath: repoPath, + initOptions: { bits: 512 }, + config: { Bootstrap: [] }, + disposable: false, + start: true }) + await ipfsd.start() + ipfs = ipfsd.api }) - after((done) => { - rimraf(repoPath, (err) => { - expect(err).to.not.exist() - ipfsd.stop(done) - }) + after(async () => { + await rimraf(repoPath) + return ipfsd.stop() }) describe('.id', () => { diff --git a/test/http-api/interface.js b/test/http-api/interface.js index 48f708f747..2a249ef58b 100644 --- a/test/http-api/interface.js +++ b/test/http-api/interface.js @@ -4,6 +4,7 @@ const tests = require('interface-ipfs-core') const CommonFactory = require('../utils/interface-common-factory') const path = require('path') +const callbackify = require('callbackify') describe('interface-ipfs-core over ipfs-http-client tests', () => { const defaultCommonFactory = CommonFactory.create({ @@ -166,6 +167,8 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => { tests.swarm(CommonFactory.create({ createSetup ({ ipfsFactory, nodes }) { + const callbackifiedSpawn = callbackify.variadic( + ipfsFactory.spawn.bind(ipfsFactory)) return callback => { callback(null, { spawnNode (repoPath, config, cb) { @@ -193,7 +196,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => { const spawnOptions = { repoPath, config, initOptions: { bits: 512 } } - ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => { + callbackifiedSpawn(spawnOptions, (err, _ipfsd) => { if (err) { return cb(err) } diff --git a/test/http-api/object.js b/test/http-api/object.js index eba7cdce6a..e60235b470 100644 --- a/test/http-api/object.js +++ b/test/http-api/object.js @@ -28,10 +28,10 @@ function asJson (cb) { describe('object endpoint', () => { let ipfs = null let ipfsd = null - before(function (done) { + before(async function () { this.timeout(20 * 1000) - df.spawn({ + ipfsd = await df.spawn({ initOptions: { bits: 512 }, config: { Bootstrap: [], @@ -44,15 +44,11 @@ describe('object endpoint', () => { } } } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => ipfsd.stop(done)) + after(() => ipfsd.stop()) describe('.object', () => { it('.new', (done) => { diff --git a/test/http-api/version.js b/test/http-api/version.js index 3b92a30b6c..ef84dc792b 100644 --- a/test/http-api/version.js +++ b/test/http-api/version.js @@ -12,9 +12,9 @@ const df = DaemonFactory.create({ exec: path.resolve(`${__dirname}/../../src/cli describe('version endpoint', () => { let ipfs = null let ipfsd = null - before(function (done) { + before(async function () { this.timeout(20 * 1000) - df.spawn({ + ipfsd = await df.spawn({ initOptions: { bits: 512 }, config: { Bootstrap: [], @@ -27,15 +27,11 @@ describe('version endpoint', () => { } } } - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = ipfsd.api - done() }) + ipfs = ipfsd.api }) - after((done) => ipfsd.stop(done)) + after(() => ipfsd.stop()) describe('.version', () => { it('get the version', (done) => { diff --git a/test/utils/interface-common-factory.js b/test/utils/interface-common-factory.js index 8df86419a7..554eea8fcc 100644 --- a/test/utils/interface-common-factory.js +++ b/test/utils/interface-common-factory.js @@ -5,6 +5,7 @@ const each = require('async/each') const IPFSFactory = require('ipfsd-ctl') const ipfsClient = require('ipfs-http-client') const IPFS = require('../../src') +const callbackify = require('callbackify') function createFactory (options) { options = options || {} @@ -31,6 +32,8 @@ function createFactory (options) { } const ipfsFactory = IPFSFactory.create(options.factoryOptions) + const callbackifiedSpawn = callbackify.variadic( + ipfsFactory.spawn.bind(ipfsFactory)) return function createCommon () { const nodes = [] @@ -42,7 +45,7 @@ function createFactory (options) { setup = (callback) => { callback(null, { spawnNode (cb) { - ipfsFactory.spawn(options.spawnOptions, (err, _ipfsd) => { + callbackifiedSpawn(options.spawnOptions, (err, _ipfsd) => { if (err) { return cb(err) } @@ -58,7 +61,7 @@ function createFactory (options) { if (options.createTeardown) { teardown = options.createTeardown({ ipfsFactory, nodes }, options) } else { - teardown = callback => each(nodes, (node, cb) => node.stop(cb), callback) + teardown = callback => each(nodes, (node, cb) => callbackify.variadic(node.stop.bind(node))(cb), callback) } return { setup, teardown } diff --git a/test/utils/on-and-off.js b/test/utils/on-and-off.js index 674a668372..dc29ed5488 100644 --- a/test/utils/on-and-off.js +++ b/test/utils/on-and-off.js @@ -2,10 +2,6 @@ 'use strict' const hat = require('hat') -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) const ipfsExec = require('../utils/ipfs-exec') const clean = require('../utils/clean') @@ -45,29 +41,27 @@ function on (tests) { const thing = {} let ipfsd - before(function (done) { + before(async function () { // CI takes longer to instantiate the daemon, // so we need to increase the timeout for the // before step this.timeout(60 * 1000) - df.spawn({ + ipfsd = await df.spawn({ type: 'js', exec: path.resolve(`${__dirname}/../../src/cli/bin.js`), initOptions: { bits: 512 }, config: { Bootstrap: [] } - }, (err, node) => { - expect(err).to.not.exist() - ipfsd = node - thing.ipfs = ipfsExec(node.repoPath) - thing.ipfs.repoPath = node.repoPath - done() }) + thing.ipfs = ipfsExec(ipfsd.repoPath) + thing.ipfs.repoPath = ipfsd.repoPath }) - after(function (done) { - this.timeout(15 * 1000) - ipfsd.stop(done) + after(function () { + if (ipfsd) { + this.timeout(15 * 1000) + return ipfsd.stop() + } }) tests(thing) From 3ac3bb7be9632974da24b78ee7bc9e8e140538b1 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 23 Aug 2019 12:43:15 +0100 Subject: [PATCH 02/12] test: fail test if there is output on stderr --- test/cli/daemon.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index daef854fa6..b228c3989e 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -122,6 +122,9 @@ describe('daemon', () => { res.kill() } }) + res.stderr.on('data', (data) => { + reject(new Error(data.toString('utf8'))) + }) }) apiAddrs.forEach(addr => expect(out).to.include(`API listening on ${addr.slice(0, -2)}`)) From a16c4c514be05e16ca2eaa86841ac609756f0dd3 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 23 Aug 2019 13:29:54 +0100 Subject: [PATCH 03/12] fix: do not double resolve --- test/cli/daemon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index b228c3989e..131f0fb4df 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -118,7 +118,7 @@ describe('daemon', () => { if (out.includes('Daemon is ready')) { res.stdout.removeListener('data', onData) const onKilled = () => resolve(out) - res.then(onKilled).catch(onKilled) + res.then(onKilled, onKilled) res.kill() } }) From 26e7e07d9b605f858eef077431055b24e19366c1 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 28 Aug 2019 17:57:16 +0100 Subject: [PATCH 04/12] test: refactor daemon tests to be more stable on windows --- test/cli/daemon.js | 265 ++++++++++++++++++++-------------------- test/utils/ipfs-exec.js | 6 +- 2 files changed, 139 insertions(+), 132 deletions(-) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index 131f0fb4df..033e011b57 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -13,43 +13,42 @@ const pkg = require('../../package.json') const skipOnWindows = isWindows() ? it.skip : it -const checkLock = (repo, cb) => { +const checkLock = (repo) => { // skip on windows // https://github.com/ipfs/js-ipfsd-ctl/pull/155#issuecomment-326983530 if (!isWindows) { if (fs.existsSync(path.join(repo, 'repo.lock'))) { - cb(new Error('repo.lock not removed')) + throw new Error('repo.lock not removed') } if (fs.existsSync(path.join(repo, 'api'))) { - cb(new Error('api file not removed')) + throw new Error('api file not removed') } } - cb() } -function testSignal (ipfs, sig, config) { - return ipfs('init').then(() => { - return ipfs('config', 'Addresses', JSON.stringify({ - API: '/ip4/127.0.0.1/tcp/0', - Gateway: '/ip4/127.0.0.1/tcp/0' - }), '--json') - }).then(() => { - const proc = ipfs('daemon') - return new Promise((resolve, reject) => { - proc.stdout.on('data', (data) => { - if (data.toString().includes(`Daemon is ready`)) { - if (proc.kill(sig)) { - resolve() - } else { - reject(new Error(`Unable to ${sig} process`)) - } +async function testSignal (ipfs, sig, config) { + await ipfs('init') + await ipfs('config', 'Addresses', JSON.stringify({ + API: '/ip4/127.0.0.1/tcp/0', + Gateway: '/ip4/127.0.0.1/tcp/0' + }), '--json') + + const proc = ipfs('daemon') + + return new Promise((resolve, reject) => { + proc.stdout.on('data', (data) => { + if (data.toString().includes(`Daemon is ready`)) { + if (proc.kill(sig)) { + resolve() + } else { + reject(new Error(`Unable to ${sig} process`)) } - }) - proc.stderr.on('data', (data) => { - if (data.toString().length > 0) { - reject(new Error(data)) - } - }) + } + }) + proc.stderr.on('data', (data) => { + if (data.toString().length > 0) { + reject(new Error(data)) + } }) }) } @@ -65,35 +64,27 @@ describe('daemon', () => { afterEach(() => clean(repoPath)) - skipOnWindows('do not crash if Addresses.Swarm is empty', function (done) { + skipOnWindows('do not crash if Addresses.Swarm is empty', async function () { this.timeout(100 * 1000) // These tests are flaky, but retrying 3 times seems to make it work 99% of the time this.retries(3) - ipfs('init').then(() => { - return ipfs('config', 'Addresses', JSON.stringify({ - Swarm: [], - API: '/ip4/127.0.0.1/tcp/0', - Gateway: '/ip4/127.0.0.1/tcp/0' - }), '--json') - }).then(() => { - const res = ipfs('daemon') - const timeout = setTimeout(() => { - done(new Error('Daemon did not get ready in time')) - }, 1000 * 120) - res.stdout.on('data', (data) => { - const line = data.toString() - if (line.includes('Daemon is ready')) { - clearTimeout(timeout) - res.kill() - done() - } - }) - }).catch(err => done(err)) + await ipfs('init') + await ipfs('config', 'Addresses', JSON.stringify({ + Swarm: [], + API: '/ip4/127.0.0.1/tcp/0', + Gateway: '/ip4/127.0.0.1/tcp/0' + }), '--json') + + const stdout = await ipfs('daemon', { + timeout: 1000 * 120 + }) + + expect(stdout).to.include('Daemon is ready') }) it('should allow bind to multiple addresses for API and Gateway', async function () { - this.timeout(20 * 1000) + this.timeout(100 * 1000) const apiAddrs = [ '/ip4/127.0.0.1/tcp/0', @@ -109,133 +100,145 @@ describe('daemon', () => { await ipfs('config', 'Addresses.API', JSON.stringify(apiAddrs), '--json') await ipfs('config', 'Addresses.Gateway', JSON.stringify(gatewayAddrs), '--json') - const out = await new Promise((resolve, reject) => { - const res = ipfs('daemon') - let out = '' - - res.stdout.on('data', function onData (data) { - out += data - if (out.includes('Daemon is ready')) { - res.stdout.removeListener('data', onData) - const onKilled = () => resolve(out) - res.then(onKilled, onKilled) - res.kill() - } - }) - res.stderr.on('data', (data) => { - reject(new Error(data.toString('utf8'))) - }) + const daemon = ipfs('daemon') + let stdout = '' + + daemon.stdout.on('data', (data) => { + stdout += data.toString('utf8') + + if (stdout.includes('Daemon is ready')) { + daemon.kill() + } }) - apiAddrs.forEach(addr => expect(out).to.include(`API listening on ${addr.slice(0, -2)}`)) - gatewayAddrs.forEach(addr => expect(out).to.include(`Gateway (read only) listening on ${addr.slice(0, -2)}`)) + try { + await daemon + throw new Error('Did not kill process') + } catch (err) { + // because we killed the process + expect(err.message).to.include('SIGTERM') + + apiAddrs.forEach(addr => expect(err.stdout).to.include(`API listening on ${addr.slice(0, -2)}`)) + gatewayAddrs.forEach(addr => expect(err.stdout).to.include(`Gateway (read only) listening on ${addr.slice(0, -2)}`)) + } }) it('should allow no bind addresses for API and Gateway', async function () { - this.timeout(20 * 1000) + this.timeout(100 * 1000) await ipfs('init') await ipfs('config', 'Addresses.API', '[]', '--json') await ipfs('config', 'Addresses.Gateway', '[]', '--json') - const out = await new Promise((resolve, reject) => { - const res = ipfs('daemon') - let out = '' - - res.stdout.on('data', function onData (data) { - out += data - if (out.includes('Daemon is ready')) { - res.stdout.removeListener('data', onData) - const onKilled = () => resolve(out) - res.then(onKilled).catch(onKilled) - res.kill() - } - }) + const daemon = ipfs('daemon') + let stdout = '' + + daemon.stdout.on('data', (data) => { + stdout += data.toString('utf8') + + if (stdout.includes('Daemon is ready')) { + daemon.kill() + } }) - expect(out).to.not.include('API listening on') - expect(out).to.not.include('Gateway (read only) listening on') + try { + await daemon + throw new Error('Did not kill process') + } catch (err) { + // because we killed the process + expect(err.message).to.include('SIGTERM') + + expect(err.stdout).to.not.include('API listening on') + expect(err.stdout).to.not.include('Gateway (read only) listening on') + } }) - skipOnWindows('should handle SIGINT gracefully', function (done) { + skipOnWindows('should handle SIGINT gracefully', async function () { this.timeout(100 * 1000) - testSignal(ipfs, 'SIGINT').then(() => { - checkLock(repoPath, done) - }).catch(done) + await testSignal(ipfs, 'SIGINT') + + checkLock(repoPath) }) - skipOnWindows('should handle SIGTERM gracefully', function (done) { + skipOnWindows('should handle SIGTERM gracefully', async function () { this.timeout(100 * 1000) - testSignal(ipfs, 'SIGTERM').then(() => { - checkLock(repoPath, done) - }).catch(done) + await testSignal(ipfs, 'SIGTERM') + + checkLock(repoPath) }) - skipOnWindows('should handle SIGHUP gracefully', function (done) { + skipOnWindows('should handle SIGHUP gracefully', async function () { this.timeout(100 * 1000) - testSignal(ipfs, 'SIGHUP').then(() => { - checkLock(repoPath, done) - }).catch(done) + await testSignal(ipfs, 'SIGHUP') + + checkLock(repoPath) }) - it('gives error if user hasn\'t run init before', function (done) { + it('gives error if user hasn\'t run init before', async function () { this.timeout(100 * 1000) - const expectedError = 'no initialized ipfs repo found in ' + repoPath + const err = await ipfs.fail('daemon') - ipfs('daemon').catch((err) => { - expect(err.stdout).to.have.string(expectedError) - done() - }) + expect(err.stdout).to.include('no initialized ipfs repo found in ' + repoPath) }) - it('should be silent', function (done) { - this.timeout(10 * 1000) - const res = ipfs('daemon --silent') - res.catch(function () {}) // Handles the unhandled promise rejection - let output = '' - const onData = (d) => { output += d } - res.stdout.on('data', onData) - res.stderr.on('data', onData) - setTimeout(function () { - res.kill() - expect(output).to.be.empty() - done() + it('should be silent', async function () { + this.timeout(100 * 1000) + await ipfs('init') + + const daemon = ipfs('daemon --silent') + + setTimeout(() => { + daemon.kill() }, 5 * 1000) + + try { + await daemon + throw new Error('Did not kill process') + } catch (err) { + // because we killed the process + expect(err.message).to.include('SIGTERM') + expect(err.stdout).to.be.empty() + expect(err.stderr).to.be.empty() + } }) - it('should present ipfs path help when option help is received', function (done) { + it('should present ipfs path help when option help is received', async function () { this.timeout(100 * 1000) - ipfs('daemon --help').then((res) => { - expect(res).to.have.string('export IPFS_PATH=/path/to/ipfsrepo') - done() - }) + const result = await ipfs('daemon --help') + + expect(result).to.include('export IPFS_PATH=/path/to/ipfsrepo') }) it('should print version info', async function () { this.timeout(100 * 1000) await ipfs('init') - const out = await new Promise(resolve => { - const res = ipfs('daemon') - let out = '' + const daemon = ipfs('daemon') + let stdout = '' - res.stdout.on('data', function onData (data) { - out += data - if (out.includes('Daemon is ready')) { - res.stdout.removeListener('data', onData) - res.kill() - resolve(out) - } - }) + daemon.stdout.on('data', (data) => { + stdout += data.toString('utf8') + + if (stdout.includes('Daemon is ready')) { + daemon.kill() + } }) - expect(out).to.include(`js-ipfs version: ${pkg.version}`) - expect(out).to.include(`System version: ${os.arch()}/${os.platform()}`) - expect(out).to.include(`Node.js version: ${process.versions.node}`) + try { + await daemon + throw new Error('Did not kill process') + } catch (err) { + // because we killed the process + expect(err.message).to.include('SIGTERM') + + expect(err.stdout).to.include(`js-ipfs version: ${pkg.version}`) + expect(err.stdout).to.include(`System version: ${os.arch()}/${os.platform()}`) + expect(err.stdout).to.include(`Node.js version: ${process.versions.node}`) + } }) }) diff --git a/test/utils/ipfs-exec.js b/test/utils/ipfs-exec.js index 2e764632c5..98253fb6a6 100644 --- a/test/utils/ipfs-exec.js +++ b/test/utils/ipfs-exec.js @@ -81,11 +81,15 @@ module.exports = (repoPath, opts) => { .catch(err => { caught = true expect(err).to.exist() + + return err }) - .then(() => { + .then((res) => { if (!caught) { throw new Error(`jsipfs expected to fail during command: jsipfs ${args.join(' ')}`) } + + return res }) } From 7e2e81a533b92468cbfa4fc52b4abeb2d54c7512 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 28 Aug 2019 18:38:52 +0100 Subject: [PATCH 05/12] test: fix up tests on not-windows --- test/cli/daemon.js | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index 033e011b57..64b6d05078 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -26,28 +26,29 @@ const checkLock = (repo) => { } } -async function testSignal (ipfs, sig, config) { +async function testSignal (ipfs, sig) { await ipfs('init') await ipfs('config', 'Addresses', JSON.stringify({ API: '/ip4/127.0.0.1/tcp/0', Gateway: '/ip4/127.0.0.1/tcp/0' }), '--json') - const proc = ipfs('daemon') - return new Promise((resolve, reject) => { - proc.stdout.on('data', (data) => { - if (data.toString().includes(`Daemon is ready`)) { - if (proc.kill(sig)) { - resolve() - } else { - reject(new Error(`Unable to ${sig} process`)) - } + const daemon = ipfs('daemon') + let stdout = '' + + daemon.stdout.on('data', (data) => { + stdout += data.toString('utf8') + + if (stdout.includes('Daemon is ready')) { + daemon.kill(sig) + resolve() } }) - proc.stderr.on('data', (data) => { - if (data.toString().length > 0) { - reject(new Error(data)) + + daemon.catch((err) => { + if (!err.signal.includes(sig)) { + reject(err) } }) }) @@ -76,9 +77,7 @@ describe('daemon', () => { Gateway: '/ip4/127.0.0.1/tcp/0' }), '--json') - const stdout = await ipfs('daemon', { - timeout: 1000 * 120 - }) + const stdout = await ipfs('daemon') expect(stdout).to.include('Daemon is ready') }) @@ -113,10 +112,9 @@ describe('daemon', () => { try { await daemon - throw new Error('Did not kill process') + throw new Error('fail') } catch (err) { - // because we killed the process - expect(err.message).to.include('SIGTERM') + expect(err.killed).to.be.true() apiAddrs.forEach(addr => expect(err.stdout).to.include(`API listening on ${addr.slice(0, -2)}`)) gatewayAddrs.forEach(addr => expect(err.stdout).to.include(`Gateway (read only) listening on ${addr.slice(0, -2)}`)) @@ -145,8 +143,7 @@ describe('daemon', () => { await daemon throw new Error('Did not kill process') } catch (err) { - // because we killed the process - expect(err.message).to.include('SIGTERM') + expect(err.killed).to.be.true() expect(err.stdout).to.not.include('API listening on') expect(err.stdout).to.not.include('Gateway (read only) listening on') @@ -199,8 +196,8 @@ describe('daemon', () => { await daemon throw new Error('Did not kill process') } catch (err) { - // because we killed the process - expect(err.message).to.include('SIGTERM') + expect(err.killed).to.be.true() + expect(err.stdout).to.be.empty() expect(err.stderr).to.be.empty() } @@ -233,8 +230,7 @@ describe('daemon', () => { await daemon throw new Error('Did not kill process') } catch (err) { - // because we killed the process - expect(err.message).to.include('SIGTERM') + expect(err.killed).to.be.true() expect(err.stdout).to.include(`js-ipfs version: ${pkg.version}`) expect(err.stdout).to.include(`System version: ${os.arch()}/${os.platform()}`) From 9f50d7db32488bb799d61e7182470f95c733d111 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 28 Aug 2019 18:51:15 +0100 Subject: [PATCH 06/12] test: fix up again, for everyone this time --- test/cli/daemon.js | 50 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index 64b6d05078..df743d473d 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -47,7 +47,7 @@ async function testSignal (ipfs, sig) { }) daemon.catch((err) => { - if (!err.signal.includes(sig)) { + if (!err.killed) { reject(err) } }) @@ -77,9 +77,25 @@ describe('daemon', () => { Gateway: '/ip4/127.0.0.1/tcp/0' }), '--json') - const stdout = await ipfs('daemon') + const daemon = ipfs('daemon') + let stdout = '' + + daemon.stdout.on('data', (data) => { + stdout += data.toString('utf8') + + if (stdout.includes('Daemon is ready')) { + daemon.kill() + } + }) + + try { + await daemon + throw new Error('Did not kill process') + } catch (err) { + expect(err.killed).to.be.true() - expect(stdout).to.include('Daemon is ready') + expect(stdout).to.include('Daemon is ready') + } }) it('should allow bind to multiple addresses for API and Gateway', async function () { @@ -112,7 +128,7 @@ describe('daemon', () => { try { await daemon - throw new Error('fail') + throw new Error('Did not kill process') } catch (err) { expect(err.killed).to.be.true() @@ -187,20 +203,24 @@ describe('daemon', () => { await ipfs('init') const daemon = ipfs('daemon --silent') - - setTimeout(() => { + const stop = (err) => { daemon.kill() - }, 5 * 1000) - try { - await daemon - throw new Error('Did not kill process') - } catch (err) { - expect(err.killed).to.be.true() - - expect(err.stdout).to.be.empty() - expect(err.stderr).to.be.empty() + if (err) { + throw err + } } + + return new Promise((resolve, reject) => { + daemon.stdout.on('data', (data) => { + reject(new Error('Output was received ' + data.toString('utf8'))) + }) + + setTimeout(() => { + resolve() + }, 5 * 1000) + }) + .then(stop, stop) }) it('should present ipfs path help when option help is received', async function () { From 42d2ea5af63df17b59e3a09f5b8f8d7669865c2b Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 28 Aug 2019 18:53:01 +0100 Subject: [PATCH 07/12] test: reject on stderr output too --- test/cli/daemon.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index df743d473d..705006ba57 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -213,7 +213,10 @@ describe('daemon', () => { return new Promise((resolve, reject) => { daemon.stdout.on('data', (data) => { - reject(new Error('Output was received ' + data.toString('utf8'))) + reject(new Error('Output was received on stdout ' + data.toString('utf8'))) + }) + daemon.stderr.on('data', (data) => { + reject(new Error('Output was received stderr ' + data.toString('utf8'))) }) setTimeout(() => { From 2a2c0cd63b23d454c953d42f57fb883ab9c12869 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 28 Aug 2019 19:39:08 +0100 Subject: [PATCH 08/12] test: fix gc tests --- test/core/gc.spec.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/test/core/gc.spec.js b/test/core/gc.spec.js index 239c8816a7..42fd39de20 100644 --- a/test/core/gc.spec.js +++ b/test/core/gc.spec.js @@ -53,35 +53,33 @@ describe('gc', function () { let ipfs let lockEmitter - before(function (done) { + before(async function () { this.timeout(40 * 1000) const factory = IPFSFactory.create({ type: 'proc', exec: IPFS }) const config = { Bootstrap: [] } + if (env.isNode) { config.Addresses = { Swarm: ['/ip4/127.0.0.1/tcp/0'] } } - factory.spawn({ config }, (err, node) => { - expect(err).to.not.exist() - - ipfsd = node - ipfs = ipfsd.api + ipfsd = await factory.spawn({ config }) + ipfs = ipfsd.api - // Replace the Mutex with one that emits events when a readLock or - // writeLock is requested (needed in the tests below) - ipfs._gcLock.mutex = new MutexEmitter(ipfs._options.repoOwner) - lockEmitter = ipfs._gcLock.mutex.emitter - done() - }) + // Replace the Mutex with one that emits events when a readLock or + // writeLock is requested (needed in the tests below) + ipfs._gcLock.mutex = new MutexEmitter(ipfs._options.repoOwner) + lockEmitter = ipfs._gcLock.mutex.emitter }) - after((done) => { - ipfsd.stop(done) + after(() => { + if (ipfsd) { + return ipfsd.stop() + } }) const blockAddTests = [{ From ad774d793607540f414238c2fc76ea60fec6043a Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 28 Aug 2019 21:43:06 +0100 Subject: [PATCH 09/12] chore: disable bundle size check because service returns 500s --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f7eef6a3ce..98a181e915 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,8 @@ jobs: include: - stage: check script: - - npx aegir build --bundlesize + # https://bundlesize-store.now.sh/values?repo=ipfs/js-ipfs&token=[secure] is 500ing + # - npx aegir build --bundlesize - npx aegir dep-check -- -i wrtc -i electron-webrtc - npm run lint From 9ecf18767c604b0a1cd38a051a1fb76f3daa4663 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 28 Aug 2019 21:47:11 +0100 Subject: [PATCH 10/12] chore: fix linting --- test/core/gc.spec.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/core/gc.spec.js b/test/core/gc.spec.js index 42fd39de20..ab3e148a7c 100644 --- a/test/core/gc.spec.js +++ b/test/core/gc.spec.js @@ -57,7 +57,6 @@ describe('gc', function () { this.timeout(40 * 1000) const factory = IPFSFactory.create({ type: 'proc', exec: IPFS }) - const config = { Bootstrap: [] } if (env.isNode) { @@ -69,7 +68,6 @@ describe('gc', function () { ipfsd = await factory.spawn({ config }) ipfs = ipfsd.api - // Replace the Mutex with one that emits events when a readLock or // writeLock is requested (needed in the tests below) ipfs._gcLock.mutex = new MutexEmitter(ipfs._options.repoOwner) From 4ae692c0fde70948db831301d47a24463d40a1a0 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 29 Aug 2019 08:46:24 +0100 Subject: [PATCH 11/12] chore: more windows fixes --- test/cli/daemon.js | 15 ++++++---- test/core/ping.spec.js | 66 ++++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index 705006ba57..eb05d981aa 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -203,20 +203,25 @@ describe('daemon', () => { await ipfs('init') const daemon = ipfs('daemon --silent') - const stop = (err) => { + const stop = async (err) => { daemon.kill() if (err) { throw err } + + try { + await daemon + } catch (err) { + if (!err.killed) { + throw err + } + } } return new Promise((resolve, reject) => { daemon.stdout.on('data', (data) => { - reject(new Error('Output was received on stdout ' + data.toString('utf8'))) - }) - daemon.stderr.on('data', (data) => { - reject(new Error('Output was received stderr ' + data.toString('utf8'))) + reject(new Error('Output was received ' + data.toString('utf8'))) }) setTimeout(() => { diff --git a/test/core/ping.spec.js b/test/core/ping.spec.js index 8c0362b850..d39c5d8e97 100644 --- a/test/core/ping.spec.js +++ b/test/core/ping.spec.js @@ -6,13 +6,14 @@ const dirtyChai = require('dirty-chai') const pull = require('pull-stream/pull') const drain = require('pull-stream/sinks/drain') const parallel = require('async/parallel') -const series = require('async/series') const DaemonFactory = require('ipfsd-ctl') const isNode = require('detect-node') const path = require('path') const expect = chai.expect chai.use(dirtyChai) -const df = DaemonFactory.create({ exec: path.resolve(`${__dirname}/../../src/cli/bin.js`) }) +const df = DaemonFactory.create({ + exec: path.resolve(`${__dirname}/../../src/cli/bin.js`) +}) const dfProc = DaemonFactory.create({ exec: require('../../'), type: 'proc' @@ -31,6 +32,7 @@ const config = { const spawnNode = ({ dht = false, type = 'js' }) => { const args = dht ? [] : ['--offline'] const factory = type === 'js' ? df : dfProc + return factory.spawn({ args, config, @@ -76,20 +78,23 @@ describe('ping', function () { // Connect the nodes before(async function () { this.timeout(60 * 1000) + await ipfsdA.api.swarm.connect(bMultiaddr) }) after(async () => { - if (!ipfsdA) return - await ipfsdA.stop() + if (ipfsdB) { + await ipfsdB.stop() + } }) after(async () => { - if (!ipfsdB) return - await ipfsdB.stop() + if (ipfsdA) { + await ipfsdA.stop() + } }) - it('can ping via a promise without options', async () => { + it.only('can ping via a promise without options', async () => { const res = await ipfsdA.api.ping(ipfsdBId) expect(res.length).to.be.ok() @@ -128,13 +133,15 @@ describe('ping', function () { }) after(async () => { - if (!ipfsdA) return - await ipfsdA.stop() + if (ipfsdA) { + await ipfsdA.stop() + } }) after(async () => { - if (!ipfsdB) return - await ipfsdB.stop() + if (ipfsdB) { + await ipfsdB.stop() + } }) it('sends the specified number of packets', (done) => { @@ -191,20 +198,12 @@ describe('ping', function () { let ipfsdCId // Spawn nodes - before(function (done) { + before(async function () { this.timeout(60 * 1000) - series([ - spawnNode.bind(null, { dht: true }), - spawnNode.bind(null, { dht: true }), - spawnNode.bind(null, { dht: true }) - ], (err, ipfsd) => { - expect(err).to.not.exist() - ipfsdA = ipfsd[0] - ipfsdB = ipfsd[1] - ipfsdC = ipfsd[2] - done() - }) + ipfsdA = await spawnNode({ dht: true }) + ipfsdB = await spawnNode({ dht: true }) + ipfsdC = await spawnNode({ dht: true }) }) // Get the peer info objects @@ -249,19 +248,22 @@ describe('ping', function () { }) }) - after((done) => { - if (!ipfsdA) return done() - ipfsdA.stop(done) + after(async () => { + if (ipfsdA) { + await ipfsdA.stop() + } }) - after((done) => { - if (!ipfsdB) return done() - ipfsdB.stop(done) + after(async () => { + if (ipfsdB) { + await ipfsdB.stop() + } }) - after((done) => { - if (!ipfsdC) return done() - ipfsdC.stop(done) + after(async () => { + if (ipfsdC) { + await ipfsdC.stop() + } }) it('if enabled uses the DHT peer routing to find peer', (done) => { From 06f7588f4c7022c884efcfcd5933bea43df1b46d Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 29 Aug 2019 10:04:18 +0100 Subject: [PATCH 12/12] chore: helps to save files after editing them --- test/core/ping.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/ping.spec.js b/test/core/ping.spec.js index d39c5d8e97..9de8966f4a 100644 --- a/test/core/ping.spec.js +++ b/test/core/ping.spec.js @@ -94,7 +94,7 @@ describe('ping', function () { } }) - it.only('can ping via a promise without options', async () => { + it('can ping via a promise without options', async () => { const res = await ipfsdA.api.ping(ipfsdBId) expect(res.length).to.be.ok()