From 53e391bfd16f9208fd220be20b5cd24d2df56227 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 22 Dec 2017 19:31:00 -0600 Subject: [PATCH] fix: removing factory --- .aegir.js | 3 +- test/browser.js | 4 +- test/circuit-relay.js | 69 ++++++++----------- test/exchange-files.js | 11 +-- test/kad-dht.js | 1 + test/node.js | 6 +- test/repo.js | 47 ++++++++----- .../ipfs-factory-instance/default-config.json | 29 -------- test/utils/ipfs-factory-instance/index.js | 63 ----------------- 9 files changed, 71 insertions(+), 162 deletions(-) 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 6e832dad..f11e51ff 100644 --- a/.aegir.js +++ b/.aegir.js @@ -11,7 +11,8 @@ module.exports = { served: true, included: false }], - singleRun: true + singleRun: true, + browserNoActivityTimeout: 100 * 1000 }, hooks: { browser: { diff --git a/test/browser.js b/test/browser.js index d10f90d8..48a8a5d8 100644 --- a/test/browser.js +++ b/test/browser.js @@ -2,5 +2,7 @@ 'use strict' // require('./exchange-files') -require('./repo') +// require('./pubsub') +// require('./kad-dht') require('./circuit-relay') +require('./repo') diff --git a/test/circuit-relay.js b/test/circuit-relay.js index 7cb7c71e..9f9ad3cc 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -12,7 +12,8 @@ const series = require('async/series') const waterfall = require('async/waterfall') const multiaddr = require('multiaddr') const crypto = require('crypto') -const IPFSFactory = require('./utils/ipfs-factory-instance') +const IPFS = require('ipfs') +const createRepo = require('./utils/create-repo-nodejs') const isNode = require('detect-node') @@ -37,19 +38,27 @@ function setupInProcNode (factory, addrs, hop, callback) { hop = false } - factory.spawnNode(null, Object.assign({}, baseConf, { - Addresses: { - Swarm: addrs - }, - EXPERIMENTAL: { - relay: { - enabled: true, - hop: { - enabled: hop + const node = new IPFS({ + repo: createRepo(), + init: { bits: 1024 }, + config: Object.assign({}, baseConf, { + Addresses: { + Swarm: addrs + }, + EXPERIMENTAL: { + relay: { + enabled: true, + hop: { + enabled: hop + } } } - } - }), callback) + }) + }) + + node.once('ready', () => { + callback(null, node) + }) } function setUpJsNode (addrs, hop, callback) { @@ -264,9 +273,7 @@ function tests (relayType) { return } - this.timeout(50 * 1000) - - let factory + this.timeout(90 * 1000) let browserNode1 let browserNode2 @@ -275,11 +282,9 @@ function tests (relayType) { let browserNode2Addrs before(function (done) { - factory = new IPFSFactory() - parallel([ - (cb) => setupInProcNode(factory, [], false, cb), - (cb) => setupInProcNode(factory, [], false, cb) + (cb) => setupInProcNode([], false, cb), + (cb) => setupInProcNode([], false, cb) ], (err, nodes) => { expect(err).to.not.exist() browserNode1 = nodes[0] @@ -292,8 +297,6 @@ function tests (relayType) { }) }) - after((done) => factory.dismantle(done)) - it('should connect and transfer', function (done) { const data = crypto.randomBytes(128) series([ @@ -316,17 +319,14 @@ function tests (relayType) { this.timeout(50 * 1000) - let factory - let browserNode1 let jsTCP let jsTCPAddrs before(function (done) { - factory = new IPFSFactory() parallel([ - (cb) => setupInProcNode(factory, [], false, cb), + (cb) => setupInProcNode([], false, cb), (cb) => setUpJsNode([`${base}/35003`], cb) ], (err, nodes) => { expect(err).to.not.exist() @@ -339,12 +339,7 @@ function tests (relayType) { }) }) - after((done) => { - parallel([ - (cb) => factory.dismantle(cb), - (cb) => jsTCP.stop(cb) - ], done) - }) + after((done) => jsTCP.stop(done)) it('should connect and transfer', function (done) { const data = crypto.randomBytes(128) @@ -368,17 +363,14 @@ function tests (relayType) { this.timeout(50 * 1000) - let factory - let browserNode1 let goTCP let goTCPAddrs before(function (done) { - factory = new IPFSFactory() parallel([ - (cb) => setupInProcNode(factory, [], false, cb), + (cb) => setupInProcNode([], false, cb), (cb) => setUpGoNode([`${base}/35003`], cb) ], (err, nodes) => { expect(err).to.not.exist() @@ -392,12 +384,7 @@ function tests (relayType) { }) }) - after((done) => { - parallel([ - (cb) => factory.dismantle(cb), - (cb) => goTCP.stop(cb) - ], done) - }) + after((done) => goTCP.stop(done)) it('should connect and transfer', function (done) { const data = crypto.randomBytes(128) diff --git a/test/exchange-files.js b/test/exchange-files.js index 1a34f726..6c3988e7 100644 --- a/test/exchange-files.js +++ b/test/exchange-files.js @@ -58,8 +58,8 @@ describe('exchange files', () => { parallel([ (cb) => df.spawn(cb), - (cb) => df.spawn({ isJs: true }, cb), - (cb) => df.spawn({ isJs: true }, cb) + (cb) => df.spawn({ type: 'js' }, cb), + (cb) => df.spawn({ type: 'js' }, cb) ], (err, n) => { expect(err).to.not.exist() nodes = n @@ -172,7 +172,8 @@ describe('exchange files', () => { // TODO these tests are not fetching the full dir?? describe('get directory', () => dirs.forEach((num) => { - it(`go -> js: depth: 5, num: ${num}`, () => { + it(`go -> js: depth: 5, num: ${num}`, function () { + this.timeout(10 * 1000) const dir = tmpDir() return randomFs({ path: dir, @@ -190,7 +191,7 @@ describe('exchange files', () => { }) it(`js -> go: depth: 5, num: ${num}`, function () { - this.timeout(6000) + this.timeout(10 * 1000) const dir = tmpDir() return randomFs({ @@ -209,7 +210,7 @@ describe('exchange files', () => { }) it(`js -> js: depth: 5, num: ${num}`, function () { - this.timeout(6000) + this.timeout(20 * 1000) const dir = tmpDir() return randomFs({ diff --git a/test/kad-dht.js b/test/kad-dht.js index 6f715461..5cf2c022 100644 --- a/test/kad-dht.js +++ b/test/kad-dht.js @@ -33,6 +33,7 @@ describe.skip('kad-dht', () => { goD2 = nodes[1] goD3 = nodes[2] jsD = nodes[3] + done() }) }) diff --git a/test/node.js b/test/node.js index 7e4a5134..2d3b4f8a 100644 --- a/test/node.js +++ b/test/node.js @@ -3,6 +3,6 @@ require('./repo') require('./exchange-files') -require('./circuit-relay') -require('./kad-dht') -require('./pubsub') +// require('./circuit-relay') +// require('./kad-dht') +// require('./pubsub') diff --git a/test/repo.js b/test/repo.js index d3566fd3..c54ad0cc 100644 --- a/test/repo.js +++ b/test/repo.js @@ -5,7 +5,8 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const waterfall = require('async/waterfall') + +const series = require('async/series') const crypto = require('crypto') const os = require('os') const path = require('path') @@ -22,8 +23,8 @@ function catAndCheck (api, hash, data, callback) { }) } -describe.skip('repo', () => { - it.skip('read repo: go -> js', function (done) { +describe('repo', () => { + it('read repo: go -> js', function (done) { this.timeout(50 * 1000) const dir = path.join(os.tmpdir(), hat()) @@ -33,29 +34,37 @@ describe.skip('repo', () => { let jsDaemon let hash - waterfall([ + series([ (cb) => df.spawn({ - repoPath: dir - }, cb), - (node, cb) => { + repoPath: dir, + disposable: false + }, (err, node) => { + expect(err).to.not.exist() goDaemon = node - goDaemon.api.add(data, cb) - }, - (res, cb) => { + goDaemon.init(cb) + }), + (cb) => goDaemon.start(cb), + (cb) => goDaemon.api.add(data, (err, res) => { + expect(err).to.not.exist() hash = res[0].hash - catAndCheck(goDaemon.api, hash, data, cb) - }, + cb() + }), + (cb) => catAndCheck(goDaemon.api, hash, data, cb), (cb) => goDaemon.stop(cb), (cb) => df.spawn({ type: 'js', - repoPath: dir - }, cb), - (node, cb) => { - console.dir('HERE') + repoPath: dir, + disposable: false + }, (err, node) => { + expect(err).to.not.exist() + jsDaemon = node cb() - }, + }), + (cb) => jsDaemon.start(cb), (cb) => catAndCheck(jsDaemon.api, hash, data, cb), - (cb) => jsDaemon.stop(cb) + (cb) => jsDaemon.stop(cb), + (cb) => setTimeout(cb, 10500), + (cb) => jsDaemon.cleanup(cb) ], done) }) @@ -70,7 +79,7 @@ describe.skip('repo', () => { let goDaemon let hash - waterfall([ + series([ (cb) => df.spawn({ type: 'js', repoPath: dir }, cb), (node, cb) => { jsDaemon = node 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 677c7c85..00000000 --- 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 b704bd54..00000000 --- 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('ipfs') -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) - } -}