From 53035e14b1526c114109c4717ebb9dea0afb8fac Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 5 Sep 2018 17:05:42 +0100 Subject: [PATCH 1/6] feat: adds waitFor utility Calls back when async func returns true. License: MIT Signed-off-by: Alan Shaw --- test/cli/bitswap.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/cli/bitswap.js b/test/cli/bitswap.js index 087bb19453..0257903b7f 100644 --- a/test/cli/bitswap.js +++ b/test/cli/bitswap.js @@ -20,12 +20,20 @@ describe('bitswap', () => runOn((thing) => { }) before(function (done) { - this.timeout(60 * 1000) + this.timeout(2 * 60 * 1000) PeerId.create({ bits: 512 }, (err, peer) => { expect(err).to.not.exist() peerId = peer.toB58String() - done() + + waitFor((cb) => { + ipfs('bitswap wantlist') + .then(out => cb(null, out.includes(key))) + .catch(cb) + }, { + name: key + ' to be wanted', + timeout: 60 * 1000 + }, done) }) }) From 95d0007868d0b061de6893cbafa8452fdaed6665 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 5 Sep 2018 18:04:57 +0100 Subject: [PATCH 2/6] fix: appease the linter License: MIT Signed-off-by: Alan Shaw --- test/cli/bitswap.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/test/cli/bitswap.js b/test/cli/bitswap.js index 0257903b7f..6213857c5f 100644 --- a/test/cli/bitswap.js +++ b/test/cli/bitswap.js @@ -25,15 +25,7 @@ describe('bitswap', () => runOn((thing) => { PeerId.create({ bits: 512 }, (err, peer) => { expect(err).to.not.exist() peerId = peer.toB58String() - - waitFor((cb) => { - ipfs('bitswap wantlist') - .then(out => cb(null, out.includes(key))) - .catch(cb) - }, { - name: key + ' to be wanted', - timeout: 60 * 1000 - }, done) + done() }) }) From 5c3f5310d1a8d0ecec6fe42c542f0f900217798a Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 6 Sep 2018 10:47:27 +0100 Subject: [PATCH 3/6] chore: cleanup temp repos after tests License: MIT Signed-off-by: Alan Shaw --- test/bootstrapers.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/bootstrapers.js b/test/bootstrapers.js index afc3b7fc0c..e806c42cdb 100644 --- a/test/bootstrapers.js +++ b/test/bootstrapers.js @@ -40,7 +40,11 @@ describe('Check that a js-ipfs node can indeed contact the bootstrappers', () => it('a node connects to bootstrappers', function (done) { this.timeout(2 * 60 * 1000) +<<<<<<< HEAD const test = (cb) => { +======= + waitFor((cb) => { +>>>>>>> chore: cleanup temp repos after tests ipfsd.api.swarm.peers((err, peers) => { if (err) return cb(err) @@ -52,8 +56,12 @@ describe('Check that a js-ipfs node can indeed contact the bootstrappers', () => cb(null, bootstrapList.every(addr => peerList.includes(addr))) }) +<<<<<<< HEAD } waitFor(test, { name: 'connect to all bootstrap nodes', timeout: 60 * 1000 }, done) +======= + }, { name: 'connect to all bootstrap nodes', timeout: 60 * 1000 }, done) +>>>>>>> chore: cleanup temp repos after tests }) }) From d38e701bcc27a7021ef3fd90baf227c411162ad6 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 6 Sep 2018 11:01:21 +0100 Subject: [PATCH 4/6] chore: appease linter License: MIT Signed-off-by: Alan Shaw --- test/bootstrapers.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/bootstrapers.js b/test/bootstrapers.js index e806c42cdb..afc3b7fc0c 100644 --- a/test/bootstrapers.js +++ b/test/bootstrapers.js @@ -40,11 +40,7 @@ describe('Check that a js-ipfs node can indeed contact the bootstrappers', () => it('a node connects to bootstrappers', function (done) { this.timeout(2 * 60 * 1000) -<<<<<<< HEAD const test = (cb) => { -======= - waitFor((cb) => { ->>>>>>> chore: cleanup temp repos after tests ipfsd.api.swarm.peers((err, peers) => { if (err) return cb(err) @@ -56,12 +52,8 @@ describe('Check that a js-ipfs node can indeed contact the bootstrappers', () => cb(null, bootstrapList.every(addr => peerList.includes(addr))) }) -<<<<<<< HEAD } waitFor(test, { name: 'connect to all bootstrap nodes', timeout: 60 * 1000 }, done) -======= - }, { name: 'connect to all bootstrap nodes', timeout: 60 * 1000 }, done) ->>>>>>> chore: cleanup temp repos after tests }) }) From 84c29ba9b2e184d11f81db266a4350cdae953f7b Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 5 Sep 2018 11:07:47 +0100 Subject: [PATCH 5/6] perf: faster startup time I noticed that libp2p takes over 200ms to require. When using the CLI with no daemon we never start the IPFS node so libp2p is required but unused. This PR lazily requires libp2p when start is called, which means that if the node is never started, you do not suffer the 200ms it takes to require the library. License: MIT Signed-off-by: Alan Shaw --- src/core/components/libp2p.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index c07e7b79f0..87838cb1e7 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -1,7 +1,5 @@ 'use strict' -// libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified -const Node = require('../runtime/libp2p-nodejs') const promisify = require('promisify-es6') const get = require('lodash/get') const defaultsDeep = require('@nodeutils/defaults-deep') @@ -59,6 +57,9 @@ module.exports = function libp2p (self) { libp2pDefaults ) + // Required inline to reduce startup time + // Note: libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified + const Node = require('../runtime/libp2p-nodejs') return new Node(libp2pOptions) } From 8d5de85681eb3dae5e0cdbcfadce045faaf24f9b Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 11 Sep 2018 12:30:13 +0100 Subject: [PATCH 6/6] fix: revert increase timeout License: MIT Signed-off-by: Alan Shaw --- test/cli/bitswap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/bitswap.js b/test/cli/bitswap.js index 6213857c5f..087bb19453 100644 --- a/test/cli/bitswap.js +++ b/test/cli/bitswap.js @@ -20,7 +20,7 @@ describe('bitswap', () => runOn((thing) => { }) before(function (done) { - this.timeout(2 * 60 * 1000) + this.timeout(60 * 1000) PeerId.create({ bits: 512 }, (err, peer) => { expect(err).to.not.exist()