From 81b1e99124c8d3a348865c7b34487ec1283ec0cb Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Thu, 21 Dec 2017 00:41:26 -0600 Subject: [PATCH 01/49] feat: port to new ipfsd-ctl --- .aegir.js | 3 +- test/browser.js | 3 +- test/circuit-relay.js | 462 ++++++++++++++++++++++ test/exchange-files.js | 22 +- test/kad-dht.js | 1 - test/pubsub.js | 1 + test/repo.js | 29 +- test/utils/ipfs-factory-instance/index.js | 63 +++ 8 files changed, 548 insertions(+), 36 deletions(-) create mode 100644 test/circuit-relay.js create mode 100644 test/utils/ipfs-factory-instance/index.js diff --git a/.aegir.js b/.aegir.js index f11e51ff..6e832dad 100644 --- a/.aegir.js +++ b/.aegir.js @@ -11,8 +11,7 @@ module.exports = { served: true, included: false }], - singleRun: true, - browserNoActivityTimeout: 100 * 1000 + singleRun: true }, hooks: { browser: { diff --git a/test/browser.js b/test/browser.js index e1398b8c..d10f90d8 100644 --- a/test/browser.js +++ b/test/browser.js @@ -2,6 +2,5 @@ 'use strict' // require('./exchange-files') -// require('./pubsub') -require('./kad-dht') require('./repo') +require('./circuit-relay') diff --git a/test/circuit-relay.js b/test/circuit-relay.js new file mode 100644 index 00000000..7cb7c71e --- /dev/null +++ b/test/circuit-relay.js @@ -0,0 +1,462 @@ +/* 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 multiaddr = require('multiaddr') +const crypto = require('crypto') +const IPFSFactory = require('./utils/ipfs-factory-instance') + +const isNode = require('detect-node') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const baseConf = { + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: + false + } + } +} + +const base = '/ip4/127.0.0.1/tcp' + +function setupInProcNode (factory, addrs, hop, callback) { + if (typeof hop === 'function') { + callback = hop + hop = false + } + + factory.spawnNode(null, Object.assign({}, baseConf, { + Addresses: { + Swarm: addrs + }, + EXPERIMENTAL: { + relay: { + enabled: true, + hop: { + enabled: hop + } + } + } + }), callback) +} + +function setUpJsNode (addrs, hop, callback) { + if (typeof hop === 'function') { + callback = hop + hop = false + } + + df.spawn({ + type: 'js', + config: Object.assign({}, baseConf, { + Addresses: { + Swarm: addrs + }, + EXPERIMENTAL: { + relay: { + enabled: true, + hop: { + enabled: hop + } + } + } + }) + }, (err, ipfsd) => { + expect(err).to.not.exist() + ipfsd.api.swarm.localAddrs((err, addrs) => { + callback(err, { ipfsd, addrs: circuitFilter(addrs) }) + }) + }) +} + +function setUpGoNode (addrs, hop, callback) { + if (typeof hop === 'function') { + callback = hop + hop = false + } + + df.spawn({ + config: Object.assign({}, baseConf, { + Addresses: { + Swarm: addrs + }, + Swarm: { + DisableRelay: false, + EnableRelayHop: hop + } + }) + }, (err, ipfsd) => { + expect(err).to.not.exist() + ipfsd.api.id((err, id) => { + callback(err, { ipfsd, addrs: circuitFilter(id.addresses) }) + }) + }) +} + +function addAndCat (node1, node2, data, callback) { + waterfall([ + (cb) => node1.files.add(data, cb), + (res, cb) => node2.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], callback) +} + +const circuitFilter = (addrs) => addrs.map((a) => a.toString()).filter((a) => !a.includes('/p2p-circuit')) +const wsAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/ws')) +const tcpAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => !a.includes('/ws')) + +function tests (relayType) { + describe(`jsWS <-> ${relayType} <-> goTCP`, function () { + this.timeout(50 * 1000) + + let goTCP + let goTCPAddr + let jsWSAddr + let jsWS + let jsWSCircuitAddr + + let nodes + before((done) => { + parallel([ + (cb) => setUpGoNode([`${base}/35003`], cb), + (cb) => setUpJsNode([`${base}/35004/ws`], cb) + ], (err, res) => { + expect(err).to.not.exist() + nodes = res.map((node) => node.ipfsd) + + goTCPAddr = tcpAddr(res[0].addrs) + goTCP = res[0].ipfsd.api + + jsWSAddr = wsAddr(res[1].addrs) + jsWS = res[1].ipfsd.api + jsWSCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(jsWSAddr).getPeerId()}` + + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('should connect and transfer', function (done) { + const data = crypto.randomBytes(128) + series([ + (cb) => this.relay.api.swarm.connect(goTCPAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => this.relay.api.swarm.connect(jsWSAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => goTCP.swarm.connect(jsWSCircuitAddr, cb) + ], (err) => { + expect(err).to.not.exist() + addAndCat(goTCP, jsWS, data, done) + }) + }) + }) + + describe(`jsWS <-> ${relayType} <-> jsTCP`, function () { + this.timeout(50 * 1000) + let jsTCP + let jsTCPAddr + + let jsWS + let jsWSAddr + let jsTCPCircuitAddr + + let nodes + before((done) => { + parallel([ + (cb) => setUpJsNode([`${base}/35003`], cb), + (cb) => setUpJsNode([`${base}/35004/ws`], cb) + ], (err, res) => { + expect(err).to.not.exist() + nodes = res.map((node) => node.ipfsd) + + jsTCP = res[0].ipfsd.api + jsTCPAddr = tcpAddr(res[0].addrs) + jsTCPCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(jsTCPAddr).getPeerId()}` + + jsWS = res[1].ipfsd.api + jsWSAddr = wsAddr(res[1].addrs) + + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('should connect and transfer', function (done) { + const data = crypto.randomBytes(128) + series([ + (cb) => this.relay.api.swarm.connect(jsTCPAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => this.relay.api.swarm.connect(jsWSAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => jsWS.swarm.connect(jsTCPCircuitAddr, cb) + ], (err) => { + expect(err).to.not.exist() + addAndCat(jsTCP, jsWS, data, done) + }) + }) + }) + + describe(`goWS <-> ${relayType} <-> goTCP`, function () { + this.timeout(50 * 1000) + let goTCP + let goTCPAddr + let goTCPCircuitAddr + + let goWS + let goWSAddr + + let nodes + before((done) => { + parallel([ + (cb) => setUpGoNode([`${base}/35003`], cb), + (cb) => setUpGoNode([`${base}/35004/ws`], cb) + ], (err, res) => { + expect(err).to.not.exist() + nodes = res.map((node) => node.ipfsd) + + goTCP = res[0].ipfsd.api + goTCPAddr = tcpAddr(res[0].addrs) + goTCPCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(goTCPAddr).getPeerId()}` + + goWS = res[1].ipfsd.api + goWSAddr = wsAddr(res[1].addrs) + + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('should connect and transfer', function (done) { + const data = crypto.randomBytes(128) + series([ + (cb) => this.relay.api.swarm.connect(goTCPAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => this.relay.api.swarm.connect(goWSAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => goWS.swarm.connect(goTCPCircuitAddr, cb) + ], (err) => { + expect(err).to.not.exist() + addAndCat(goTCP, goWS, data, done) + }) + }) + }) + + describe(`browser <-> ${relayType} <-> browser`, function () { + if (isNode) { + return + } + + this.timeout(50 * 1000) + + let factory + + let browserNode1 + let browserNode2 + + // let browserNodeId1 + let browserNode2Addrs + + before(function (done) { + factory = new IPFSFactory() + + parallel([ + (cb) => setupInProcNode(factory, [], false, cb), + (cb) => setupInProcNode(factory, [], false, cb) + ], (err, nodes) => { + expect(err).to.not.exist() + browserNode1 = nodes[0] + browserNode2 = nodes[1] + browserNode2.id((err, id) => { + expect(err).to.not.exist() + browserNode2Addrs = id.addresses + done() + }) + }) + }) + + after((done) => factory.dismantle(done)) + + it('should connect and transfer', function (done) { + const data = crypto.randomBytes(128) + series([ + (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => browserNode2.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => browserNode1.swarm.connect(browserNode2Addrs[0], cb) + ], (err) => { + expect(err).to.not.exist() + addAndCat(browserNode1, browserNode2, data, done) + }) + }) + }) + + describe(`jsTCP <-> ${relayType} <-> browser`, function () { + if (isNode) { + return + } + + 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) => setUpJsNode([`${base}/35003`], cb) + ], (err, nodes) => { + expect(err).to.not.exist() + browserNode1 = nodes[0] + + jsTCP = nodes[1].ipfsd + jsTCPAddrs = nodes[1].addrs + + done() + }) + }) + + after((done) => { + parallel([ + (cb) => factory.dismantle(cb), + (cb) => jsTCP.stop(cb) + ], done) + }) + + it('should connect and transfer', function (done) { + const data = crypto.randomBytes(128) + series([ + (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => jsTCP.api.swarm.connect(tcpAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => browserNode1.swarm.connect(jsTCPAddrs[0], cb) + ], (err) => { + expect(err).to.not.exist() + addAndCat(browserNode1, jsTCP.api, data, done) + }) + }) + }) + + describe(`goTCP <-> ${relayType} <-> browser`, function () { + if (isNode) { + return + } + + 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) => setUpGoNode([`${base}/35003`], cb) + ], (err, nodes) => { + expect(err).to.not.exist() + + browserNode1 = nodes[0] + + goTCP = nodes[1].ipfsd + goTCPAddrs = nodes[1].addrs + + done() + }) + }) + + after((done) => { + parallel([ + (cb) => factory.dismantle(cb), + (cb) => goTCP.stop(cb) + ], done) + }) + + it('should connect and transfer', function (done) { + const data = crypto.randomBytes(128) + series([ + (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => goTCP.api.swarm.connect(tcpAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => browserNode1.swarm.connect(goTCPAddrs[0], cb) + ], (err) => { + expect(err).to.not.exist() + addAndCat(browserNode1, goTCP.api, data, done) + }) + }) + }) +} + +describe('circuit', () => { + describe('js relay', function () { + this.relay = null + this.relayAddrs = null + + beforeEach(function (done) { + this.timeout(50 * 1000) + + setUpJsNode([`${base}/35002`, `${base}/35001/ws`], true, (err, res) => { + expect(err).to.not.exist() + this.relay = res.ipfsd + this.relayAddrs = res.addrs + done() + }) + }) + + afterEach(function (done) { this.relay.stop(done) }) + + describe('test js relay', function () { + tests('jsRelay') + }) + }) + + describe('go relay', function () { + this.relay = null + this.relayAddrs = null + + beforeEach(function (done) { + this.timeout(50 * 1000) + + setUpGoNode([`${base}/35002`, `${base}/35001/ws`], true, (err, res) => { + expect(err).to.not.exist() + this.relay = res.ipfsd + this.relayAddrs = res.addrs + done() + }) + }) + + afterEach(function (done) { this.relay.stop(done) }) + + describe('test go relay', function () { + tests('goRelay') + }) + }) +}) diff --git a/test/exchange-files.js b/test/exchange-files.js index 3cd36db1..a0050c0a 100644 --- a/test/exchange-files.js +++ b/test/exchange-files.js @@ -54,7 +54,7 @@ describe('exchange files', () => { let nodes before(function (done) { - this.timeout(50 * 1000) + this.timeout(100 * 1000) parallel([ (cb) => df.spawn({ initOptions: { bits: 1024 } }, cb), @@ -73,7 +73,7 @@ describe('exchange files', () => { after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) it('connect go <-> js', function (done) { - this.timeout(50 * 1000) + this.timeout(500 * 1000) let jsId let goId @@ -103,7 +103,7 @@ describe('exchange files', () => { }) it('connect js <-> js', function (done) { - this.timeout(50 * 1000) + this.timeout(500 * 1000) let jsId let js2Id @@ -133,8 +133,7 @@ describe('exchange files', () => { }) describe('cat file', () => sizes.forEach((size) => { - it(`go -> js: ${pretty(size)}`, function (done) { - this.timeout(50 * 1000) + it(`go -> js: ${pretty(size)}`, (done) => { const data = crypto.randomBytes(size) waterfall([ (cb) => goDaemon.api.add(data, cb), @@ -146,8 +145,7 @@ describe('exchange files', () => { }) }) - it(`js -> go: ${pretty(size)}`, function (done) { - this.timeout(50 * 1000) + it(`js -> go: ${pretty(size)}`, (done) => { const data = crypto.randomBytes(size) waterfall([ (cb) => jsDaemon.api.add(data, cb), @@ -159,8 +157,7 @@ describe('exchange files', () => { }) }) - it(`js -> js: ${pretty(size)}`, function (done) { - this.timeout(20 * 1000) + it(`js -> js: ${pretty(size)}`, (done) => { const data = crypto.randomBytes(size) waterfall([ (cb) => js2Daemon.api.add(data, cb), @@ -175,8 +172,7 @@ 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}`, function () { - this.timeout(50 * 1000) + it(`go -> js: depth: 5, num: ${num}`, () => { const dir = tmpDir() return randomFs({ path: dir, @@ -194,7 +190,7 @@ describe('exchange files', () => { }) it(`js -> go: depth: 5, num: ${num}`, function () { - this.timeout(50 * 1000) + this.timeout(6000) const dir = tmpDir() return randomFs({ @@ -213,7 +209,7 @@ describe('exchange files', () => { }) it(`js -> js: depth: 5, num: ${num}`, function () { - this.timeout(80 * 1000) + this.timeout(6000) const dir = tmpDir() return randomFs({ diff --git a/test/kad-dht.js b/test/kad-dht.js index 2389dc09..e991e111 100644 --- a/test/kad-dht.js +++ b/test/kad-dht.js @@ -33,7 +33,6 @@ describe.skip('kad-dht', () => { goD2 = nodes[1] goD3 = nodes[2] jsD = nodes[3] - done() }) }) diff --git a/test/pubsub.js b/test/pubsub.js index b81a9c95..3a312bd3 100644 --- a/test/pubsub.js +++ b/test/pubsub.js @@ -10,6 +10,7 @@ const series = require('async/series') const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() /* * Wait for a condition to become true. When its true, callback is called. diff --git a/test/repo.js b/test/repo.js index 83a8edd8..4e4d47cd 100644 --- a/test/repo.js +++ b/test/repo.js @@ -5,8 +5,7 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) - -const series = require('async/series') +const waterfall = require('async/waterfall') const crypto = require('crypto') const os = require('os') const path = require('path') @@ -23,8 +22,8 @@ function catAndCheck (api, hash, data, callback) { }) } -describe('repo', () => { - it('read repo: go -> js', function (done) { +describe.skip('repo', () => { + it.skip('read repo: go -> js', function (done) { this.timeout(50 * 1000) const dir = path.join(os.tmpdir(), hat()) @@ -34,7 +33,7 @@ describe('repo', () => { let jsDaemon let hash - series([ + waterfall([ (cb) => df.spawn({ repoPath: dir, disposable: false, @@ -42,15 +41,12 @@ describe('repo', () => { }, (err, node) => { expect(err).to.not.exist() goDaemon = node - goDaemon.init(cb) - }), - (cb) => goDaemon.start(cb), - (cb) => goDaemon.api.add(data, (err, res) => { - expect(err).to.not.exist() + goDaemon.api.add(data, cb) + }, + (res, cb) => { hash = res[0].hash - cb() - }), - (cb) => catAndCheck(goDaemon.api, hash, data, cb), + catAndCheck(goDaemon.api, hash, data, cb) + }, (cb) => goDaemon.stop(cb), (cb) => df.spawn({ type: 'js', @@ -61,12 +57,9 @@ describe('repo', () => { expect(err).to.not.exist() jsDaemon = node cb() - }), - (cb) => jsDaemon.start(cb), + }, (cb) => catAndCheck(jsDaemon.api, hash, data, cb), - (cb) => jsDaemon.stop(cb), - (cb) => setTimeout(cb, 10500), - (cb) => jsDaemon.cleanup(cb) + (cb) => jsDaemon.stop(cb) ], done) }) diff --git a/test/utils/ipfs-factory-instance/index.js b/test/utils/ipfs-factory-instance/index.js new file mode 100644 index 00000000..b704bd54 --- /dev/null +++ b/test/utils/ipfs-factory-instance/index.js @@ -0,0 +1,63 @@ +'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) + } +} From 7013f8830fe5b1c9040ee3c360a8babe0fa9c673 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 22 Dec 2017 19:31:00 -0600 Subject: [PATCH 02/49] fix: removing factory --- .aegir.js | 3 +- test/browser.js | 4 +- test/circuit-relay.js | 71 +++++++++-------------- test/exchange-files.js | 7 ++- test/kad-dht.js | 1 + test/repo.js | 29 +++++---- test/utils/ipfs-factory-instance/index.js | 63 -------------------- 7 files changed, 56 insertions(+), 122 deletions(-) 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..77075275 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,13 @@ 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 +338,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 +362,13 @@ 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 +382,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 a0050c0a..076bef6e 100644 --- a/test/exchange-files.js +++ b/test/exchange-files.js @@ -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(50 * 1000) const dir = tmpDir() return randomFs({ diff --git a/test/kad-dht.js b/test/kad-dht.js index e991e111..2389dc09 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/repo.js b/test/repo.js index 4e4d47cd..83a8edd8 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,7 +34,7 @@ describe.skip('repo', () => { let jsDaemon let hash - waterfall([ + series([ (cb) => df.spawn({ repoPath: dir, disposable: false, @@ -41,12 +42,15 @@ describe.skip('repo', () => { }, (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', @@ -57,9 +61,12 @@ describe.skip('repo', () => { 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) }) 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) - } -} From 65295bf6deb283b5cd1e65ce481f58c06fcf104f Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 10 Jan 2018 19:13:35 -0600 Subject: [PATCH 03/49] feat: adopting latest changes to ipfsd-ctl --- .aegir.js | 2 +- test/circuit-relay.js | 189 +++++++++++++++++++++++++----------------- test/pubsub.js | 1 - 3 files changed, 113 insertions(+), 79 deletions(-) diff --git a/.aegir.js b/.aegir.js index f11e51ff..d107bb3b 100644 --- a/.aegir.js +++ b/.aegir.js @@ -11,7 +11,7 @@ module.exports = { served: true, included: false }], - singleRun: true, + singleRun: false, browserNoActivityTimeout: 100 * 1000 }, hooks: { diff --git a/test/circuit-relay.js b/test/circuit-relay.js index 77075275..0f0a763c 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -13,12 +13,13 @@ const waterfall = require('async/waterfall') const multiaddr = require('multiaddr') const crypto = require('crypto') const IPFS = require('ipfs') -const createRepo = require('./utils/create-repo-nodejs') const isNode = require('detect-node') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const jsDf = DaemonFactory.create({ type: 'js' }) +const goDf = DaemonFactory.create({ type: 'go' }) +const procDf = DaemonFactory.create({ type: 'proc', exec: IPFS }) const baseConf = { Bootstrap: [], @@ -38,9 +39,7 @@ function setupInProcNode (factory, addrs, hop, callback) { hop = false } - const node = new IPFS({ - repo: createRepo(), - init: { bits: 1024 }, + procDf.spawn({ config: Object.assign({}, baseConf, { Addresses: { Swarm: addrs @@ -54,10 +53,11 @@ function setupInProcNode (factory, addrs, hop, callback) { } } }) - }) - - node.once('ready', () => { - callback(null, node) + }, (err, ipfsd) => { + expect(err).to.not.exist() + ipfsd.api.id((err, id) => { + callback(err, { ipfsd, addrs: circuitFilter(id.addresses) }) + }) }) } @@ -67,8 +67,7 @@ function setUpJsNode (addrs, hop, callback) { hop = false } - df.spawn({ - type: 'js', + jsDf.spawn({ config: Object.assign({}, baseConf, { Addresses: { Swarm: addrs @@ -84,8 +83,8 @@ function setUpJsNode (addrs, hop, callback) { }) }, (err, ipfsd) => { expect(err).to.not.exist() - ipfsd.api.swarm.localAddrs((err, addrs) => { - callback(err, { ipfsd, addrs: circuitFilter(addrs) }) + ipfsd.api.id((err, id) => { + callback(err, { ipfsd, addrs: circuitFilter(id.addresses) }) }) }) } @@ -96,7 +95,7 @@ function setUpGoNode (addrs, hop, callback) { hop = false } - df.spawn({ + goDf.spawn({ config: Object.assign({}, baseConf, { Addresses: { Swarm: addrs @@ -114,17 +113,6 @@ function setUpGoNode (addrs, hop, callback) { }) } -function addAndCat (node1, node2, data, callback) { - waterfall([ - (cb) => node1.files.add(data, cb), - (res, cb) => node2.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], callback) -} - const circuitFilter = (addrs) => addrs.map((a) => a.toString()).filter((a) => !a.includes('/p2p-circuit')) const wsAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/ws')) const tcpAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => !a.includes('/ws')) @@ -135,16 +123,17 @@ function tests (relayType) { let goTCP let goTCPAddr - let jsWSAddr let jsWS + let jsWSAddr let jsWSCircuitAddr let nodes - before((done) => { + + before(function (done) { parallel([ (cb) => setUpGoNode([`${base}/35003`], cb), (cb) => setUpJsNode([`${base}/35004/ws`], cb) - ], (err, res) => { + ], function (err, res) { expect(err).to.not.exist() nodes = res.map((node) => node.ipfsd) @@ -161,18 +150,26 @@ function tests (relayType) { after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - it('should connect and transfer', function (done) { - const data = crypto.randomBytes(128) + it('should connect', function (done) { series([ (cb) => this.relay.api.swarm.connect(goTCPAddr, cb), (cb) => setTimeout(cb, 1000), (cb) => this.relay.api.swarm.connect(jsWSAddr, cb), (cb) => setTimeout(cb, 1000), (cb) => goTCP.swarm.connect(jsWSCircuitAddr, cb) - ], (err) => { - expect(err).to.not.exist() - addAndCat(goTCP, jsWS, data, done) - }) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => goTCP.files.add(data, cb), + (res, cb) => jsWS.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) }) }) @@ -207,18 +204,26 @@ function tests (relayType) { after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - it('should connect and transfer', function (done) { - const data = crypto.randomBytes(128) + it('should connect', function (done) { series([ (cb) => this.relay.api.swarm.connect(jsTCPAddr, cb), (cb) => setTimeout(cb, 1000), (cb) => this.relay.api.swarm.connect(jsWSAddr, cb), (cb) => setTimeout(cb, 1000), (cb) => jsWS.swarm.connect(jsTCPCircuitAddr, cb) - ], (err) => { - expect(err).to.not.exist() - addAndCat(jsTCP, jsWS, data, done) - }) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => jsTCP.files.add(data, cb), + (res, cb) => jsWS.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) }) }) @@ -253,18 +258,26 @@ function tests (relayType) { after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - it('should connect and transfer', function (done) { - const data = crypto.randomBytes(128) + it('should connect', function (done) { series([ (cb) => this.relay.api.swarm.connect(goTCPAddr, cb), (cb) => setTimeout(cb, 1000), (cb) => this.relay.api.swarm.connect(goWSAddr, cb), (cb) => setTimeout(cb, 1000), (cb) => goWS.swarm.connect(goTCPCircuitAddr, cb) - ], (err) => { - expect(err).to.not.exist() - addAndCat(goTCP, goWS, data, done) - }) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => goTCP.files.add(data, cb), + (res, cb) => goWS.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) }) }) @@ -287,28 +300,34 @@ function tests (relayType) { (cb) => setupInProcNode([], false, cb) ], (err, nodes) => { expect(err).to.not.exist() - browserNode1 = nodes[0] - browserNode2 = nodes[1] - browserNode2.id((err, id) => { - expect(err).to.not.exist() - browserNode2Addrs = id.addresses - done() - }) + browserNode1 = nodes[0].ipfsd.api + browserNode2 = nodes[1].ipfsd.api + + browserNode2Addrs = nodes[1].addrs + done() }) }) - it('should connect and transfer', function (done) { - const data = crypto.randomBytes(128) + it('should connect', function (done) { series([ (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), (cb) => browserNode2.swarm.connect(wsAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), (cb) => browserNode1.swarm.connect(browserNode2Addrs[0], cb) - ], (err) => { - expect(err).to.not.exist() - addAndCat(browserNode1, browserNode2, data, done) - }) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => browserNode1.files.add(data, cb), + (res, cb) => browserNode2.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) }) }) @@ -341,17 +360,25 @@ function tests (relayType) { after((done) => jsTCP.stop(done)) it('should connect and transfer', function (done) { - const data = crypto.randomBytes(128) series([ (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), (cb) => jsTCP.api.swarm.connect(tcpAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), (cb) => browserNode1.swarm.connect(jsTCPAddrs[0], cb) - ], (err) => { - expect(err).to.not.exist() - addAndCat(browserNode1, jsTCP.api, data, done) - }) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => browserNode1.files.add(data, cb), + (res, cb) => jsTCP.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) }) }) @@ -384,31 +411,39 @@ function tests (relayType) { after((done) => goTCP.stop(done)) - it('should connect and transfer', function (done) { - const data = crypto.randomBytes(128) + it('should connect', function (done) { series([ (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), (cb) => goTCP.api.swarm.connect(tcpAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), (cb) => browserNode1.swarm.connect(goTCPAddrs[0], cb) - ], (err) => { - expect(err).to.not.exist() - addAndCat(browserNode1, goTCP.api, data, done) - }) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => browserNode1.files.add(data, cb), + (res, cb) => goTCP.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) }) }) } -describe('circuit', () => { +describe.only('circuit', () => { describe('js relay', function () { this.relay = null this.relayAddrs = null - beforeEach(function (done) { + before(function (done) { this.timeout(50 * 1000) - setUpJsNode([`${base}/35002`, `${base}/35001/ws`], true, (err, res) => { + setUpJsNode([`${base}/35001/ws`, `${base}/35002`], true, (err, res) => { expect(err).to.not.exist() this.relay = res.ipfsd this.relayAddrs = res.addrs @@ -416,7 +451,7 @@ describe('circuit', () => { }) }) - afterEach(function (done) { this.relay.stop(done) }) + after(function (done) { this.relay.stop(done) }) describe('test js relay', function () { tests('jsRelay') @@ -427,10 +462,10 @@ describe('circuit', () => { this.relay = null this.relayAddrs = null - beforeEach(function (done) { + before(function (done) { this.timeout(50 * 1000) - setUpGoNode([`${base}/35002`, `${base}/35001/ws`], true, (err, res) => { + setUpGoNode([`${base}/35001/ws`, `${base}/35002`], true, (err, res) => { expect(err).to.not.exist() this.relay = res.ipfsd this.relayAddrs = res.addrs @@ -438,7 +473,7 @@ describe('circuit', () => { }) }) - afterEach(function (done) { this.relay.stop(done) }) + after(function (done) { this.relay.stop(done) }) describe('test go relay', function () { tests('goRelay') diff --git a/test/pubsub.js b/test/pubsub.js index 3a312bd3..b81a9c95 100644 --- a/test/pubsub.js +++ b/test/pubsub.js @@ -10,7 +10,6 @@ const series = require('async/series') const parallel = require('async/parallel') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() /* * Wait for a condition to become true. When its true, callback is called. From 4052ffa415689add2fd9d41f69d652512af4583b Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 17 Jan 2018 14:07:20 -0600 Subject: [PATCH 04/49] chore: upping ipfsd-ctl version --- .aegir.js | 2 +- test/circuit-relay.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.aegir.js b/.aegir.js index d107bb3b..f11e51ff 100644 --- a/.aegir.js +++ b/.aegir.js @@ -11,7 +11,7 @@ module.exports = { served: true, included: false }], - singleRun: false, + singleRun: true, browserNoActivityTimeout: 100 * 1000 }, hooks: { diff --git a/test/circuit-relay.js b/test/circuit-relay.js index 0f0a763c..62cb3946 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -435,7 +435,7 @@ function tests (relayType) { }) } -describe.only('circuit', () => { +describe('circuit', () => { describe('js relay', function () { this.relay = null this.relayAddrs = null From e4445398690b08406a0e5037800681b8125c960a Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 17 Jan 2018 15:29:58 -0600 Subject: [PATCH 05/49] test: increase timeouts --- test/exchange-files.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/test/exchange-files.js b/test/exchange-files.js index 076bef6e..3cd36db1 100644 --- a/test/exchange-files.js +++ b/test/exchange-files.js @@ -54,7 +54,7 @@ describe('exchange files', () => { let nodes before(function (done) { - this.timeout(100 * 1000) + this.timeout(50 * 1000) parallel([ (cb) => df.spawn({ initOptions: { bits: 1024 } }, cb), @@ -73,7 +73,7 @@ describe('exchange files', () => { after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) it('connect go <-> js', function (done) { - this.timeout(500 * 1000) + this.timeout(50 * 1000) let jsId let goId @@ -103,7 +103,7 @@ describe('exchange files', () => { }) it('connect js <-> js', function (done) { - this.timeout(500 * 1000) + this.timeout(50 * 1000) let jsId let js2Id @@ -133,7 +133,8 @@ describe('exchange files', () => { }) describe('cat file', () => sizes.forEach((size) => { - it(`go -> js: ${pretty(size)}`, (done) => { + it(`go -> js: ${pretty(size)}`, function (done) { + this.timeout(50 * 1000) const data = crypto.randomBytes(size) waterfall([ (cb) => goDaemon.api.add(data, cb), @@ -145,7 +146,8 @@ describe('exchange files', () => { }) }) - it(`js -> go: ${pretty(size)}`, (done) => { + it(`js -> go: ${pretty(size)}`, function (done) { + this.timeout(50 * 1000) const data = crypto.randomBytes(size) waterfall([ (cb) => jsDaemon.api.add(data, cb), @@ -157,7 +159,8 @@ describe('exchange files', () => { }) }) - it(`js -> js: ${pretty(size)}`, (done) => { + it(`js -> js: ${pretty(size)}`, function (done) { + this.timeout(20 * 1000) const data = crypto.randomBytes(size) waterfall([ (cb) => js2Daemon.api.add(data, cb), @@ -173,7 +176,7 @@ 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}`, function () { - this.timeout(10 * 1000) + this.timeout(50 * 1000) const dir = tmpDir() return randomFs({ path: dir, @@ -191,7 +194,7 @@ describe('exchange files', () => { }) it(`js -> go: depth: 5, num: ${num}`, function () { - this.timeout(10 * 1000) + this.timeout(50 * 1000) const dir = tmpDir() return randomFs({ @@ -210,7 +213,7 @@ describe('exchange files', () => { }) it(`js -> js: depth: 5, num: ${num}`, function () { - this.timeout(50 * 1000) + this.timeout(80 * 1000) const dir = tmpDir() return randomFs({ From 21eaeac76296ffd6da053438083298917ac3b8bc Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 17 Jan 2018 23:26:07 -0600 Subject: [PATCH 06/49] test: fixing circuit tests --- test/circuit-relay.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/test/circuit-relay.js b/test/circuit-relay.js index 62cb3946..9679c765 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -56,7 +56,7 @@ function setupInProcNode (factory, addrs, hop, callback) { }, (err, ipfsd) => { expect(err).to.not.exist() ipfsd.api.id((err, id) => { - callback(err, { ipfsd, addrs: circuitFilter(id.addresses) }) + callback(err, { ipfsd, addrs: id.addresses }) }) }) } @@ -84,7 +84,7 @@ function setUpJsNode (addrs, hop, callback) { }, (err, ipfsd) => { expect(err).to.not.exist() ipfsd.api.id((err, id) => { - callback(err, { ipfsd, addrs: circuitFilter(id.addresses) }) + callback(err, { ipfsd, addrs: id.addresses }) }) }) } @@ -108,12 +108,11 @@ function setUpGoNode (addrs, hop, callback) { }, (err, ipfsd) => { expect(err).to.not.exist() ipfsd.api.id((err, id) => { - callback(err, { ipfsd, addrs: circuitFilter(id.addresses) }) + callback(err, { ipfsd, addrs: id.addresses }) }) }) } -const circuitFilter = (addrs) => addrs.map((a) => a.toString()).filter((a) => !a.includes('/p2p-circuit')) const wsAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/ws')) const tcpAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => !a.includes('/ws')) @@ -340,6 +339,7 @@ function tests (relayType) { let browserNode1 let jsTCP + let jsTCPNode let jsTCPAddrs before(function (done) { @@ -348,22 +348,23 @@ function tests (relayType) { (cb) => setUpJsNode([`${base}/35003`], cb) ], (err, nodes) => { expect(err).to.not.exist() - browserNode1 = nodes[0] - jsTCP = nodes[1].ipfsd + browserNode1 = nodes[0].ipfsd.api + jsTCP = nodes[1].ipfsd.api + jsTCPNode = nodes[1].ipfsd jsTCPAddrs = nodes[1].addrs done() }) }) - after((done) => jsTCP.stop(done)) + after((done) => jsTCPNode.stop(done)) - it('should connect and transfer', function (done) { + it('should connect', function (done) { series([ (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), - (cb) => jsTCP.api.swarm.connect(tcpAddr(this.relayAddrs), cb), + (cb) => jsTCP.swarm.connect(tcpAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), (cb) => browserNode1.swarm.connect(jsTCPAddrs[0], cb) ], done) @@ -391,6 +392,7 @@ function tests (relayType) { let browserNode1 let goTCP + let goTCPNode let goTCPAddrs before(function (done) { @@ -400,22 +402,22 @@ function tests (relayType) { ], (err, nodes) => { expect(err).to.not.exist() - browserNode1 = nodes[0] - - goTCP = nodes[1].ipfsd + browserNode1 = nodes[0].ipfsd.api + goTCP = nodes[1].ipfsd.api + goTCPNode = nodes[1].ipfsd goTCPAddrs = nodes[1].addrs done() }) }) - after((done) => goTCP.stop(done)) + after((done) => goTCPNode.stop(done)) it('should connect', function (done) { series([ (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), - (cb) => goTCP.api.swarm.connect(tcpAddr(this.relayAddrs), cb), + (cb) => goTCP.swarm.connect(tcpAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), (cb) => browserNode1.swarm.connect(goTCPAddrs[0], cb) ], done) From 6cc1628381819dcab1908e2c956ef39bbbb9c95c Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Thu, 18 Jan 2018 10:04:23 -0600 Subject: [PATCH 07/49] test: run kad-dht tests in browser --- test/browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/browser.js b/test/browser.js index 48a8a5d8..fdc32cc4 100644 --- a/test/browser.js +++ b/test/browser.js @@ -3,6 +3,6 @@ // require('./exchange-files') // require('./pubsub') -// require('./kad-dht') +require('./kad-dht') require('./circuit-relay') require('./repo') From 4b8907bbf0418147b287a7e728c4c6745f3ddc98 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 24 Jan 2018 09:52:33 -0600 Subject: [PATCH 08/49] wip: adding browser relay tests --- test/circuit-relay.js | 269 +++++++++++++++++++++++------------------- 1 file changed, 149 insertions(+), 120 deletions(-) diff --git a/test/circuit-relay.js b/test/circuit-relay.js index 9679c765..caba1ec4 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -33,7 +33,7 @@ const baseConf = { const base = '/ip4/127.0.0.1/tcp' -function setupInProcNode (factory, addrs, hop, callback) { +function setupInProcNode (addrs, hop, callback) { if (typeof hop === 'function') { callback = hop hop = false @@ -116,32 +116,32 @@ function setUpGoNode (addrs, hop, callback) { const wsAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/ws')) const tcpAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => !a.includes('/ws')) -function tests (relayType) { - describe(`jsWS <-> ${relayType} <-> goTCP`, function () { - this.timeout(50 * 1000) +function tests (relay, parseAddrA, parseAddrB) { + describe(`js <-> ${relay} relay <-> go`, function () { + this.timeout(80 * 1000) - let goTCP - let goTCPAddr - let jsWS - let jsWSAddr - let jsWSCircuitAddr + let nodeA + let nodeAAddr + let nodeB + let nodeBAddr + let nodeBCircuitAddr let nodes - before(function (done) { parallel([ - (cb) => setUpGoNode([`${base}/35003`], cb), - (cb) => setUpJsNode([`${base}/35004/ws`], cb) + (cb) => setUpGoNode([this.addrA], cb), + (cb) => setUpJsNode([this.addrB], cb) ], function (err, res) { expect(err).to.not.exist() nodes = res.map((node) => node.ipfsd) - goTCPAddr = tcpAddr(res[0].addrs) - goTCP = res[0].ipfsd.api + nodeAAddr = parseAddrA(res[0].addrs) + nodeA = res[0].ipfsd.api + + nodeBAddr = parseAddrB(res[1].addrs) - jsWSAddr = wsAddr(res[1].addrs) - jsWS = res[1].ipfsd.api - jsWSCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(jsWSAddr).getPeerId()}` + nodeB = res[1].ipfsd.api + nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeBAddr).getPeerId()}` done() }) @@ -151,19 +151,19 @@ function tests (relayType) { it('should connect', function (done) { series([ - (cb) => this.relay.api.swarm.connect(goTCPAddr, cb), + (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), (cb) => setTimeout(cb, 1000), - (cb) => this.relay.api.swarm.connect(jsWSAddr, cb), + (cb) => this.relay.api.swarm.connect(nodeBAddr, cb), (cb) => setTimeout(cb, 1000), - (cb) => goTCP.swarm.connect(jsWSCircuitAddr, cb) + (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) ], done) }) it('should transfer', function (done) { const data = crypto.randomBytes(128) waterfall([ - (cb) => goTCP.files.add(data, cb), - (res, cb) => jsWS.files.cat(res[0].hash, cb), + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), (buffer, cb) => { expect(buffer).to.deep.equal(data) cb() @@ -172,30 +172,30 @@ function tests (relayType) { }) }) - describe(`jsWS <-> ${relayType} <-> jsTCP`, function () { - this.timeout(50 * 1000) - let jsTCP - let jsTCPAddr + describe(`js <-> ${relay} relay <-> js`, function () { + this.timeout(80 * 1000) + let nodeA + let nodeAAddr - let jsWS - let jsWSAddr - let jsTCPCircuitAddr + let nodeB + let nodeBAddr + let nodeBCircuitAddr let nodes - before((done) => { + before(function (done) { parallel([ - (cb) => setUpJsNode([`${base}/35003`], cb), - (cb) => setUpJsNode([`${base}/35004/ws`], cb) + (cb) => setUpJsNode([this.addrA], cb), + (cb) => setUpJsNode([this.addrB], cb) ], (err, res) => { expect(err).to.not.exist() nodes = res.map((node) => node.ipfsd) - jsTCP = res[0].ipfsd.api - jsTCPAddr = tcpAddr(res[0].addrs) - jsTCPCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(jsTCPAddr).getPeerId()}` + nodeA = res[0].ipfsd.api + nodeAAddr = parseAddrA(res[0].addrs) + nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeAAddr).getPeerId()}` - jsWS = res[1].ipfsd.api - jsWSAddr = wsAddr(res[1].addrs) + nodeB = res[1].ipfsd.api + nodeBAddr = parseAddrB(res[1].addrs) done() }) @@ -205,19 +205,19 @@ function tests (relayType) { it('should connect', function (done) { series([ - (cb) => this.relay.api.swarm.connect(jsTCPAddr, cb), + (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), (cb) => setTimeout(cb, 1000), - (cb) => this.relay.api.swarm.connect(jsWSAddr, cb), + (cb) => this.relay.api.swarm.connect(nodeBAddr, cb), (cb) => setTimeout(cb, 1000), - (cb) => jsWS.swarm.connect(jsTCPCircuitAddr, cb) + (cb) => nodeB.swarm.connect(nodeBCircuitAddr, cb) ], done) }) it('should transfer', function (done) { const data = crypto.randomBytes(128) waterfall([ - (cb) => jsTCP.files.add(data, cb), - (res, cb) => jsWS.files.cat(res[0].hash, cb), + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), (buffer, cb) => { expect(buffer).to.deep.equal(data) cb() @@ -226,30 +226,30 @@ function tests (relayType) { }) }) - describe(`goWS <-> ${relayType} <-> goTCP`, function () { - this.timeout(50 * 1000) - let goTCP - let goTCPAddr - let goTCPCircuitAddr + describe(`go <-> ${relay} relay <-> go`, function () { + this.timeout(80 * 1000) + let nodeA + let nodeAAddr + let nodeACircuitAddr - let goWS - let goWSAddr + let nodeB + let nodeBAddr let nodes - before((done) => { + before(function (done) { parallel([ - (cb) => setUpGoNode([`${base}/35003`], cb), - (cb) => setUpGoNode([`${base}/35004/ws`], cb) + (cb) => setUpGoNode([this.addrA], cb), + (cb) => setUpGoNode([this.addrB], cb) ], (err, res) => { expect(err).to.not.exist() nodes = res.map((node) => node.ipfsd) - goTCP = res[0].ipfsd.api - goTCPAddr = tcpAddr(res[0].addrs) - goTCPCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(goTCPAddr).getPeerId()}` + nodeA = res[0].ipfsd.api + nodeAAddr = parseAddrA(res[0].addrs) + nodeACircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeAAddr).getPeerId()}` - goWS = res[1].ipfsd.api - goWSAddr = wsAddr(res[1].addrs) + nodeB = res[1].ipfsd.api + nodeBAddr = parseAddrB(res[1].addrs) done() }) @@ -259,19 +259,19 @@ function tests (relayType) { it('should connect', function (done) { series([ - (cb) => this.relay.api.swarm.connect(goTCPAddr, cb), + (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), (cb) => setTimeout(cb, 1000), - (cb) => this.relay.api.swarm.connect(goWSAddr, cb), + (cb) => this.relay.api.swarm.connect(nodeBAddr, cb), (cb) => setTimeout(cb, 1000), - (cb) => goWS.swarm.connect(goTCPCircuitAddr, cb) + (cb) => nodeB.swarm.connect(nodeACircuitAddr, cb) ], done) }) it('should transfer', function (done) { const data = crypto.randomBytes(128) waterfall([ - (cb) => goTCP.files.add(data, cb), - (res, cb) => goWS.files.cat(res[0].hash, cb), + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), (buffer, cb) => { expect(buffer).to.deep.equal(data) cb() @@ -280,48 +280,51 @@ function tests (relayType) { }) }) - describe(`browser <-> ${relayType} <-> browser`, function () { + describe(`js <-> ${relay} relay <-> browser`, function () { if (isNode) { return } - this.timeout(90 * 1000) - - let browserNode1 - let browserNode2 + this.timeout(80 * 1000) - // let browserNodeId1 - let browserNode2Addrs + let nodeA + let nodeB + let nodeBIpfsd + let nodeBAddr before(function (done) { parallel([ (cb) => setupInProcNode([], false, cb), - (cb) => setupInProcNode([], false, cb) + (cb) => setUpJsNode([this.addrA], cb) ], (err, nodes) => { expect(err).to.not.exist() - browserNode1 = nodes[0].ipfsd.api - browserNode2 = nodes[1].ipfsd.api - browserNode2Addrs = nodes[1].addrs + nodeA = nodes[0].ipfsd.api + nodeB = nodes[1].ipfsd.api + nodeBIpfsd = nodes[1].ipfsd + nodeBAddr = nodes[1].addrs + done() }) }) + after((done) => nodeBIpfsd.stop(done)) + it('should connect', function (done) { series([ - (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => nodeA.swarm.connect(wsAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), - (cb) => browserNode2.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => nodeB.swarm.connect(tcpAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), - (cb) => browserNode1.swarm.connect(browserNode2Addrs[0], cb) + (cb) => nodeA.swarm.connect(nodeBAddr[0], cb) ], done) }) it('should transfer', function (done) { const data = crypto.randomBytes(128) waterfall([ - (cb) => browserNode1.files.add(data, cb), - (res, cb) => browserNode2.files.cat(res[0].hash, cb), + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), (buffer, cb) => { expect(buffer).to.deep.equal(data) cb() @@ -330,51 +333,51 @@ function tests (relayType) { }) }) - describe(`jsTCP <-> ${relayType} <-> browser`, function () { + describe(`go <-> ${relay} relay <-> browser`, function () { if (isNode) { return } - this.timeout(50 * 1000) + this.timeout(80 * 1000) - let browserNode1 - let jsTCP - let jsTCPNode - let jsTCPAddrs + let nodeA + let nodeB + let nodeBIpfsd + let nodeBAddrs before(function (done) { parallel([ (cb) => setupInProcNode([], false, cb), - (cb) => setUpJsNode([`${base}/35003`], cb) + (cb) => setUpGoNode([this.addrA], cb) ], (err, nodes) => { expect(err).to.not.exist() - browserNode1 = nodes[0].ipfsd.api - jsTCP = nodes[1].ipfsd.api - jsTCPNode = nodes[1].ipfsd - jsTCPAddrs = nodes[1].addrs + nodeA = nodes[0].ipfsd.api + nodeB = nodes[1].ipfsd.api + nodeBIpfsd = nodes[1].ipfsd + nodeBAddrs = nodes[1].addrs done() }) }) - after((done) => jsTCPNode.stop(done)) + after((done) => nodeBIpfsd.stop(done)) it('should connect', function (done) { series([ - (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => nodeA.swarm.connect(wsAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), - (cb) => jsTCP.swarm.connect(tcpAddr(this.relayAddrs), cb), + (cb) => nodeB.swarm.connect(tcpAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), - (cb) => browserNode1.swarm.connect(jsTCPAddrs[0], cb) + (cb) => nodeA.swarm.connect(nodeBAddrs[0], cb) ], done) }) it('should transfer', function (done) { const data = crypto.randomBytes(128) waterfall([ - (cb) => browserNode1.files.add(data, cb), - (res, cb) => jsTCP.files.cat(res[0].hash, cb), + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), (buffer, cb) => { expect(buffer).to.deep.equal(data) cb() @@ -383,51 +386,48 @@ function tests (relayType) { }) }) - describe(`goTCP <-> ${relayType} <-> browser`, function () { - if (isNode) { + describe(`browser <-> ${relay} relay <-> browser`, function () { + if (isNode || relay === 'browser') { return } - this.timeout(50 * 1000) + this.timeout(90 * 1000) + + let nodeA + let nodeB - let browserNode1 - let goTCP - let goTCPNode - let goTCPAddrs + // let nodeAId1 + let nodeBAddrs before(function (done) { parallel([ (cb) => setupInProcNode([], false, cb), - (cb) => setUpGoNode([`${base}/35003`], cb) + (cb) => setupInProcNode([], false, cb) ], (err, nodes) => { expect(err).to.not.exist() + nodeA = nodes[0].ipfsd.api + nodeB = nodes[1].ipfsd.api - browserNode1 = nodes[0].ipfsd.api - goTCP = nodes[1].ipfsd.api - goTCPNode = nodes[1].ipfsd - goTCPAddrs = nodes[1].addrs - + nodeBAddrs = nodes[1].addrs done() }) }) - after((done) => goTCPNode.stop(done)) - it('should connect', function (done) { series([ - (cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => nodeA.swarm.connect(wsAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), - (cb) => goTCP.swarm.connect(tcpAddr(this.relayAddrs), cb), + (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), (cb) => setTimeout(cb, 1000), - (cb) => browserNode1.swarm.connect(goTCPAddrs[0], cb) + (cb) => nodeA.swarm.connect(nodeBAddrs[0], cb) ], done) }) it('should transfer', function (done) { const data = crypto.randomBytes(128) waterfall([ - (cb) => browserNode1.files.add(data, cb), - (res, cb) => goTCP.files.cat(res[0].hash, cb), + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), (buffer, cb) => { expect(buffer).to.deep.equal(data) cb() @@ -445,6 +445,9 @@ describe('circuit', () => { before(function (done) { this.timeout(50 * 1000) + this.addrA = `${base}/35003` + this.addrB = `${base}/35004/ws` + setUpJsNode([`${base}/35001/ws`, `${base}/35002`], true, (err, res) => { expect(err).to.not.exist() this.relay = res.ipfsd @@ -455,9 +458,7 @@ describe('circuit', () => { after(function (done) { this.relay.stop(done) }) - describe('test js relay', function () { - tests('jsRelay') - }) + tests('js', tcpAddr, wsAddr) }) describe('go relay', function () { @@ -467,6 +468,9 @@ describe('circuit', () => { before(function (done) { this.timeout(50 * 1000) + this.addrA = `${base}/35003` + this.addrB = `${base}/35004/ws` + setUpGoNode([`${base}/35001/ws`, `${base}/35002`], true, (err, res) => { expect(err).to.not.exist() this.relay = res.ipfsd @@ -477,8 +481,33 @@ describe('circuit', () => { after(function (done) { this.relay.stop(done) }) - describe('test go relay', function () { - tests('goRelay') + tests('go', tcpAddr, wsAddr) + }) + + describe('browser relay', function () { + if (isNode) { + return + } + + this.relay = null + this.relayAddrs = null + + before(function (done) { + this.timeout(50 * 1000) + + this.addrA = `${base}/35003/ws` + this.addrB = `${base}/35004/ws` + + setupInProcNode([], true, (err, res) => { + expect(err).to.not.exist() + this.relay = res.ipfsd + this.relayAddrs = res.addrs + done() + }) }) + + after(function (done) { this.relay.stop(done) }) + + tests('browser', wsAddr, wsAddr) }) }) From d40a5bfde00ef5c41377d1988df4c479c8450f05 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Thu, 25 Jan 2018 12:07:09 -0600 Subject: [PATCH 09/49] increase timeouts --- test/circuit-relay.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/circuit-relay.js b/test/circuit-relay.js index caba1ec4..d9e9e1ad 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -285,7 +285,7 @@ function tests (relay, parseAddrA, parseAddrB) { return } - this.timeout(80 * 1000) + this.timeout(90 * 1000) let nodeA let nodeB @@ -338,7 +338,7 @@ function tests (relay, parseAddrA, parseAddrB) { return } - this.timeout(80 * 1000) + this.timeout(90 * 1000) let nodeA let nodeB From 9243b657a2cb799cef38e924dfdbcefb8352fac2 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 26 Jan 2018 21:12:31 -0600 Subject: [PATCH 10/49] feat: add missing circuit tests from node runs --- test/node.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/node.js b/test/node.js index f42c5a11..d14777e4 100644 --- a/test/node.js +++ b/test/node.js @@ -1,6 +1,7 @@ /* eslint-env mocha */ 'use strict' +require('./circuit-relay') require('./repo') require('./exchange-files') require('./kad-dht') From 7a623884bee873971f8cc3d765b6f0704209507a Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 08:39:10 -0600 Subject: [PATCH 11/49] fix: avoid using default API and Gateway ports --- test/circuit-relay.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/circuit-relay.js b/test/circuit-relay.js index d9e9e1ad..dd51020d 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -23,6 +23,10 @@ const procDf = DaemonFactory.create({ type: 'proc', exec: IPFS }) const baseConf = { Bootstrap: [], + Addresses: { + API: '/ipv4/0.0.0.0/tcp/0', + Gateway: '/ipv4/0.0.0.0/tcp/0' + }, Discovery: { MDNS: { Enabled: From c61c5fde79d8a55e151336be1c3ba7a3e49a1505 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 08:58:45 -0600 Subject: [PATCH 12/49] feat: adding go to js test --- test/circuit-relay.js | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/circuit-relay.js b/test/circuit-relay.js index dd51020d..bdd5a1aa 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -284,6 +284,60 @@ function tests (relay, parseAddrA, parseAddrB) { }) }) + describe(`go <-> ${relay} relay <-> js`, function () { + this.timeout(80 * 1000) + let nodeA + let nodeAAddr + let nodeACircuitAddr + + let nodeB + let nodeBAddr + + let nodes + before(function (done) { + parallel([ + (cb) => setUpGoNode([this.addrA], cb), + (cb) => setUpJsNode([this.addrB], cb) + ], (err, res) => { + expect(err).to.not.exist() + nodes = res.map((node) => node.ipfsd) + + nodeA = res[0].ipfsd.api + nodeAAddr = parseAddrA(res[0].addrs) + nodeACircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeAAddr).getPeerId()}` + + nodeB = res[1].ipfsd.api + nodeBAddr = parseAddrB(res[1].addrs) + + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('should connect', function (done) { + series([ + (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => this.relay.api.swarm.connect(nodeBAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeB.swarm.connect(nodeACircuitAddr, cb) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) + }) + }) + describe(`js <-> ${relay} relay <-> browser`, function () { if (isNode) { return From 90b7320a429c67e7e114cfa975b518338cef795d Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 09:21:50 -0600 Subject: [PATCH 13/49] fix: /ipv4 -> /ip4 --- test/circuit-relay.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/circuit-relay.js b/test/circuit-relay.js index bdd5a1aa..dc782fe8 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -24,8 +24,8 @@ const procDf = DaemonFactory.create({ type: 'proc', exec: IPFS }) const baseConf = { Bootstrap: [], Addresses: { - API: '/ipv4/0.0.0.0/tcp/0', - Gateway: '/ipv4/0.0.0.0/tcp/0' + API: '/ip4/0.0.0.0/tcp/0', + Gateway: '/ip4/0.0.0.0/tcp/0' }, Discovery: { MDNS: { From e4e1790f3285def22ef058e4ca997f09033f8f8e Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 10:51:17 -0600 Subject: [PATCH 14/49] fix: cant relay if both the relay and one of the nodes are browser --- test/circuit-relay.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/circuit-relay.js b/test/circuit-relay.js index dc782fe8..7611bbed 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -339,7 +339,7 @@ function tests (relay, parseAddrA, parseAddrB) { }) describe(`js <-> ${relay} relay <-> browser`, function () { - if (isNode) { + if (relay === 'browser') { return } @@ -392,7 +392,7 @@ function tests (relay, parseAddrA, parseAddrB) { }) describe(`go <-> ${relay} relay <-> browser`, function () { - if (isNode) { + if (relay === 'browser') { return } @@ -445,7 +445,7 @@ function tests (relay, parseAddrA, parseAddrB) { }) describe(`browser <-> ${relay} relay <-> browser`, function () { - if (isNode || relay === 'browser') { + if (relay === 'browser') { return } From 46f172f9159d116c55d7d8e4a93280a9e0dfdcce Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 13:09:39 -0600 Subject: [PATCH 15/49] test: skip `get directory` tests on windows --- test/exchange-files.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/exchange-files.js b/test/exchange-files.js index 3cd36db1..d1748845 100644 --- a/test/exchange-files.js +++ b/test/exchange-files.js @@ -17,6 +17,8 @@ const join = require('path').join const os = require('os') const hat = require('hat') +const isWindows = os.platform() === 'win32' + const rmDir = promisify(rimraf) const DaemonFactory = require('ipfsd-ctl') @@ -175,6 +177,11 @@ describe('exchange files', () => { // TODO these tests are not fetching the full dir?? describe('get directory', () => dirs.forEach((num) => { + // skipping until https://github.com/ipfs/interop/issues/9 is addressed + if (isWindows) { + return + } + it(`go -> js: depth: 5, num: ${num}`, function () { this.timeout(50 * 1000) const dir = tmpDir() From 98a7d0477e3f2a15b2292ae045ee0e820596f92b Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 16:16:46 -0600 Subject: [PATCH 16/49] fix: skip repo tests on windows --- test/repo.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/repo.js b/test/repo.js index 83a8edd8..4177e69a 100644 --- a/test/repo.js +++ b/test/repo.js @@ -12,6 +12,8 @@ const os = require('os') const path = require('path') const hat = require('hat') +const isWindows = os.platform() === 'win32' + const DaemonFactory = require('ipfsd-ctl') const df = DaemonFactory.create() @@ -24,6 +26,11 @@ function catAndCheck (api, hash, data, callback) { } describe('repo', () => { + // skipping until https://github.com/ipfs/interop/issues/8 is addressed + if (isWindows) { + return + } + it('read repo: go -> js', function (done) { this.timeout(50 * 1000) From e9e8f73b6dfcf1fadb6e0ec51625029afc672250 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 18:45:01 -0600 Subject: [PATCH 17/49] fix: skip browser tests in node --- test/circuit-relay.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/circuit-relay.js b/test/circuit-relay.js index 7611bbed..8b7fb145 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -339,7 +339,7 @@ function tests (relay, parseAddrA, parseAddrB) { }) describe(`js <-> ${relay} relay <-> browser`, function () { - if (relay === 'browser') { + if (isNode || relay === 'browser') { return } @@ -392,7 +392,7 @@ function tests (relay, parseAddrA, parseAddrB) { }) describe(`go <-> ${relay} relay <-> browser`, function () { - if (relay === 'browser') { + if (isNode || relay === 'browser') { return } @@ -445,7 +445,7 @@ function tests (relay, parseAddrA, parseAddrB) { }) describe(`browser <-> ${relay} relay <-> browser`, function () { - if (relay === 'browser') { + if (isNode || relay === 'browser') { return } From 655be3176fe9624a2ab9b19a94aa36989eed6048 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 19:54:04 -0600 Subject: [PATCH 18/49] fix: remove repo tests from browser runs --- test/browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/browser.js b/test/browser.js index fdc32cc4..21715fe8 100644 --- a/test/browser.js +++ b/test/browser.js @@ -5,4 +5,4 @@ // require('./pubsub') require('./kad-dht') require('./circuit-relay') -require('./repo') +// require('./repo') From 9f91929b93d0c6bb3f91f1dd831ac9581f009569 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 20:07:26 -0600 Subject: [PATCH 19/49] fix: timeouts --- test/circuit-relay.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/circuit-relay.js b/test/circuit-relay.js index 8b7fb145..97e04037 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -396,7 +396,7 @@ function tests (relay, parseAddrA, parseAddrB) { return } - this.timeout(90 * 1000) + this.timeout(100 * 1000) let nodeA let nodeB From 4dd9b5f18e9cf927d7ab2d74959f4f8c449c2866 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 21:09:51 -0600 Subject: [PATCH 20/49] fix: timeouts --- test/circuit-relay.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/circuit-relay.js b/test/circuit-relay.js index 97e04037..9a13c817 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -343,7 +343,7 @@ function tests (relay, parseAddrA, parseAddrB) { return } - this.timeout(90 * 1000) + this.timeout(100 * 1000) let nodeA let nodeB @@ -449,7 +449,7 @@ function tests (relay, parseAddrA, parseAddrB) { return } - this.timeout(90 * 1000) + this.timeout(100 * 1000) let nodeA let nodeB From b124d282f2e67cb36a61182e4834463ce5340150 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 29 Jan 2018 22:20:51 -0600 Subject: [PATCH 21/49] feat: increase browser inactivity timeout to make windows hapy --- .aegir.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.aegir.js b/.aegir.js index f11e51ff..91ffb8a9 100644 --- a/.aegir.js +++ b/.aegir.js @@ -12,7 +12,7 @@ module.exports = { included: false }], singleRun: true, - browserNoActivityTimeout: 100 * 1000 + browserNoActivityTimeout: 150 * 1000 }, hooks: { browser: { From d504b65595e43173b02edd9cb7455a346eca9c79 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 30 Jan 2018 17:31:59 -0600 Subject: [PATCH 22/49] feat: adding all missing browser tests --- .aegir.js | 28 +- package.json | 4 +- test/circuit-relay.js | 616 ++++++++++++++++++++++++++++++------------ 3 files changed, 475 insertions(+), 173 deletions(-) diff --git a/.aegir.js b/.aegir.js index 91ffb8a9..25d3a753 100644 --- a/.aegir.js +++ b/.aegir.js @@ -1,6 +1,10 @@ 'use strict' const createServer = require('ipfsd-ctl').createServer +const parallel = require('async/parallel') +const rendezvous = require('libp2p-websocket-star-rendezvous') + +let rzserver const server = createServer() module.exports = { @@ -12,12 +16,28 @@ module.exports = { included: false }], singleRun: true, - browserNoActivityTimeout: 150 * 1000 + browserNoActivityTimeout: 200 * 1000 }, hooks: { - browser: { - pre: server.start.bind(server), - post: server.stop.bind(server) + pre: (done) => { + parallel([ + (cb) => server.start(cb), + (cb) => { + rendezvous.start({ port: 24642 }, (err, _rzserver) => { + if (err) { + return done(err) + } + rzserver = _rzserver + cb() + }) + } + ], done) + }, + post: (done) => { + parallel([ + (cb) => server.stop(cb), + (cb) => rzserver.stop(cb) + ], done) } } } diff --git a/package.json b/package.json index 36e97c83..676650c6 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "scripts": { "lint": "aegir lint", - "test": "aegir test -t node -t browser --no-cors", + "test": "aegir test -t node -t browser --no-cors --timeout 200000", "test:node": "aegir test -t node -f test/node.js", "test:browser": "aegir test -t browser --no-cors -f test/browser.js" }, @@ -57,6 +57,8 @@ "ipfs-api": "^18.1.1", "ipfsd-ctl": "~0.29.1", "left-pad": "^1.2.0", + "libp2p-websocket-star": "^0.7.2", + "libp2p-websocket-star-rendezvous": "^0.2.2", "lodash": "^4.17.4", "mocha": "^4.0.1", "ncp": "^2.0.0", diff --git a/test/circuit-relay.js b/test/circuit-relay.js index 9a13c817..8e187ac7 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -37,7 +37,7 @@ const baseConf = { const base = '/ip4/127.0.0.1/tcp' -function setupInProcNode (addrs, hop, callback) { +const setUpInProcNode = (addrs, hop, callback) => { if (typeof hop === 'function') { callback = hop hop = false @@ -65,7 +65,7 @@ function setupInProcNode (addrs, hop, callback) { }) } -function setUpJsNode (addrs, hop, callback) { +const setUpJsNode = (addrs, hop, callback) => { if (typeof hop === 'function') { callback = hop hop = false @@ -93,7 +93,7 @@ function setUpJsNode (addrs, hop, callback) { }) } -function setUpGoNode (addrs, hop, callback) { +const setUpGoNode = (addrs, hop, callback) => { if (typeof hop === 'function') { callback = hop hop = false @@ -117,7 +117,9 @@ function setUpGoNode (addrs, hop, callback) { }) } -const wsAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/ws')) +const wsAddr = (addrs) => addrs.map((a) => a.toString()) + .find((a) => a.includes('/ws') && !a.includes('/p2p-websocket-star')) +const wsStarAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/p2p-websocket-star')) const tcpAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => !a.includes('/ws')) function tests (relay, parseAddrA, parseAddrB) { @@ -337,162 +339,6 @@ function tests (relay, parseAddrA, parseAddrB) { ], done) }) }) - - describe(`js <-> ${relay} relay <-> browser`, function () { - if (isNode || relay === 'browser') { - return - } - - this.timeout(100 * 1000) - - let nodeA - let nodeB - let nodeBIpfsd - let nodeBAddr - - before(function (done) { - parallel([ - (cb) => setupInProcNode([], false, cb), - (cb) => setUpJsNode([this.addrA], cb) - ], (err, nodes) => { - expect(err).to.not.exist() - - nodeA = nodes[0].ipfsd.api - nodeB = nodes[1].ipfsd.api - nodeBIpfsd = nodes[1].ipfsd - nodeBAddr = nodes[1].addrs - - done() - }) - }) - - after((done) => nodeBIpfsd.stop(done)) - - it('should connect', function (done) { - series([ - (cb) => nodeA.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(tcpAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBAddr[0], cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - - describe(`go <-> ${relay} relay <-> browser`, function () { - if (isNode || relay === 'browser') { - return - } - - this.timeout(100 * 1000) - - let nodeA - let nodeB - let nodeBIpfsd - let nodeBAddrs - - before(function (done) { - parallel([ - (cb) => setupInProcNode([], false, cb), - (cb) => setUpGoNode([this.addrA], cb) - ], (err, nodes) => { - expect(err).to.not.exist() - - nodeA = nodes[0].ipfsd.api - nodeB = nodes[1].ipfsd.api - nodeBIpfsd = nodes[1].ipfsd - nodeBAddrs = nodes[1].addrs - - done() - }) - }) - - after((done) => nodeBIpfsd.stop(done)) - - it('should connect', function (done) { - series([ - (cb) => nodeA.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(tcpAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBAddrs[0], cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - - describe(`browser <-> ${relay} relay <-> browser`, function () { - if (isNode || relay === 'browser') { - return - } - - this.timeout(100 * 1000) - - let nodeA - let nodeB - - // let nodeAId1 - let nodeBAddrs - - before(function (done) { - parallel([ - (cb) => setupInProcNode([], false, cb), - (cb) => setupInProcNode([], false, cb) - ], (err, nodes) => { - expect(err).to.not.exist() - nodeA = nodes[0].ipfsd.api - nodeB = nodes[1].ipfsd.api - - nodeBAddrs = nodes[1].addrs - done() - }) - }) - - it('should connect', function (done) { - series([ - (cb) => nodeA.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBAddrs[0], cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) } describe('circuit', () => { @@ -506,7 +352,11 @@ describe('circuit', () => { this.addrA = `${base}/35003` this.addrB = `${base}/35004/ws` - setUpJsNode([`${base}/35001/ws`, `${base}/35002`], true, (err, res) => { + setUpJsNode([ + `${base}/35001/ws`, + `${base}/35002`, + '/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star' + ], true, (err, res) => { expect(err).to.not.exist() this.relay = res.ipfsd this.relayAddrs = res.addrs @@ -517,6 +367,169 @@ describe('circuit', () => { after(function (done) { this.relay.stop(done) }) tests('js', tcpAddr, wsAddr) + + describe(`js browser`, function () { + if (isNode) { + return + } + + describe(`js <-> js relay <-> browser`, function () { + this.timeout(100 * 1000) + + let nodeA + let nodeAAddr + + let nodeB + let nodeBAddr + let nodeBCircuitAddr + + let nodes + before(function (done) { + parallel([ + (cb) => setUpJsNode([this.addrA], cb), + (cb) => setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], cb) + ], (err, res) => { + expect(err).to.not.exist() + nodes = res.map((node) => node.ipfsd) + + nodeA = res[0].ipfsd.api + nodeAAddr = tcpAddr(res[0].addrs) + nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeAAddr).getPeerId()}` + + nodeB = res[1].ipfsd.api + nodeBAddr = wsStarAddr(res[1].addrs) + + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('should connect', function (done) { + series([ + (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => this.relay.api.swarm.connect(nodeBAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeB.swarm.connect(nodeBCircuitAddr, cb) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) + }) + }) + + describe(`go <-> js relay <-> browser`, function () { + this.timeout(100 * 1000) + + let nodeA + let nodeAAddr + + let nodeB + let nodeBAddr + let nodeBCircuitAddr + + let nodes + before(function (done) { + parallel([ + (cb) => setUpGoNode([this.addrA], cb), + (cb) => setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], cb) + ], (err, res) => { + expect(err).to.not.exist() + nodes = res.map((node) => node.ipfsd) + + nodeA = res[0].ipfsd.api + nodeAAddr = tcpAddr(res[0].addrs) + + nodeB = res[1].ipfsd.api + nodeBAddr = wsStarAddr(res[1].addrs) + nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeBAddr).getPeerId()}` + + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('should connect', function (done) { + series([ + (cb) => nodeA.swarm.connect(tcpAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) + }) + }) + + describe(`browser <-> js relay <-> browser`, function () { + this.timeout(100 * 1000) + + let nodeA + let nodeB + + // let nodeAId1 + let nodeBAddrs + + before(function (done) { + parallel([ + (cb) => setUpInProcNode([], false, cb), + (cb) => setUpInProcNode([], false, cb) + ], (err, nodes) => { + expect(err).to.not.exist() + nodeA = nodes[0].ipfsd.api + nodeB = nodes[1].ipfsd.api + + nodeBAddrs = nodes[1].addrs + done() + }) + }) + + it('should connect', function (done) { + console.dir(`wsAddr: ${wsAddr(this.relayAddrs)}`) + series([ + (cb) => nodeA.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeA.swarm.connect(nodeBAddrs[0], cb) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) + }) + }) + }) }) describe('go relay', function () { @@ -529,7 +542,10 @@ describe('circuit', () => { this.addrA = `${base}/35003` this.addrB = `${base}/35004/ws` - setUpGoNode([`${base}/35001/ws`, `${base}/35002`], true, (err, res) => { + setUpGoNode([ + `${base}/35001/ws`, + `${base}/35002` + ], true, (err, res) => { expect(err).to.not.exist() this.relay = res.ipfsd this.relayAddrs = res.addrs @@ -540,13 +556,165 @@ describe('circuit', () => { after(function (done) { this.relay.stop(done) }) tests('go', tcpAddr, wsAddr) + + describe(`go browser`, function () { + if (isNode) { + return + } + + describe(`js <-> go relay <-> browser`, function () { + this.timeout(100 * 1000) + + let nodeA + + let nodeB + let nodeBCircuitAddr + + let nodes + before(function (done) { + parallel([ + (cb) => setUpJsNode([this.addrA], cb), + (cb) => setUpInProcNode([], cb) + ], (err, res) => { + expect(err).to.not.exist() + nodes = res.map((node) => node.ipfsd) + + nodeA = res[0].ipfsd.api + nodeB = res[1].ipfsd.api + nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(res[1].addrs[0]).getPeerId()}` + + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('should connect', function (done) { + series([ + (cb) => nodeA.swarm.connect(tcpAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) + }) + }) + + describe(`go <-> go relay <-> browser`, function () { + this.timeout(100 * 1000) + + let nodeA + + let nodeB + let nodeBCircuitAddr + + let nodes + before(function (done) { + parallel([ + (cb) => setUpGoNode([this.addrA], cb), + (cb) => setUpInProcNode([], cb) + ], (err, res) => { + expect(err).to.not.exist() + nodes = res.map((node) => node.ipfsd) + + nodeA = res[0].ipfsd.api + nodeB = res[1].ipfsd.api + nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(res[1].addrs[0]).getPeerId()}` + + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('should connect', function (done) { + series([ + (cb) => nodeA.swarm.connect(tcpAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) + }) + }) + + describe(`browser <-> go relay <-> browser`, function () { + if (isNode) { + return + } + + this.timeout(100 * 1000) + + let nodeA + let nodeB + + // let nodeAId1 + let nodeBAddrs + + before(function (done) { + parallel([ + (cb) => setUpInProcNode([], false, cb), + (cb) => setUpInProcNode([], false, cb) + ], (err, nodes) => { + expect(err).to.not.exist() + nodeA = nodes[0].ipfsd.api + nodeB = nodes[1].ipfsd.api + + nodeBAddrs = nodes[1].addrs + done() + }) + }) + + it('should connect', function (done) { + series([ + (cb) => nodeA.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeA.swarm.connect(nodeBAddrs[0], cb) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) + }) + }) + }) }) describe('browser relay', function () { - if (isNode) { - return - } - this.relay = null this.relayAddrs = null @@ -556,7 +724,7 @@ describe('circuit', () => { this.addrA = `${base}/35003/ws` this.addrB = `${base}/35004/ws` - setupInProcNode([], true, (err, res) => { + setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], true, (err, res) => { expect(err).to.not.exist() this.relay = res.ipfsd this.relayAddrs = res.addrs @@ -566,6 +734,118 @@ describe('circuit', () => { after(function (done) { this.relay.stop(done) }) - tests('browser', wsAddr, wsAddr) + tests('go', wsAddr, wsAddr) + + describe(`go browser`, function () { + if (isNode) { + return + } + + describe(`js <-> browser relay <-> browser`, function () { + this.timeout(100 * 1000) + + let nodeA + let nodeAAddr + + let nodeB + let nodeBCircuitAddr + + let nodes + before(function (done) { + parallel([ + (cb) => setUpJsNode([this.addrA], cb), + (cb) => setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], cb) + ], (err, res) => { + expect(err).to.not.exist() + nodes = res.map((node) => node.ipfsd) + + nodeA = res[0].ipfsd.api + nodeAAddr = wsAddr(res[0].addrs) + + nodeB = res[1].ipfsd.api + nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(res[1].addrs[0]).getPeerId()}` + + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('should connect', function (done) { + series([ + (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeB.swarm.connect(wsStarAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) + }) + }) + + describe(`go <-> browser relay <-> browser`, function () { + this.timeout(100 * 1000) + + let nodeA + let nodeAAddr + + let nodeB + let nodeBCircuitAddr + + let nodes + before(function (done) { + parallel([ + (cb) => setUpGoNode([this.addrA], cb), + (cb) => setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], cb) + ], (err, res) => { + expect(err).to.not.exist() + nodes = res.map((node) => node.ipfsd) + + nodeA = res[0].ipfsd.api + nodeAAddr = wsAddr(res[0].addrs) + + nodeB = res[1].ipfsd.api + nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(res[1].addrs[0]).getPeerId()}` + + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('should connect', function (done) { + series([ + (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeB.swarm.connect(wsStarAddr(this.relayAddrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) + ], done) + }) + + it('should transfer', function (done) { + const data = crypto.randomBytes(128) + waterfall([ + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], done) + }) + }) + }) }) }) From e938f61569f2c3af3fd2e52f1e9e462efe80bfcf Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 2 Feb 2018 08:26:23 -0600 Subject: [PATCH 23/49] fix: use IPFS_REUSEPORT untille new version of go-ipfs is released --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 676650c6..bb5aab84 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ }, "scripts": { "lint": "aegir lint", - "test": "aegir test -t node -t browser --no-cors --timeout 200000", - "test:node": "aegir test -t node -f test/node.js", - "test:browser": "aegir test -t browser --no-cors -f test/browser.js" + "test": "IPFS_REUSEPORT=false aegir test -t node -t browser --no-cors", + "test:node": "IPFS_REUSEPORT=false aegir test -t node -f test/node.js", + "test:browser": "IPFS_REUSEPORT=false aegir test -t browser --no-cors -f test/browser.js" }, "pre-commit": [ "lint" From d02d6083f38aaca3b4a88ce708a0147ad03039d3 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 2 Feb 2018 09:40:59 -0600 Subject: [PATCH 24/49] experiment: remove individual timeouts to rule time out related failures --- package.json | 6 ++--- test/circuit-relay.js | 58 +++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index bb5aab84..bf4fba07 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ }, "scripts": { "lint": "aegir lint", - "test": "IPFS_REUSEPORT=false aegir test -t node -t browser --no-cors", - "test:node": "IPFS_REUSEPORT=false aegir test -t node -f test/node.js", - "test:browser": "IPFS_REUSEPORT=false aegir test -t browser --no-cors -f test/browser.js" + "test": "aegir test -t node -t browser --no-cors --timeout 500000", + "test:node": "aegir test -t node -f test/node.js", + "test:browser": "aegir test -t browser --no-cors -f test/browser.js" }, "pre-commit": [ "lint" diff --git a/test/circuit-relay.js b/test/circuit-relay.js index 8e187ac7..bb00d401 100644 --- a/test/circuit-relay.js +++ b/test/circuit-relay.js @@ -124,7 +124,7 @@ const tcpAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => !a.include function tests (relay, parseAddrA, parseAddrB) { describe(`js <-> ${relay} relay <-> go`, function () { - this.timeout(80 * 1000) + // this.timeout(80 * 1000) let nodeA let nodeAAddr @@ -179,7 +179,7 @@ function tests (relay, parseAddrA, parseAddrB) { }) describe(`js <-> ${relay} relay <-> js`, function () { - this.timeout(80 * 1000) + // this.timeout(80 * 1000) let nodeA let nodeAAddr @@ -233,7 +233,7 @@ function tests (relay, parseAddrA, parseAddrB) { }) describe(`go <-> ${relay} relay <-> go`, function () { - this.timeout(80 * 1000) + // this.timeout(80 * 1000) let nodeA let nodeAAddr let nodeACircuitAddr @@ -287,7 +287,7 @@ function tests (relay, parseAddrA, parseAddrB) { }) describe(`go <-> ${relay} relay <-> js`, function () { - this.timeout(80 * 1000) + // this.timeout(80 * 1000) let nodeA let nodeAAddr let nodeACircuitAddr @@ -347,14 +347,14 @@ describe('circuit', () => { this.relayAddrs = null before(function (done) { - this.timeout(50 * 1000) + // this.timeout(50 * 1000) - this.addrA = `${base}/35003` - this.addrB = `${base}/35004/ws` + this.addrA = `${base}/0` + this.addrB = `${base}/0/ws` setUpJsNode([ - `${base}/35001/ws`, - `${base}/35002`, + `${base}/0/ws`, + `${base}/0`, '/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star' ], true, (err, res) => { expect(err).to.not.exist() @@ -374,7 +374,7 @@ describe('circuit', () => { } describe(`js <-> js relay <-> browser`, function () { - this.timeout(100 * 1000) + // this.timeout(100 * 1000) let nodeA let nodeAAddr @@ -429,10 +429,10 @@ describe('circuit', () => { }) describe(`go <-> js relay <-> browser`, function () { - this.timeout(100 * 1000) + // this.timeout(100 * 1000) let nodeA - let nodeAAddr + // let nodeAAddr let nodeB let nodeBAddr @@ -448,7 +448,7 @@ describe('circuit', () => { nodes = res.map((node) => node.ipfsd) nodeA = res[0].ipfsd.api - nodeAAddr = tcpAddr(res[0].addrs) + // nodeAAddr = tcpAddr(res[0].addrs) nodeB = res[1].ipfsd.api nodeBAddr = wsStarAddr(res[1].addrs) @@ -484,7 +484,7 @@ describe('circuit', () => { }) describe(`browser <-> js relay <-> browser`, function () { - this.timeout(100 * 1000) + // this.timeout(100 * 1000) let nodeA let nodeB @@ -537,14 +537,14 @@ describe('circuit', () => { this.relayAddrs = null before(function (done) { - this.timeout(50 * 1000) + // this.timeout(50 * 1000) - this.addrA = `${base}/35003` - this.addrB = `${base}/35004/ws` + this.addrA = `${base}/0` + this.addrB = `${base}/0/ws` setUpGoNode([ - `${base}/35001/ws`, - `${base}/35002` + `${base}/0/ws`, + `${base}/0` ], true, (err, res) => { expect(err).to.not.exist() this.relay = res.ipfsd @@ -563,7 +563,7 @@ describe('circuit', () => { } describe(`js <-> go relay <-> browser`, function () { - this.timeout(100 * 1000) + // this.timeout(100 * 1000) let nodeA @@ -613,7 +613,7 @@ describe('circuit', () => { }) describe(`go <-> go relay <-> browser`, function () { - this.timeout(100 * 1000) + // this.timeout(100 * 1000) let nodeA @@ -667,7 +667,7 @@ describe('circuit', () => { return } - this.timeout(100 * 1000) + // this.timeout(100 * 1000) let nodeA let nodeB @@ -719,10 +719,10 @@ describe('circuit', () => { this.relayAddrs = null before(function (done) { - this.timeout(50 * 1000) + // this.timeout(50 * 1000) - this.addrA = `${base}/35003/ws` - this.addrB = `${base}/35004/ws` + this.addrA = `${base}/0/ws` + this.addrB = `${base}/0/ws` setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], true, (err, res) => { expect(err).to.not.exist() @@ -734,15 +734,15 @@ describe('circuit', () => { after(function (done) { this.relay.stop(done) }) - tests('go', wsAddr, wsAddr) + tests('browser', wsAddr, wsAddr) - describe(`go browser`, function () { + describe(`browser`, function () { if (isNode) { return } describe(`js <-> browser relay <-> browser`, function () { - this.timeout(100 * 1000) + // this.timeout(100 * 1000) let nodeA let nodeAAddr @@ -795,7 +795,7 @@ describe('circuit', () => { }) describe(`go <-> browser relay <-> browser`, function () { - this.timeout(100 * 1000) + // this.timeout(100 * 1000) let nodeA let nodeAAddr From 0af7ac56fdd1677d5c0e326b2b9f4bd1cc81ee20 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 3 Feb 2018 17:47:40 -0600 Subject: [PATCH 25/49] tests: reworking --- .aegir.js | 47 ++- package.json | 9 +- test/browser.js | 2 +- test/circuit-relay.js | 851 ------------------------------------------ test/circuit.js | 693 ++++++++++++++++++++++++++++++++++ test/node.js | 2 +- test/utils/circuit.js | 186 +++++++++ 7 files changed, 913 insertions(+), 877 deletions(-) delete mode 100644 test/circuit-relay.js create mode 100644 test/circuit.js create mode 100644 test/utils/circuit.js diff --git a/.aegir.js b/.aegir.js index 25d3a753..9eef3cac 100644 --- a/.aegir.js +++ b/.aegir.js @@ -16,28 +16,35 @@ module.exports = { included: false }], singleRun: true, - browserNoActivityTimeout: 200 * 1000 + captureTimeout: 5000 * 1000, + // browserDisconnectTolerance: 3, //this one helps + browserDisconnectTimeout: 5000 * 1000, + browserNoActivityTimeout: 5000 * 1000 }, hooks: { - pre: (done) => { - parallel([ - (cb) => server.start(cb), - (cb) => { - rendezvous.start({ port: 24642 }, (err, _rzserver) => { - if (err) { - return done(err) - } - rzserver = _rzserver - cb() - }) - } - ], done) - }, - post: (done) => { - parallel([ - (cb) => server.stop(cb), - (cb) => rzserver.stop(cb) - ], done) + browser: { + pre: (done) => { + parallel([ + (cb) => server.start(cb), + (cb) => { + rendezvous.start({ + port: 24642 + }, (err, _rzserver) => { + if (err) { + return done(err) + } + rzserver = _rzserver + cb() + }) + } + ], done) + }, + post: (done) => { + parallel([ + (cb) => server.stop(cb), + (cb) => rzserver.stop(cb) + ], done) + } } } } diff --git a/package.json b/package.json index bf4fba07..011c192b 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ }, "scripts": { "lint": "aegir lint", - "test": "aegir test -t node -t browser --no-cors --timeout 500000", - "test:node": "aegir test -t node -f test/node.js", - "test:browser": "aegir test -t browser --no-cors -f test/browser.js" + "test": "cross-env IPFS_REUSEPORT=false aegir test -t node -t browser --no-cors --timeout 50000", + "test:node": "cross-env IPFS_REUSEPORT=false aegir test -t node -f test/node.js --timeout 50000", + "test:browser": "cross-env IPFS_REUSEPORT=false aegir test -t browser --no-cors -f test/browser.js --timeout 100000" }, "pre-commit": [ "lint" @@ -45,6 +45,7 @@ "buffer-loader": "0.0.1", "chai": "^4.1.2", "cids": "^0.5.2", + "cross-env": "^5.1.3", "detect-node": "^2.0.3", "dir-compare": "^1.4.0", "dirty-chai": "^2.0.1", @@ -53,7 +54,7 @@ "form-data": "^2.3.1", "go-ipfs-dep": "^0.4.13", "hat": "0.0.3", - "ipfs": "~0.27.7", + "ipfs": "^0.28.0", "ipfs-api": "^18.1.1", "ipfsd-ctl": "~0.29.1", "left-pad": "^1.2.0", diff --git a/test/browser.js b/test/browser.js index 21715fe8..beca3f4b 100644 --- a/test/browser.js +++ b/test/browser.js @@ -4,5 +4,5 @@ // require('./exchange-files') // require('./pubsub') require('./kad-dht') -require('./circuit-relay') +require('./circuit') // require('./repo') diff --git a/test/circuit-relay.js b/test/circuit-relay.js deleted file mode 100644 index bb00d401..00000000 --- a/test/circuit-relay.js +++ /dev/null @@ -1,851 +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 multiaddr = require('multiaddr') -const crypto = require('crypto') -const IPFS = require('ipfs') - -const isNode = require('detect-node') - -const DaemonFactory = require('ipfsd-ctl') -const jsDf = DaemonFactory.create({ type: 'js' }) -const goDf = DaemonFactory.create({ type: 'go' }) -const procDf = DaemonFactory.create({ type: 'proc', exec: IPFS }) - -const baseConf = { - Bootstrap: [], - Addresses: { - API: '/ip4/0.0.0.0/tcp/0', - Gateway: '/ip4/0.0.0.0/tcp/0' - }, - Discovery: { - MDNS: { - Enabled: - false - } - } -} - -const base = '/ip4/127.0.0.1/tcp' - -const setUpInProcNode = (addrs, hop, callback) => { - if (typeof hop === 'function') { - callback = hop - hop = false - } - - procDf.spawn({ - config: Object.assign({}, baseConf, { - Addresses: { - Swarm: addrs - }, - EXPERIMENTAL: { - relay: { - enabled: true, - hop: { - enabled: hop - } - } - } - }) - }, (err, ipfsd) => { - expect(err).to.not.exist() - ipfsd.api.id((err, id) => { - callback(err, { ipfsd, addrs: id.addresses }) - }) - }) -} - -const setUpJsNode = (addrs, hop, callback) => { - if (typeof hop === 'function') { - callback = hop - hop = false - } - - jsDf.spawn({ - config: Object.assign({}, baseConf, { - Addresses: { - Swarm: addrs - }, - EXPERIMENTAL: { - relay: { - enabled: true, - hop: { - enabled: hop - } - } - } - }) - }, (err, ipfsd) => { - expect(err).to.not.exist() - ipfsd.api.id((err, id) => { - callback(err, { ipfsd, addrs: id.addresses }) - }) - }) -} - -const setUpGoNode = (addrs, hop, callback) => { - if (typeof hop === 'function') { - callback = hop - hop = false - } - - goDf.spawn({ - config: Object.assign({}, baseConf, { - Addresses: { - Swarm: addrs - }, - Swarm: { - DisableRelay: false, - EnableRelayHop: hop - } - }) - }, (err, ipfsd) => { - expect(err).to.not.exist() - ipfsd.api.id((err, id) => { - callback(err, { ipfsd, addrs: id.addresses }) - }) - }) -} - -const wsAddr = (addrs) => addrs.map((a) => a.toString()) - .find((a) => a.includes('/ws') && !a.includes('/p2p-websocket-star')) -const wsStarAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/p2p-websocket-star')) -const tcpAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => !a.includes('/ws')) - -function tests (relay, parseAddrA, parseAddrB) { - describe(`js <-> ${relay} relay <-> go`, function () { - // this.timeout(80 * 1000) - - let nodeA - let nodeAAddr - let nodeB - let nodeBAddr - let nodeBCircuitAddr - - let nodes - before(function (done) { - parallel([ - (cb) => setUpGoNode([this.addrA], cb), - (cb) => setUpJsNode([this.addrB], cb) - ], function (err, res) { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - nodeAAddr = parseAddrA(res[0].addrs) - nodeA = res[0].ipfsd.api - - nodeBAddr = parseAddrB(res[1].addrs) - - nodeB = res[1].ipfsd.api - nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeBAddr).getPeerId()}` - - done() - }) - }) - - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - - it('should connect', function (done) { - series([ - (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => this.relay.api.swarm.connect(nodeBAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - - describe(`js <-> ${relay} relay <-> js`, function () { - // this.timeout(80 * 1000) - let nodeA - let nodeAAddr - - let nodeB - let nodeBAddr - let nodeBCircuitAddr - - let nodes - before(function (done) { - parallel([ - (cb) => setUpJsNode([this.addrA], cb), - (cb) => setUpJsNode([this.addrB], cb) - ], (err, res) => { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - nodeA = res[0].ipfsd.api - nodeAAddr = parseAddrA(res[0].addrs) - nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeAAddr).getPeerId()}` - - nodeB = res[1].ipfsd.api - nodeBAddr = parseAddrB(res[1].addrs) - - done() - }) - }) - - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - - it('should connect', function (done) { - series([ - (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => this.relay.api.swarm.connect(nodeBAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(nodeBCircuitAddr, cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - - describe(`go <-> ${relay} relay <-> go`, function () { - // this.timeout(80 * 1000) - let nodeA - let nodeAAddr - let nodeACircuitAddr - - let nodeB - let nodeBAddr - - let nodes - before(function (done) { - parallel([ - (cb) => setUpGoNode([this.addrA], cb), - (cb) => setUpGoNode([this.addrB], cb) - ], (err, res) => { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - nodeA = res[0].ipfsd.api - nodeAAddr = parseAddrA(res[0].addrs) - nodeACircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeAAddr).getPeerId()}` - - nodeB = res[1].ipfsd.api - nodeBAddr = parseAddrB(res[1].addrs) - - done() - }) - }) - - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - - it('should connect', function (done) { - series([ - (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => this.relay.api.swarm.connect(nodeBAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(nodeACircuitAddr, cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - - describe(`go <-> ${relay} relay <-> js`, function () { - // this.timeout(80 * 1000) - let nodeA - let nodeAAddr - let nodeACircuitAddr - - let nodeB - let nodeBAddr - - let nodes - before(function (done) { - parallel([ - (cb) => setUpGoNode([this.addrA], cb), - (cb) => setUpJsNode([this.addrB], cb) - ], (err, res) => { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - nodeA = res[0].ipfsd.api - nodeAAddr = parseAddrA(res[0].addrs) - nodeACircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeAAddr).getPeerId()}` - - nodeB = res[1].ipfsd.api - nodeBAddr = parseAddrB(res[1].addrs) - - done() - }) - }) - - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - - it('should connect', function (done) { - series([ - (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => this.relay.api.swarm.connect(nodeBAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(nodeACircuitAddr, cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) -} - -describe('circuit', () => { - describe('js relay', function () { - this.relay = null - this.relayAddrs = null - - before(function (done) { - // this.timeout(50 * 1000) - - this.addrA = `${base}/0` - this.addrB = `${base}/0/ws` - - setUpJsNode([ - `${base}/0/ws`, - `${base}/0`, - '/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star' - ], true, (err, res) => { - expect(err).to.not.exist() - this.relay = res.ipfsd - this.relayAddrs = res.addrs - done() - }) - }) - - after(function (done) { this.relay.stop(done) }) - - tests('js', tcpAddr, wsAddr) - - describe(`js browser`, function () { - if (isNode) { - return - } - - describe(`js <-> js relay <-> browser`, function () { - // this.timeout(100 * 1000) - - let nodeA - let nodeAAddr - - let nodeB - let nodeBAddr - let nodeBCircuitAddr - - let nodes - before(function (done) { - parallel([ - (cb) => setUpJsNode([this.addrA], cb), - (cb) => setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], cb) - ], (err, res) => { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - nodeA = res[0].ipfsd.api - nodeAAddr = tcpAddr(res[0].addrs) - nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeAAddr).getPeerId()}` - - nodeB = res[1].ipfsd.api - nodeBAddr = wsStarAddr(res[1].addrs) - - done() - }) - }) - - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - - it('should connect', function (done) { - series([ - (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => this.relay.api.swarm.connect(nodeBAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(nodeBCircuitAddr, cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - - describe(`go <-> js relay <-> browser`, function () { - // this.timeout(100 * 1000) - - let nodeA - // let nodeAAddr - - let nodeB - let nodeBAddr - let nodeBCircuitAddr - - let nodes - before(function (done) { - parallel([ - (cb) => setUpGoNode([this.addrA], cb), - (cb) => setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], cb) - ], (err, res) => { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - nodeA = res[0].ipfsd.api - // nodeAAddr = tcpAddr(res[0].addrs) - - nodeB = res[1].ipfsd.api - nodeBAddr = wsStarAddr(res[1].addrs) - nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeBAddr).getPeerId()}` - - done() - }) - }) - - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - - it('should connect', function (done) { - series([ - (cb) => nodeA.swarm.connect(tcpAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - - describe(`browser <-> js relay <-> browser`, function () { - // this.timeout(100 * 1000) - - let nodeA - let nodeB - - // let nodeAId1 - let nodeBAddrs - - before(function (done) { - parallel([ - (cb) => setUpInProcNode([], false, cb), - (cb) => setUpInProcNode([], false, cb) - ], (err, nodes) => { - expect(err).to.not.exist() - nodeA = nodes[0].ipfsd.api - nodeB = nodes[1].ipfsd.api - - nodeBAddrs = nodes[1].addrs - done() - }) - }) - - it('should connect', function (done) { - console.dir(`wsAddr: ${wsAddr(this.relayAddrs)}`) - series([ - (cb) => nodeA.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBAddrs[0], cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - }) - }) - - describe('go relay', function () { - this.relay = null - this.relayAddrs = null - - before(function (done) { - // this.timeout(50 * 1000) - - this.addrA = `${base}/0` - this.addrB = `${base}/0/ws` - - setUpGoNode([ - `${base}/0/ws`, - `${base}/0` - ], true, (err, res) => { - expect(err).to.not.exist() - this.relay = res.ipfsd - this.relayAddrs = res.addrs - done() - }) - }) - - after(function (done) { this.relay.stop(done) }) - - tests('go', tcpAddr, wsAddr) - - describe(`go browser`, function () { - if (isNode) { - return - } - - describe(`js <-> go relay <-> browser`, function () { - // this.timeout(100 * 1000) - - let nodeA - - let nodeB - let nodeBCircuitAddr - - let nodes - before(function (done) { - parallel([ - (cb) => setUpJsNode([this.addrA], cb), - (cb) => setUpInProcNode([], cb) - ], (err, res) => { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - nodeA = res[0].ipfsd.api - nodeB = res[1].ipfsd.api - nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(res[1].addrs[0]).getPeerId()}` - - done() - }) - }) - - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - - it('should connect', function (done) { - series([ - (cb) => nodeA.swarm.connect(tcpAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - - describe(`go <-> go relay <-> browser`, function () { - // this.timeout(100 * 1000) - - let nodeA - - let nodeB - let nodeBCircuitAddr - - let nodes - before(function (done) { - parallel([ - (cb) => setUpGoNode([this.addrA], cb), - (cb) => setUpInProcNode([], cb) - ], (err, res) => { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - nodeA = res[0].ipfsd.api - nodeB = res[1].ipfsd.api - nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(res[1].addrs[0]).getPeerId()}` - - done() - }) - }) - - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - - it('should connect', function (done) { - series([ - (cb) => nodeA.swarm.connect(tcpAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - - describe(`browser <-> go relay <-> browser`, function () { - if (isNode) { - return - } - - // this.timeout(100 * 1000) - - let nodeA - let nodeB - - // let nodeAId1 - let nodeBAddrs - - before(function (done) { - parallel([ - (cb) => setUpInProcNode([], false, cb), - (cb) => setUpInProcNode([], false, cb) - ], (err, nodes) => { - expect(err).to.not.exist() - nodeA = nodes[0].ipfsd.api - nodeB = nodes[1].ipfsd.api - - nodeBAddrs = nodes[1].addrs - done() - }) - }) - - it('should connect', function (done) { - series([ - (cb) => nodeA.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(wsAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBAddrs[0], cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - }) - }) - - describe('browser relay', function () { - this.relay = null - this.relayAddrs = null - - before(function (done) { - // this.timeout(50 * 1000) - - this.addrA = `${base}/0/ws` - this.addrB = `${base}/0/ws` - - setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], true, (err, res) => { - expect(err).to.not.exist() - this.relay = res.ipfsd - this.relayAddrs = res.addrs - done() - }) - }) - - after(function (done) { this.relay.stop(done) }) - - tests('browser', wsAddr, wsAddr) - - describe(`browser`, function () { - if (isNode) { - return - } - - describe(`js <-> browser relay <-> browser`, function () { - // this.timeout(100 * 1000) - - let nodeA - let nodeAAddr - - let nodeB - let nodeBCircuitAddr - - let nodes - before(function (done) { - parallel([ - (cb) => setUpJsNode([this.addrA], cb), - (cb) => setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], cb) - ], (err, res) => { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - nodeA = res[0].ipfsd.api - nodeAAddr = wsAddr(res[0].addrs) - - nodeB = res[1].ipfsd.api - nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(res[1].addrs[0]).getPeerId()}` - - done() - }) - }) - - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - - it('should connect', function (done) { - series([ - (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(wsStarAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - - describe(`go <-> browser relay <-> browser`, function () { - // this.timeout(100 * 1000) - - let nodeA - let nodeAAddr - - let nodeB - let nodeBCircuitAddr - - let nodes - before(function (done) { - parallel([ - (cb) => setUpGoNode([this.addrA], cb), - (cb) => setUpInProcNode(['/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star'], cb) - ], (err, res) => { - expect(err).to.not.exist() - nodes = res.map((node) => node.ipfsd) - - nodeA = res[0].ipfsd.api - nodeAAddr = wsAddr(res[0].addrs) - - nodeB = res[1].ipfsd.api - nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(res[1].addrs[0]).getPeerId()}` - - done() - }) - }) - - after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) - - it('should connect', function (done) { - series([ - (cb) => this.relay.api.swarm.connect(nodeAAddr, cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeB.swarm.connect(wsStarAddr(this.relayAddrs), cb), - (cb) => setTimeout(cb, 1000), - (cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb) - ], done) - }) - - it('should transfer', function (done) { - const data = crypto.randomBytes(128) - waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), - (buffer, cb) => { - expect(buffer).to.deep.equal(data) - cb() - } - ], done) - }) - }) - }) - }) -}) diff --git a/test/circuit.js b/test/circuit.js new file mode 100644 index 00000000..2d84d99d --- /dev/null +++ b/test/circuit.js @@ -0,0 +1,693 @@ +/* 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 isNode = require('detect-node') +const utils = require('./utils/circuit') + +const proc = utils.setUpProcNode +const js = utils.setUpJsNode +const go = utils.setUpGoNode + +const ws = utils.wsAddr +const star = utils.wsStarAddr +const circuit = utils.circuitAddr + +const create = utils.create +const connect = utils.connect +const send = utils.send + +const base = '/ip4/127.0.0.1/tcp' + +// TODO: (dryajov) circuit tests ended up being +// more complex than expected, the majority +// of the complexity comes from spawning and +// connecting the nodes. +// +// I've come up with this little DSL to avoid +// duplicating code all over the place. Some +// notable quirks that lead to this: +// +// - ipfs-api connect, doesn't support peer ids, +// only plain addresses, hence we end up filtering +// addresses (clunky) +// - not all connect sequences work in all cases +// - i.e. cant connect to browser relays since +// go doesn't support the star protos, so the +// sequence has to be changed to connect the +// browser relay to the nodes instead +// +// that breaks the flow and also any attempt to +// generalize and abstract things out + + +/** + * Legend: + * - `name` - the name of the test + * - `nodes` - object containing the nodes to spawn + * - `key` - the key of the object is the name + * - `exec` - the method used to spawn the node, there are tree `js`, `go` and `proc` + * - `addrs` - the address to spawn the node with + * - `connect` - array of arrays describing how to connect the nodes, reads from left to right + * the first element connects to the second. A tuple contains objects of the for of + * [{name: 'node1', parser: js}, {name: 'relay'}] + * - `name` - the name of the node + * - `parser` - the parsing function used to extract the address + * - `send` - array describing the direction in which to send the data + * ['node1', 'node2'] send from node1 to node2 + * + * + * { + * name: 'go-go-go', // name of the test, what shows in the describe + * nodes: { // describes the nodes section + * node1: { // name of the node + * exec: go, // the function to create the nodes + * addrs: [`${base}/0/ws`] // address of the node + * }, + * relay: { + * exec: go, + * addrs: [`${base}/0/ws`] + * }, + * node2: { + * exec: go, + * addrs: [`${base}/0/ws`] + * } + * }, + * connect: [ // describes how to connect the nodes + * [{ name: 'node1', parser: ws }, { name: 'relay' }], // connect node1 to relay use ws parser to filter the address + * [{ name: 'node2', parser: ws }, { name: 'relay' }], // connect node2 to relay use ws parser to filter the address + * [{ name: 'node1', parser: circuit }, { name: 'node2' }] // connect node1 to node2 use circuit parser to filter the address + * ], + * send: ['node1', 'node2'] // describe the direction which data is sent - node1 to node2 + * skip: () => true // method called to determine if the tests should be skipped + * } + */ + +const tests = [ + { + name: 'go-go-go', + nodes: { + node1: { + exec: go, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: go, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: go, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'] + }, + { + name: 'js-go-go', + nodes: { + node1: { + exec: js, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: go, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: go, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => true + }, + { + name: 'js-go-js', + nodes: { + node1: { + exec: js, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: go, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: js, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'] + }, + { + name: 'js-js-js', + nodes: { + node1: { + exec: js, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: js, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: js, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'] + }, + { + name: 'js-js-go', + nodes: { + node1: { + exec: js, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: js, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: go, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'] + }, + { + name: 'go-js-go', + nodes: { + node1: { + exec: go, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: js, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: go, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'] + }, + { + name: 'browser-js-go', + nodes: { + node1: { + exec: proc, + addrs: [] + }, + relay: { + exec: js, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: go, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'browser-js-js', + nodes: { + node1: { + exec: proc, + addrs: [] + }, + relay: { + exec: js, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: js, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'js-js-browser', + nodes: { + node1: { + exec: js, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: js, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: proc, + addrs: [] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'go-js-browser', + nodes: { + node1: { + exec: go, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: js, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: proc, + addrs: [] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'browser-js-browser', + nodes: { + node1: { + exec: proc, + addrs: [] + }, + relay: { + exec: js, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: proc, + addrs: [] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'browser-go-go', + nodes: { + node1: { + exec: proc, + addrs: [] + }, + relay: { + exec: go, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: go, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'browser-go-js', + nodes: { + node1: { + exec: proc, + addrs: [] + }, + relay: { + exec: go, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: js, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'js-go-browser', + nodes: { + node1: { + exec: js, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: go, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: proc, + addrs: [] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'go-go-browser', + nodes: { + node1: { + exec: go, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: go, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: proc, + addrs: [] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'browser-go-browser', + nodes: { + node1: { + exec: proc, + addrs: [] + }, + relay: { + exec: go, + addrs: [`${base}/0/ws`] + }, + node2: { + exec: proc, + addrs: [] + } + }, + connect: [ + [{ name: 'node1', parser: ws }, { name: 'relay' }], + [{ name: 'node2', parser: ws }, { name: 'relay' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => true + }, + { + name: 'go-browser-browser', + nodes: { + node1: { + exec: go, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: proc, + addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], + relay: true + }, + node2: { + exec: proc, + addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] + } + }, + connect: [ + [{ name: 'relay', parser: ws }, { name: 'node1' }], + [{ name: 'relay', parser: star }, { name: 'node2' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'go-browser-js', + nodes: { + node1: { + exec: go, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: proc, + addrs: [] + }, + node2: { + exec: js, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'relay', parser: ws }, { name: 'node1' }], + [{ name: 'relay', parser: ws }, { name: 'node2' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'go-browser-go', + nodes: { + node1: { + exec: go, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: proc, + addrs: [] + }, + node2: { + exec: go, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'relay', parser: ws }, { name: 'node1' }], + [{ name: 'relay', parser: ws }, { name: 'node2' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => true + }, + { + name: 'js-browser-js', + nodes: { + node1: { + exec: js, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: proc, + addrs: [] + }, + node2: { + exec: js, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'relay', parser: ws }, { name: 'node1' }], + [{ name: 'relay', parser: ws }, { name: 'node2' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'js-browser-go', + nodes: { + node1: { + exec: js, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: proc, + addrs: [] + }, + node2: { + exec: go, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'relay', parser: ws }, { name: 'node1' }], + [{ name: 'relay', parser: ws }, { name: 'node2' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'js-browser-browser', + nodes: { + node1: { + exec: js, + addrs: [`${base}/0/ws`] + }, + relay: { + exec: proc, + addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] + }, + node2: { + exec: proc, + addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] + } + }, + connect: [ + [{ name: 'relay', parser: ws }, { name: 'node1' }], + [{ name: 'relay', parser: star }, { name: 'node2' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'browser-browser-js', + nodes: { + node1: { + exec: proc, + addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] + }, + relay: { + exec: proc, + addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] + }, + node2: { + exec: js, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'relay', parser: star }, { name: 'node1' }], + [{ name: 'relay', parser: ws }, { name: 'node2' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => isNode + }, + { + name: 'browser-browser-go', + nodes: { + node1: { + exec: proc, + addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] + }, + relay: { + exec: proc, + addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] + }, + node2: { + exec: go, + addrs: [`${base}/0/ws`] + } + }, + connect: [ + [{ name: 'relay', parser: star }, { name: 'node1' }], + [{ name: 'relay', parser: ws }, { name: 'node2' }], + [{ name: 'node1', parser: circuit }, { name: 'node2' }] + ], + send: ['node1', 'node2'], + skip: () => true + } +] + +describe.only('circuit', () => { + tests.forEach((test) => { + let nodes + + const dsc = test.skip && test.skip() ? describe.skip : describe + dsc(test.name, function () { + before((done) => { + create(test.nodes, (err, _nodes) => { + expect(err).to.not.exist() + nodes = _nodes + done() + }) + }) + + after((done) => parallel(nodes.map((node) => (cb) => node.node.ipfsd.stop(cb)), done)) + + it('connect', (done) => { + connect(test.connect, nodes, done) + }) + + it('send', (done) => { + send(test.send, nodes, done) + }) + }) + }) +}) diff --git a/test/node.js b/test/node.js index d14777e4..ac49e854 100644 --- a/test/node.js +++ b/test/node.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ 'use strict' -require('./circuit-relay') +require('./circuit') require('./repo') require('./exchange-files') require('./kad-dht') diff --git a/test/utils/circuit.js b/test/utils/circuit.js new file mode 100644 index 00000000..2bcf3807 --- /dev/null +++ b/test/utils/circuit.js @@ -0,0 +1,186 @@ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + +const series = require('async/series') +const waterfall = require('async/waterfall') +const crypto = require('crypto') + +const IPFS = require('ipfs') + +const DaemonFactory = require('ipfsd-ctl') +const jsDf = DaemonFactory.create({ type: 'js' }) +const goDf = DaemonFactory.create({ type: 'go' }) +const procDf = DaemonFactory.create({ type: 'proc', exec: IPFS }) + +const baseConf = { + Bootstrap: [], + Addresses: { + API: '/ip4/0.0.0.0/tcp/0', + Gateway: '/ip4/0.0.0.0/tcp/0' + }, + Discovery: { + MDNS: { + Enabled: + false + } + } +} + +exports.setUpProcNode = (addrs, hop, callback) => { + if (typeof hop === 'function') { + callback = hop + hop = false + } + + procDf.spawn({ + initOptions: { bits: 512 }, + config: Object.assign({}, baseConf, { + Addresses: { + Swarm: addrs + }, + EXPERIMENTAL: { + relay: { + enabled: true, + hop: { + enabled: hop + } + } + } + }) + }, (err, ipfsd) => { + expect(err).to.not.exist() + ipfsd.api.id((err, id) => { + callback(err, { ipfsd, addrs: id.addresses }) + }) + }) +} + +exports.setUpJsNode = (addrs, hop, callback) => { + if (typeof hop === 'function') { + callback = hop + hop = false + } + + jsDf.spawn({ + initOptions: { bits: 512 }, + config: Object.assign({}, baseConf, { + Addresses: { + Swarm: addrs + }, + EXPERIMENTAL: { + relay: { + enabled: true, + hop: { + enabled: hop + } + } + } + }) + }, (err, ipfsd) => { + expect(err).to.not.exist() + ipfsd.api.id((err, id) => { + callback(err, { ipfsd, addrs: id.addresses }) + }) + }) +} + +exports.setUpGoNode = (addrs, hop, callback) => { + if (typeof hop === 'function') { + callback = hop + hop = false + } + + goDf.spawn({ + initOptions: { bits: 1024 }, + config: Object.assign({}, baseConf, { + Addresses: { + Swarm: addrs + }, + Swarm: { + DisableRelay: false, + EnableRelayHop: hop + } + }) + }, (err, ipfsd) => { + expect(err).to.not.exist() + ipfsd.api.id((err, id) => { + const addrs = [].concat(id.addresses, [`/p2p-circuit/ipfs/${id.id}`]) + callback(err, { ipfsd, addrs: addrs }) + }) + }) +} + +exports.create = (nodes, callback) => { + series( + Object.keys(nodes).map((key) => (cb) => { + const node = nodes[key] + return node.exec(node.addrs, true, (err, res) => { + expect(err).to.not.exist() + cb(null, { + name: key, + node: res + }) + }) + }), (err, res) => { + if (err) { return callback(err) } + callback(null, res) + }) +} + +exports.connect = (connect, nodes, callback) => { + const seq = connect.map((step) => { + const nodeA = nodes.find((node) => node.name === step[0].name) + const nodeB = nodes.find((node) => node.name === step[1].name) + + return (cb) => { + const addr = step[0].parser(nodeB.node.addrs) + nodeA.node.ipfsd.api.swarm.connect(addr, (err) => setTimeout(cb, 1000, err)) + } + }) + + series(seq.map((func) => (cb) => func(cb)), callback) +} + +const data = crypto.randomBytes(128) +exports.send = (send, nodes, callback) => { + const nodeA = nodes.find((node) => node.name === send[0]).node.ipfsd.api + const nodeB = nodes.find((node) => node.name === send[1]).node.ipfsd.api + waterfall([ + (cb) => nodeA.files.add(data, cb), + (res, cb) => nodeB.files.cat(res[0].hash, cb), + (buffer, cb) => { + expect(buffer).to.deep.equal(data) + cb() + } + ], (err) => { + expect(err).to.not.exist() + callback() + }) +} + +exports.wsAddr = (addrs) => addrs + .map((a) => a.toString()) + .find((a) => { + return a.includes('/ws') && !a.includes('/p2p-websocket-star') + }) + +exports.wsStarAddr = (addrs) => addrs + .map((a) => a.toString()) + .find((a) => a.includes('/p2p-websocket-star')) + +exports.wrtcStarAddr = (addrs) => addrs + .map((a) => a.toString()) + .find((a) => a.includes('/p2p-webrtc-star')) + +exports.tcpAddr = (addrs) => addrs + .map((a) => a.toString()) + .find((a) => !a.includes('/ws') && !a.includes('/p2p-websocket-star')) + +exports.circuitAddr = (addrs) => addrs + .map((a) => a.toString()) + .find((a) => a.includes('/p2p-circuit/ipfs')) + From 645bf5fc98bd77edbe0bc5a897f52797ff1ca43e Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 2 Mar 2018 18:47:52 -0600 Subject: [PATCH 26/49] remove runaway only --- test/circuit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/circuit.js b/test/circuit.js index 2d84d99d..69473d22 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -665,7 +665,7 @@ const tests = [ } ] -describe.only('circuit', () => { +describe('circuit', () => { tests.forEach((test) => { let nodes From 08d168c65b0bc012dcf327a3825f24ba5f7d1225 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 2 Mar 2018 19:46:00 -0600 Subject: [PATCH 27/49] lint --- test/circuit.js | 1 - test/utils/circuit.js | 1 - 2 files changed, 2 deletions(-) diff --git a/test/circuit.js b/test/circuit.js index 69473d22..991de2e2 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -47,7 +47,6 @@ const base = '/ip4/127.0.0.1/tcp' // that breaks the flow and also any attempt to // generalize and abstract things out - /** * Legend: * - `name` - the name of the test diff --git a/test/utils/circuit.js b/test/utils/circuit.js index 2bcf3807..5fbfcda5 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -183,4 +183,3 @@ exports.tcpAddr = (addrs) => addrs exports.circuitAddr = (addrs) => addrs .map((a) => a.toString()) .find((a) => a.includes('/p2p-circuit/ipfs')) - From 14059eda4b0eec6d6826b895a1330dcf04933ea4 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 2 Mar 2018 22:46:36 -0600 Subject: [PATCH 28/49] even better tests --- .aegir.js | 5 +- package.json | 6 +- test/circuit.js | 836 +++++++++++------------------------------- test/utils/circuit.js | 68 +--- 4 files changed, 216 insertions(+), 699 deletions(-) diff --git a/.aegir.js b/.aegir.js index 9eef3cac..c40c7a1f 100644 --- a/.aegir.js +++ b/.aegir.js @@ -16,10 +16,7 @@ module.exports = { included: false }], singleRun: true, - captureTimeout: 5000 * 1000, - // browserDisconnectTolerance: 3, //this one helps - browserDisconnectTimeout: 5000 * 1000, - browserNoActivityTimeout: 5000 * 1000 + browserNoActivityTimeout: 100 * 1000 }, hooks: { browser: { diff --git a/package.json b/package.json index 011c192b..adcdcfd9 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ }, "scripts": { "lint": "aegir lint", - "test": "cross-env IPFS_REUSEPORT=false aegir test -t node -t browser --no-cors --timeout 50000", - "test:node": "cross-env IPFS_REUSEPORT=false aegir test -t node -f test/node.js --timeout 50000", - "test:browser": "cross-env IPFS_REUSEPORT=false aegir test -t browser --no-cors -f test/browser.js --timeout 100000" + "test": "cross-env IPFS_REUSEPORT=false aegir test -t node -t browser --no-cors", + "test:node": "cross-env IPFS_REUSEPORT=false aegir test -t node -f test/node.js", + "test:browser": "cross-env IPFS_REUSEPORT=false aegir test -t browser --no-cors -f test/browser.js" }, "pre-commit": [ "lint" diff --git a/test/circuit.js b/test/circuit.js index 991de2e2..7d1dc4cc 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -2,14 +2,11 @@ /* 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 isNode = require('detect-node') + const utils = require('./utils/circuit') const proc = utils.setUpProcNode @@ -20,672 +17,247 @@ const ws = utils.wsAddr const star = utils.wsStarAddr const circuit = utils.circuitAddr -const create = utils.create -const connect = utils.connect const send = utils.send -const base = '/ip4/127.0.0.1/tcp' +const base = '/ip4/127.0.0.1/tcp/0' -// TODO: (dryajov) circuit tests ended up being -// more complex than expected, the majority -// of the complexity comes from spawning and -// connecting the nodes. -// -// I've come up with this little DSL to avoid -// duplicating code all over the place. Some -// notable quirks that lead to this: -// -// - ipfs-api connect, doesn't support peer ids, -// only plain addresses, hence we end up filtering -// addresses (clunky) -// - not all connect sequences work in all cases -// - i.e. cant connect to browser relays since -// go doesn't support the star protos, so the -// sequence has to be changed to connect the -// browser relay to the nodes instead -// -// that breaks the flow and also any attempt to -// generalize and abstract things out +const connect = (nodeA, nodeB, relay, callback) => { + series([ + (cb) => nodeA.ipfsd.api.swarm.connect(ws(relay.addrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeB.ipfsd.api.swarm.connect(ws(relay.addrs), cb), + (cb) => setTimeout(cb, 1000), + (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) + ], callback) +} -/** - * Legend: - * - `name` - the name of the test - * - `nodes` - object containing the nodes to spawn - * - `key` - the key of the object is the name - * - `exec` - the method used to spawn the node, there are tree `js`, `go` and `proc` - * - `addrs` - the address to spawn the node with - * - `connect` - array of arrays describing how to connect the nodes, reads from left to right - * the first element connects to the second. A tuple contains objects of the for of - * [{name: 'node1', parser: js}, {name: 'relay'}] - * - `name` - the name of the node - * - `parser` - the parsing function used to extract the address - * - `send` - array describing the direction in which to send the data - * ['node1', 'node2'] send from node1 to node2 - * - * - * { - * name: 'go-go-go', // name of the test, what shows in the describe - * nodes: { // describes the nodes section - * node1: { // name of the node - * exec: go, // the function to create the nodes - * addrs: [`${base}/0/ws`] // address of the node - * }, - * relay: { - * exec: go, - * addrs: [`${base}/0/ws`] - * }, - * node2: { - * exec: go, - * addrs: [`${base}/0/ws`] - * } - * }, - * connect: [ // describes how to connect the nodes - * [{ name: 'node1', parser: ws }, { name: 'relay' }], // connect node1 to relay use ws parser to filter the address - * [{ name: 'node2', parser: ws }, { name: 'relay' }], // connect node2 to relay use ws parser to filter the address - * [{ name: 'node1', parser: circuit }, { name: 'node2' }] // connect node1 to node2 use circuit parser to filter the address - * ], - * send: ['node1', 'node2'] // describe the direction which data is sent - node1 to node2 - * skip: () => true // method called to determine if the tests should be skipped - * } - */ +const timeout = 30 * 1000 -const tests = [ - { - name: 'go-go-go', - nodes: { - node1: { - exec: go, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: go, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: go, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'] - }, - { - name: 'js-go-go', - nodes: { - node1: { - exec: js, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: go, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: go, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => true - }, - { - name: 'js-go-js', - nodes: { - node1: { - exec: js, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: go, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: js, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'] - }, - { - name: 'js-js-js', - nodes: { - node1: { - exec: js, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: js, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: js, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'] - }, - { - name: 'js-js-go', - nodes: { - node1: { - exec: js, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: js, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: go, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'] - }, - { - name: 'go-js-go', - nodes: { - node1: { - exec: go, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: js, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: go, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'] - }, - { - name: 'browser-js-go', - nodes: { - node1: { - exec: proc, - addrs: [] - }, - relay: { - exec: js, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: go, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode +const baseTest = { + connect, + send, + timeout +} + +let tests = { + 'js-go-js': { + create: (callback) => series([ + (cb) => js([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb) + ], callback) }, - { - name: 'browser-js-js', - nodes: { - node1: { - exec: proc, - addrs: [] - }, - relay: { - exec: js, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: js, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'go-go-js': { + create: (callback) => series([ + (cb) => go([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb) + ], callback) }, - { - name: 'js-js-browser', - nodes: { - node1: { - exec: js, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: js, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: proc, - addrs: [] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'go-go-go': { + create: (callback) => series([ + (cb) => go([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb) + ], callback) }, - { - name: 'go-js-browser', - nodes: { - node1: { - exec: go, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: js, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: proc, - addrs: [] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'go-js-go': { + create: (callback) => series([ + (cb) => go([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb) + ], callback) }, - { - name: 'browser-js-browser', - nodes: { - node1: { - exec: proc, - addrs: [] - }, - relay: { - exec: js, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: proc, - addrs: [] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'js-js-go': { + create: (callback) => series([ + (cb) => js([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb) + ], callback), + timeout: 50 * 1000 }, - { - name: 'browser-go-go', - nodes: { - node1: { - exec: proc, - addrs: [] - }, - relay: { - exec: go, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: go, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'js-js-js': { + create: (callback) => series([ + (cb) => js([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb) + ], callback), + timeout: 50 * 1000 + } +} + +const browser = { + 'browser-go-js': { + create: + (callback) => series([ + (cb) => proc([], cb), + (cb) => go([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb) + ], callback), + timeout: 50 * 1000 }, - { - name: 'browser-go-js', - nodes: { - node1: { - exec: proc, - addrs: [] - }, - relay: { - exec: go, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: js, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'browser-go-go': { + create: (callback) => series([ + (cb) => proc([], cb), + (cb) => go([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb) + ], callback), + timeout: 50 * 1000 }, - { - name: 'js-go-browser', - nodes: { - node1: { - exec: js, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: go, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: proc, - addrs: [] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'browser-js-js': { + create: (callback) => series([ + (cb) => proc([], cb), + (cb) => js([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb) + ], callback), + timeout: 50 * 1000 }, - { - name: 'go-go-browser', - nodes: { - node1: { - exec: go, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: go, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: proc, - addrs: [] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'browser-js-go': { + create: (callback) => series([ + (cb) => proc([], cb), + (cb) => js([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb) + ], callback), + timeout: 50 * 1000 }, - { - name: 'browser-go-browser', - nodes: { - node1: { - exec: proc, - addrs: [] - }, - relay: { - exec: go, - addrs: [`${base}/0/ws`] - }, - node2: { - exec: proc, - addrs: [] - } - }, - connect: [ - [{ name: 'node1', parser: ws }, { name: 'relay' }], - [{ name: 'node2', parser: ws }, { name: 'relay' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => true + 'js-go-browser': { + create: (callback) => series([ + (cb) => js([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb), + (cb) => proc([], cb) + ], callback), + timeout: 50 * 1000 }, - { - name: 'go-browser-browser', - nodes: { - node1: { - exec: go, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: proc, - addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], - relay: true - }, - node2: { - exec: proc, - addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] - } - }, - connect: [ - [{ name: 'relay', parser: ws }, { name: 'node1' }], - [{ name: 'relay', parser: star }, { name: 'node2' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'go-go-browser': { + create: (callback) => series([ + (cb) => go([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb), + (cb) => proc([], cb) + ], callback), + timeout: 50 * 1000 }, - { - name: 'go-browser-js', - nodes: { - node1: { - exec: go, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: proc, - addrs: [] - }, - node2: { - exec: js, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'relay', parser: ws }, { name: 'node1' }], - [{ name: 'relay', parser: ws }, { name: 'node2' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'js-js-browser': { + create: (callback) => series([ + (cb) => js([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb), + (cb) => proc([], cb) + ], callback), + timeout: 50 * 1000 }, - { - name: 'go-browser-go', - nodes: { - node1: { - exec: go, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: proc, - addrs: [] - }, - node2: { - exec: go, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'relay', parser: ws }, { name: 'node1' }], - [{ name: 'relay', parser: ws }, { name: 'node2' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => true + 'go-js-browser': { + create: (callback) => series([ + (cb) => go([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb), + (cb) => proc([], cb) + ], callback), + timeout: 50 * 1000 }, - { - name: 'js-browser-js', - nodes: { - node1: { - exec: js, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: proc, - addrs: [] - }, - node2: { - exec: js, - addrs: [`${base}/0/ws`] - } + 'go-browser-browser': { + create: (callback) => series([ + (cb) => go([`${base}/ws`], cb), + (cb) => setTimeout(cb, 2000), + (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => setTimeout(cb, 2000), + (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) + ], callback), + connect: (nodeA, nodeB, relay, callback) => { + series([ + (cb) => relay.ipfsd.api.swarm.connect(ws(nodeA.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => relay.ipfsd.api.swarm.connect(star(nodeB.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) + ], callback) }, - connect: [ - [{ name: 'relay', parser: ws }, { name: 'node1' }], - [{ name: 'relay', parser: ws }, { name: 'node2' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + timeout: 80 * 1000 }, - { - name: 'js-browser-go', - nodes: { - node1: { - exec: js, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: proc, - addrs: [] - }, - node2: { - exec: go, - addrs: [`${base}/0/ws`] - } + 'js-browser-browser': { + create: (callback) => series([ + (cb) => js([`${base}/ws`], cb), + (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) + ], callback), + connect: (nodeA, nodeB, relay, callback) => { + series([ + (cb) => relay.ipfsd.api.swarm.connect(ws(nodeA.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => relay.ipfsd.api.swarm.connect(star(nodeB.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) + ], callback) }, - connect: [ - [{ name: 'relay', parser: ws }, { name: 'node1' }], - [{ name: 'relay', parser: ws }, { name: 'node2' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + timeout: 80 * 1000 }, - { - name: 'js-browser-browser', - nodes: { - node1: { - exec: js, - addrs: [`${base}/0/ws`] - }, - relay: { - exec: proc, - addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] - }, - node2: { - exec: proc, - addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] - } + 'browser-browser-go': { + create: (callback) => series([ + (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => go([`${base}/ws`], cb) + ], callback), + connect: (nodeA, nodeB, relay, callback) => { + series([ + (cb) => relay.ipfsd.api.swarm.connect(star(nodeA.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => relay.ipfsd.api.swarm.connect(ws(nodeB.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) + ], callback) }, - connect: [ - [{ name: 'relay', parser: ws }, { name: 'node1' }], - [{ name: 'relay', parser: star }, { name: 'node2' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + timeout: 80 * 1000 }, - { - name: 'browser-browser-js', - nodes: { - node1: { - exec: proc, - addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] - }, - relay: { - exec: proc, - addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] - }, - node2: { - exec: js, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'relay', parser: star }, { name: 'node1' }], - [{ name: 'relay', parser: ws }, { name: 'node2' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => isNode + 'browser-browser-js': { + create: (callback) => series([ + (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => js([`${base}/ws`], cb) + ], callback), + connect: (nodeA, nodeB, relay, callback) => { + series([ + (cb) => relay.ipfsd.api.swarm.connect(star(nodeA.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => relay.ipfsd.api.swarm.connect(ws(nodeB.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) + ], callback) + } }, - { - name: 'browser-browser-go', - nodes: { - node1: { - exec: proc, - addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] - }, - relay: { - exec: proc, - addrs: [`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`] - }, - node2: { - exec: go, - addrs: [`${base}/0/ws`] - } - }, - connect: [ - [{ name: 'relay', parser: star }, { name: 'node1' }], - [{ name: 'relay', parser: ws }, { name: 'node2' }], - [{ name: 'node1', parser: circuit }, { name: 'node2' }] - ], - send: ['node1', 'node2'], - skip: () => true + timeout: 80 * 1000 +} + +describe.only('circuit', () => { + if (!isNode) { + tests = Object.assign([], tests, browser) } -] -describe('circuit', () => { - tests.forEach((test) => { + Object.keys(tests).forEach((test) => { let nodes + let nodeA + let relay + let nodeB + + tests[test] = Object.assign({}, baseTest, tests[test]) + const dsc = tests[test].skip && tests[test].skip() ? describe.skip : describe + dsc(test, function () { + this.timeout(tests[test].timeout) - const dsc = test.skip && test.skip() ? describe.skip : describe - dsc(test.name, function () { before((done) => { - create(test.nodes, (err, _nodes) => { - expect(err).to.not.exist() - nodes = _nodes + tests[test].create((err, _nodes) => { + nodes = _nodes.map((n) => n.ipfsd) + nodeA = _nodes[0] + relay = _nodes[1] + nodeB = _nodes[2] done() }) }) - after((done) => parallel(nodes.map((node) => (cb) => node.node.ipfsd.stop(cb)), done)) + after((done) => parallel(nodes.map((ipfsd) => (cb) => ipfsd.stop(cb)), done)) it('connect', (done) => { - connect(test.connect, nodes, done) + tests[test].connect(nodeA, nodeB, relay, done) }) it('send', (done) => { - send(test.send, nodes, done) + tests[test].send(nodeA.ipfsd.api, nodeB.ipfsd.api, done) }) }) }) diff --git a/test/utils/circuit.js b/test/utils/circuit.js index 5fbfcda5..8a133b2a 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -5,7 +5,6 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const series = require('async/series') const waterfall = require('async/waterfall') const crypto = require('crypto') @@ -30,12 +29,7 @@ const baseConf = { } } -exports.setUpProcNode = (addrs, hop, callback) => { - if (typeof hop === 'function') { - callback = hop - hop = false - } - +exports.setUpProcNode = (addrs, callback) => { procDf.spawn({ initOptions: { bits: 512 }, config: Object.assign({}, baseConf, { @@ -46,7 +40,7 @@ exports.setUpProcNode = (addrs, hop, callback) => { relay: { enabled: true, hop: { - enabled: hop + enabled: true } } } @@ -59,12 +53,7 @@ exports.setUpProcNode = (addrs, hop, callback) => { }) } -exports.setUpJsNode = (addrs, hop, callback) => { - if (typeof hop === 'function') { - callback = hop - hop = false - } - +exports.setUpJsNode = (addrs, callback) => { jsDf.spawn({ initOptions: { bits: 512 }, config: Object.assign({}, baseConf, { @@ -75,7 +64,7 @@ exports.setUpJsNode = (addrs, hop, callback) => { relay: { enabled: true, hop: { - enabled: hop + enabled: true } } } @@ -88,12 +77,7 @@ exports.setUpJsNode = (addrs, hop, callback) => { }) } -exports.setUpGoNode = (addrs, hop, callback) => { - if (typeof hop === 'function') { - callback = hop - hop = false - } - +exports.setUpGoNode = (addrs, callback) => { goDf.spawn({ initOptions: { bits: 1024 }, config: Object.assign({}, baseConf, { @@ -102,7 +86,7 @@ exports.setUpGoNode = (addrs, hop, callback) => { }, Swarm: { DisableRelay: false, - EnableRelayHop: hop + EnableRelayHop: true } }) }, (err, ipfsd) => { @@ -114,41 +98,8 @@ exports.setUpGoNode = (addrs, hop, callback) => { }) } -exports.create = (nodes, callback) => { - series( - Object.keys(nodes).map((key) => (cb) => { - const node = nodes[key] - return node.exec(node.addrs, true, (err, res) => { - expect(err).to.not.exist() - cb(null, { - name: key, - node: res - }) - }) - }), (err, res) => { - if (err) { return callback(err) } - callback(null, res) - }) -} - -exports.connect = (connect, nodes, callback) => { - const seq = connect.map((step) => { - const nodeA = nodes.find((node) => node.name === step[0].name) - const nodeB = nodes.find((node) => node.name === step[1].name) - - return (cb) => { - const addr = step[0].parser(nodeB.node.addrs) - nodeA.node.ipfsd.api.swarm.connect(addr, (err) => setTimeout(cb, 1000, err)) - } - }) - - series(seq.map((func) => (cb) => func(cb)), callback) -} - const data = crypto.randomBytes(128) -exports.send = (send, nodes, callback) => { - const nodeA = nodes.find((node) => node.name === send[0]).node.ipfsd.api - const nodeB = nodes.find((node) => node.name === send[1]).node.ipfsd.api +exports.send = (nodeA, nodeB, callback) => { waterfall([ (cb) => nodeA.files.add(data, cb), (res, cb) => nodeB.files.cat(res[0].hash, cb), @@ -156,10 +107,7 @@ exports.send = (send, nodes, callback) => { expect(buffer).to.deep.equal(data) cb() } - ], (err) => { - expect(err).to.not.exist() - callback() - }) + ], callback) } exports.wsAddr = (addrs) => addrs From 4f7451f294c0a1509d22587ec891211115d0f785 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 3 Mar 2018 01:29:19 -0600 Subject: [PATCH 29/49] test: connect browser nodes with tiemout --- test/circuit.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/test/circuit.js b/test/circuit.js index 7d1dc4cc..a4f4447e 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -2,6 +2,11 @@ /* 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') @@ -21,12 +26,17 @@ const send = utils.send const base = '/ip4/127.0.0.1/tcp/0' -const connect = (nodeA, nodeB, relay, callback) => { +const connect = (nodeA, nodeB, relay, timeout, callback) => { + if (typeof timeout === 'function') { + callback = timeout + timeout = 500 + } + series([ (cb) => nodeA.ipfsd.api.swarm.connect(ws(relay.addrs), cb), - (cb) => setTimeout(cb, 1000), + (cb) => setTimeout(cb, timeout), (cb) => nodeB.ipfsd.api.swarm.connect(ws(relay.addrs), cb), - (cb) => setTimeout(cb, 1000), + (cb) => setTimeout(cb, timeout), (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) ], callback) } @@ -169,7 +179,8 @@ const browser = { (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) ], callback) }, - timeout: 80 * 1000 + timeout: 100 * 1000, + skip: () => true }, 'js-browser-browser': { create: (callback) => series([ @@ -186,7 +197,7 @@ const browser = { (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) ], callback) }, - timeout: 80 * 1000 + timeout: 100 * 1000 }, 'browser-browser-go': { create: (callback) => series([ @@ -203,7 +214,8 @@ const browser = { (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) ], callback) }, - timeout: 80 * 1000 + timeout: 100 * 1000, + skip: () => true }, 'browser-browser-js': { create: (callback) => series([ @@ -220,8 +232,7 @@ const browser = { (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) ], callback) } - }, - timeout: 80 * 1000 + } } describe.only('circuit', () => { @@ -242,6 +253,7 @@ describe.only('circuit', () => { before((done) => { tests[test].create((err, _nodes) => { + expect(err).to.not.exist() nodes = _nodes.map((n) => n.ipfsd) nodeA = _nodes[0] relay = _nodes[1] From 35253ac5d36341a83945f7109d2837ddee085211 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 3 Mar 2018 13:46:01 -0600 Subject: [PATCH 30/49] parametrize timeouts --- test/circuit.js | 55 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/test/circuit.js b/test/circuit.js index a4f4447e..4805cec6 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -42,7 +42,6 @@ const connect = (nodeA, nodeB, relay, timeout, callback) => { } const timeout = 30 * 1000 - const baseTest = { connect, send, @@ -50,11 +49,18 @@ const baseTest = { } let tests = { - 'js-go-js': { + 'go-go-go': { + create: (callback) => series([ + (cb) => go([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb), + (cb) => go([`${base}/ws`], cb) + ], callback) + }, + 'js-go-go': { create: (callback) => series([ (cb) => js([`${base}/ws`], cb), (cb) => go([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb) + (cb) => go([`${base}/ws`], cb) ], callback) }, 'go-go-js': { @@ -64,11 +70,11 @@ let tests = { (cb) => js([`${base}/ws`], cb) ], callback) }, - 'go-go-go': { + 'js-go-js': { create: (callback) => series([ + (cb) => js([`${base}/ws`], cb), (cb) => go([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb) + (cb) => js([`${base}/ws`], cb) ], callback) }, 'go-js-go': { @@ -86,6 +92,14 @@ let tests = { ], callback), timeout: 50 * 1000 }, + 'go-js-js': { + create: (callback) => series([ + (cb) => go([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb), + (cb) => js([`${base}/ws`], cb) + ], callback), + timeout: 50 * 1000 + }, 'js-js-js': { create: (callback) => series([ (cb) => js([`${base}/ws`], cb), @@ -96,6 +110,11 @@ let tests = { } } +const connWithTimeout = (timeout) => { + return (nodeA, nodeB, relay, callback) => { + connect(nodeA, nodeB, relay, timeout, callback) + } +} const browser = { 'browser-go-js': { create: @@ -104,7 +123,8 @@ const browser = { (cb) => go([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb) ], callback), - timeout: 50 * 1000 + timeout: 50 * 1000, + connect: connWithTimeout(1000) }, 'browser-go-go': { create: (callback) => series([ @@ -112,7 +132,8 @@ const browser = { (cb) => go([`${base}/ws`], cb), (cb) => go([`${base}/ws`], cb) ], callback), - timeout: 50 * 1000 + timeout: 50 * 1000, + connect: connWithTimeout(1000) }, 'browser-js-js': { create: (callback) => series([ @@ -120,7 +141,8 @@ const browser = { (cb) => js([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb) ], callback), - timeout: 50 * 1000 + timeout: 50 * 1000, + connect: connWithTimeout(1000) }, 'browser-js-go': { create: (callback) => series([ @@ -128,7 +150,8 @@ const browser = { (cb) => js([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb) ], callback), - timeout: 50 * 1000 + timeout: 50 * 1000, + connect: connWithTimeout(1000) }, 'js-go-browser': { create: (callback) => series([ @@ -136,7 +159,8 @@ const browser = { (cb) => go([`${base}/ws`], cb), (cb) => proc([], cb) ], callback), - timeout: 50 * 1000 + timeout: 50 * 1000, + connect: connWithTimeout(1000) }, 'go-go-browser': { create: (callback) => series([ @@ -144,7 +168,8 @@ const browser = { (cb) => go([`${base}/ws`], cb), (cb) => proc([], cb) ], callback), - timeout: 50 * 1000 + timeout: 50 * 1000, + connect: connWithTimeout(1000) }, 'js-js-browser': { create: (callback) => series([ @@ -152,7 +177,8 @@ const browser = { (cb) => js([`${base}/ws`], cb), (cb) => proc([], cb) ], callback), - timeout: 50 * 1000 + timeout: 50 * 1000, + connect: connWithTimeout(1000) }, 'go-js-browser': { create: (callback) => series([ @@ -160,7 +186,8 @@ const browser = { (cb) => js([`${base}/ws`], cb), (cb) => proc([], cb) ], callback), - timeout: 50 * 1000 + timeout: 50 * 1000, + connect: connWithTimeout(1000) }, 'go-browser-browser': { create: (callback) => series([ From 1a947d3acb584b638d37a4aee1d94c1aad836a9c Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 3 Mar 2018 14:30:48 -0600 Subject: [PATCH 31/49] reenable skipped test --- test/circuit.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/test/circuit.js b/test/circuit.js index 4805cec6..3117b9f2 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -29,7 +29,7 @@ const base = '/ip4/127.0.0.1/tcp/0' const connect = (nodeA, nodeB, relay, timeout, callback) => { if (typeof timeout === 'function') { callback = timeout - timeout = 500 + timeout = 1000 } series([ @@ -41,7 +41,7 @@ const connect = (nodeA, nodeB, relay, timeout, callback) => { ], callback) } -const timeout = 30 * 1000 +const timeout = 40 * 1000 const baseTest = { connect, send, @@ -124,7 +124,7 @@ const browser = { (cb) => js([`${base}/ws`], cb) ], callback), timeout: 50 * 1000, - connect: connWithTimeout(1000) + connect: connWithTimeout(1500) }, 'browser-go-go': { create: (callback) => series([ @@ -133,7 +133,7 @@ const browser = { (cb) => go([`${base}/ws`], cb) ], callback), timeout: 50 * 1000, - connect: connWithTimeout(1000) + connect: connWithTimeout(1500) }, 'browser-js-js': { create: (callback) => series([ @@ -142,7 +142,7 @@ const browser = { (cb) => js([`${base}/ws`], cb) ], callback), timeout: 50 * 1000, - connect: connWithTimeout(1000) + connect: connWithTimeout(1500) }, 'browser-js-go': { create: (callback) => series([ @@ -151,7 +151,7 @@ const browser = { (cb) => js([`${base}/ws`], cb) ], callback), timeout: 50 * 1000, - connect: connWithTimeout(1000) + connect: connWithTimeout(1500) }, 'js-go-browser': { create: (callback) => series([ @@ -160,7 +160,7 @@ const browser = { (cb) => proc([], cb) ], callback), timeout: 50 * 1000, - connect: connWithTimeout(1000) + connect: connWithTimeout(1500) }, 'go-go-browser': { create: (callback) => series([ @@ -169,7 +169,7 @@ const browser = { (cb) => proc([], cb) ], callback), timeout: 50 * 1000, - connect: connWithTimeout(1000) + connect: connWithTimeout(1500) }, 'js-js-browser': { create: (callback) => series([ @@ -178,7 +178,7 @@ const browser = { (cb) => proc([], cb) ], callback), timeout: 50 * 1000, - connect: connWithTimeout(1000) + connect: connWithTimeout(1500) }, 'go-js-browser': { create: (callback) => series([ @@ -187,14 +187,12 @@ const browser = { (cb) => proc([], cb) ], callback), timeout: 50 * 1000, - connect: connWithTimeout(1000) + connect: connWithTimeout(1500) }, 'go-browser-browser': { create: (callback) => series([ (cb) => go([`${base}/ws`], cb), - (cb) => setTimeout(cb, 2000), (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => setTimeout(cb, 2000), (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) ], callback), connect: (nodeA, nodeB, relay, callback) => { @@ -206,8 +204,7 @@ const browser = { (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) ], callback) }, - timeout: 100 * 1000, - skip: () => true + timeout: 100 * 1000 }, 'js-browser-browser': { create: (callback) => series([ @@ -262,7 +259,7 @@ const browser = { } } -describe.only('circuit', () => { +describe('circuit', () => { if (!isNode) { tests = Object.assign([], tests, browser) } From 3bb68f9ddc9bd1e9dc3162e8997690f592c625d9 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sun, 4 Mar 2018 15:16:31 -0600 Subject: [PATCH 32/49] skip go-browser-browser --- test/circuit.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/test/circuit.js b/test/circuit.js index 3117b9f2..bac24ff1 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -41,7 +41,7 @@ const connect = (nodeA, nodeB, relay, timeout, callback) => { ], callback) } -const timeout = 40 * 1000 +const timeout = 60 * 1000 const baseTest = { connect, send, @@ -89,24 +89,21 @@ let tests = { (cb) => js([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb), (cb) => go([`${base}/ws`], cb) - ], callback), - timeout: 50 * 1000 + ], callback) }, 'go-js-js': { create: (callback) => series([ (cb) => go([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb) - ], callback), - timeout: 50 * 1000 + ], callback) }, 'js-js-js': { create: (callback) => series([ (cb) => js([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb) - ], callback), - timeout: 50 * 1000 + ], callback) } } @@ -123,7 +120,6 @@ const browser = { (cb) => go([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb) ], callback), - timeout: 50 * 1000, connect: connWithTimeout(1500) }, 'browser-go-go': { @@ -132,7 +128,6 @@ const browser = { (cb) => go([`${base}/ws`], cb), (cb) => go([`${base}/ws`], cb) ], callback), - timeout: 50 * 1000, connect: connWithTimeout(1500) }, 'browser-js-js': { @@ -141,7 +136,6 @@ const browser = { (cb) => js([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb) ], callback), - timeout: 50 * 1000, connect: connWithTimeout(1500) }, 'browser-js-go': { @@ -150,7 +144,6 @@ const browser = { (cb) => js([`${base}/ws`], cb), (cb) => js([`${base}/ws`], cb) ], callback), - timeout: 50 * 1000, connect: connWithTimeout(1500) }, 'js-go-browser': { @@ -159,7 +152,6 @@ const browser = { (cb) => go([`${base}/ws`], cb), (cb) => proc([], cb) ], callback), - timeout: 50 * 1000, connect: connWithTimeout(1500) }, 'go-go-browser': { @@ -168,7 +160,6 @@ const browser = { (cb) => go([`${base}/ws`], cb), (cb) => proc([], cb) ], callback), - timeout: 50 * 1000, connect: connWithTimeout(1500) }, 'js-js-browser': { @@ -177,7 +168,6 @@ const browser = { (cb) => js([`${base}/ws`], cb), (cb) => proc([], cb) ], callback), - timeout: 50 * 1000, connect: connWithTimeout(1500) }, 'go-js-browser': { @@ -186,7 +176,6 @@ const browser = { (cb) => js([`${base}/ws`], cb), (cb) => proc([], cb) ], callback), - timeout: 50 * 1000, connect: connWithTimeout(1500) }, 'go-browser-browser': { @@ -204,7 +193,8 @@ const browser = { (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) ], callback) }, - timeout: 100 * 1000 + timeout: 100 * 1000, + skip: () => true }, 'js-browser-browser': { create: (callback) => series([ From 7157e5d2de5b89a65187be9dc2a300c5245cebaf Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 5 Mar 2018 02:13:05 -0600 Subject: [PATCH 33/49] timeout --- test/circuit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/circuit.js b/test/circuit.js index bac24ff1..551e6315 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -41,7 +41,7 @@ const connect = (nodeA, nodeB, relay, timeout, callback) => { ], callback) } -const timeout = 60 * 1000 +const timeout = 80 * 1000 const baseTest = { connect, send, From 6ff891ed9f2b18406a12ac3cc86fd318ea383271 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Mar 2018 10:58:55 -0600 Subject: [PATCH 34/49] cleanup based on review --- package.json | 3 +- test/circuit.js | 126 ++++++++++++++++++++++++------------------------ 2 files changed, 64 insertions(+), 65 deletions(-) diff --git a/package.json b/package.json index adcdcfd9..06306c45 100644 --- a/package.json +++ b/package.json @@ -54,11 +54,10 @@ "form-data": "^2.3.1", "go-ipfs-dep": "^0.4.13", "hat": "0.0.3", - "ipfs": "^0.28.0", + "ipfs": "~0.28.0", "ipfs-api": "^18.1.1", "ipfsd-ctl": "~0.29.1", "left-pad": "^1.2.0", - "libp2p-websocket-star": "^0.7.2", "libp2p-websocket-star-rendezvous": "^0.2.2", "lodash": "^4.17.4", "mocha": "^4.0.1", diff --git a/test/circuit.js b/test/circuit.js index 551e6315..7abdf2b3 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -14,9 +14,9 @@ const isNode = require('detect-node') const utils = require('./utils/circuit') -const proc = utils.setUpProcNode -const js = utils.setUpJsNode -const go = utils.setUpGoNode +const getProc = utils.setUpProcNode +const getJs = utils.setUpJsNode +const getGo = utils.setUpGoNode const ws = utils.wsAddr const star = utils.wsStarAddr @@ -51,58 +51,58 @@ const baseTest = { let tests = { 'go-go-go': { create: (callback) => series([ - (cb) => go([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb) + (cb) => getGo([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb) ], callback) }, 'js-go-go': { create: (callback) => series([ - (cb) => js([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb) + (cb) => getJs([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb) ], callback) }, 'go-go-js': { create: (callback) => series([ - (cb) => go([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb) + (cb) => getGo([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb) ], callback) }, 'js-go-js': { create: (callback) => series([ - (cb) => js([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb) + (cb) => getJs([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb) ], callback) }, 'go-js-go': { create: (callback) => series([ - (cb) => go([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb) + (cb) => getGo([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb) ], callback) }, 'js-js-go': { create: (callback) => series([ - (cb) => js([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb) + (cb) => getJs([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb) ], callback) }, 'go-js-js': { create: (callback) => series([ - (cb) => go([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb) + (cb) => getGo([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb) ], callback) }, 'js-js-js': { create: (callback) => series([ - (cb) => js([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb) + (cb) => getJs([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb) ], callback) } } @@ -116,73 +116,73 @@ const browser = { 'browser-go-js': { create: (callback) => series([ - (cb) => proc([], cb), - (cb) => go([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb) + (cb) => getProc([], cb), + (cb) => getGo([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb) ], callback), connect: connWithTimeout(1500) }, 'browser-go-go': { create: (callback) => series([ - (cb) => proc([], cb), - (cb) => go([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb) + (cb) => getProc([], cb), + (cb) => getGo([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb) ], callback), connect: connWithTimeout(1500) }, 'browser-js-js': { create: (callback) => series([ - (cb) => proc([], cb), - (cb) => js([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb) + (cb) => getProc([], cb), + (cb) => getJs([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb) ], callback), connect: connWithTimeout(1500) }, 'browser-js-go': { create: (callback) => series([ - (cb) => proc([], cb), - (cb) => js([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb) + (cb) => getProc([], cb), + (cb) => getJs([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb) ], callback), connect: connWithTimeout(1500) }, 'js-go-browser': { create: (callback) => series([ - (cb) => js([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb), - (cb) => proc([], cb) + (cb) => getJs([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb), + (cb) => getProc([], cb) ], callback), connect: connWithTimeout(1500) }, 'go-go-browser': { create: (callback) => series([ - (cb) => go([`${base}/ws`], cb), - (cb) => go([`${base}/ws`], cb), - (cb) => proc([], cb) + (cb) => getGo([`${base}/ws`], cb), + (cb) => getGo([`${base}/ws`], cb), + (cb) => getProc([], cb) ], callback), connect: connWithTimeout(1500) }, 'js-js-browser': { create: (callback) => series([ - (cb) => js([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb), - (cb) => proc([], cb) + (cb) => getJs([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb), + (cb) => getProc([], cb) ], callback), connect: connWithTimeout(1500) }, 'go-js-browser': { create: (callback) => series([ - (cb) => go([`${base}/ws`], cb), - (cb) => js([`${base}/ws`], cb), - (cb) => proc([], cb) + (cb) => getGo([`${base}/ws`], cb), + (cb) => getJs([`${base}/ws`], cb), + (cb) => getProc([], cb) ], callback), connect: connWithTimeout(1500) }, 'go-browser-browser': { create: (callback) => series([ - (cb) => go([`${base}/ws`], cb), - (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) + (cb) => getGo([`${base}/ws`], cb), + (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ @@ -198,9 +198,9 @@ const browser = { }, 'js-browser-browser': { create: (callback) => series([ - (cb) => js([`${base}/ws`], cb), - (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) + (cb) => getJs([`${base}/ws`], cb), + (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ @@ -215,9 +215,9 @@ const browser = { }, 'browser-browser-go': { create: (callback) => series([ - (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => go([`${base}/ws`], cb) + (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => getGo([`${base}/ws`], cb) ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ @@ -233,9 +233,9 @@ const browser = { }, 'browser-browser-js': { create: (callback) => series([ - (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => proc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => js([`${base}/ws`], cb) + (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => getJs([`${base}/ws`], cb) ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ From e5f617ae9ce0cc789534d63154413f230e129252 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Mar 2018 11:20:26 -0600 Subject: [PATCH 35/49] fix: naming of funcs --- test/circuit.js | 162 +++++++++++++++++++++--------------------- test/utils/circuit.js | 6 +- 2 files changed, 84 insertions(+), 84 deletions(-) diff --git a/test/circuit.js b/test/circuit.js index 7abdf2b3..72142033 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -14,13 +14,13 @@ const isNode = require('detect-node') const utils = require('./utils/circuit') -const getProc = utils.setUpProcNode -const getJs = utils.setUpJsNode -const getGo = utils.setUpGoNode +const creatProc = utils.createProcNode +const createJs = utils.createJsNode +const createGo = utils.createUpGoNode -const ws = utils.wsAddr -const star = utils.wsStarAddr -const circuit = utils.circuitAddr +const wsAddr = utils.wsAddr +const wsStarAddr = utils.wsStarAddr +const circuitAddr = utils.circuitAddr const send = utils.send @@ -33,11 +33,11 @@ const connect = (nodeA, nodeB, relay, timeout, callback) => { } series([ - (cb) => nodeA.ipfsd.api.swarm.connect(ws(relay.addrs), cb), + (cb) => nodeA.ipfsd.api.swarm.connect(wsAddr(relay.addrs), cb), (cb) => setTimeout(cb, timeout), - (cb) => nodeB.ipfsd.api.swarm.connect(ws(relay.addrs), cb), + (cb) => nodeB.ipfsd.api.swarm.connect(wsAddr(relay.addrs), cb), (cb) => setTimeout(cb, timeout), - (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) + (cb) => nodeA.ipfsd.api.swarm.connect(circuitAddr(nodeB.addrs), cb) ], callback) } @@ -51,58 +51,58 @@ const baseTest = { let tests = { 'go-go-go': { create: (callback) => series([ - (cb) => getGo([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb) + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb) ], callback) }, 'js-go-go': { create: (callback) => series([ - (cb) => getJs([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb) + (cb) => createJs([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb) ], callback) }, 'go-go-js': { create: (callback) => series([ - (cb) => getGo([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb) + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) ], callback) }, 'js-go-js': { create: (callback) => series([ - (cb) => getJs([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb) + (cb) => createJs([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) ], callback) }, 'go-js-go': { create: (callback) => series([ - (cb) => getGo([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb) + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb) ], callback) }, 'js-js-go': { create: (callback) => series([ - (cb) => getJs([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb) + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb) ], callback) }, 'go-js-js': { create: (callback) => series([ - (cb) => getGo([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb) + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) ], callback) }, 'js-js-js': { create: (callback) => series([ - (cb) => getJs([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb) + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) ], callback) } } @@ -116,81 +116,81 @@ const browser = { 'browser-go-js': { create: (callback) => series([ - (cb) => getProc([], cb), - (cb) => getGo([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb) + (cb) => creatProc([], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) ], callback), connect: connWithTimeout(1500) }, 'browser-go-go': { create: (callback) => series([ - (cb) => getProc([], cb), - (cb) => getGo([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb) + (cb) => creatProc([], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb) ], callback), connect: connWithTimeout(1500) }, 'browser-js-js': { create: (callback) => series([ - (cb) => getProc([], cb), - (cb) => getJs([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb) + (cb) => creatProc([], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) ], callback), connect: connWithTimeout(1500) }, 'browser-js-go': { create: (callback) => series([ - (cb) => getProc([], cb), - (cb) => getJs([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb) + (cb) => creatProc([], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) ], callback), connect: connWithTimeout(1500) }, 'js-go-browser': { create: (callback) => series([ - (cb) => getJs([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb), - (cb) => getProc([], cb) + (cb) => createJs([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => creatProc([], cb) ], callback), connect: connWithTimeout(1500) }, 'go-go-browser': { create: (callback) => series([ - (cb) => getGo([`${base}/ws`], cb), - (cb) => getGo([`${base}/ws`], cb), - (cb) => getProc([], cb) + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => creatProc([], cb) ], callback), connect: connWithTimeout(1500) }, 'js-js-browser': { create: (callback) => series([ - (cb) => getJs([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb), - (cb) => getProc([], cb) + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => creatProc([], cb) ], callback), connect: connWithTimeout(1500) }, 'go-js-browser': { create: (callback) => series([ - (cb) => getGo([`${base}/ws`], cb), - (cb) => getJs([`${base}/ws`], cb), - (cb) => getProc([], cb) + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => creatProc([], cb) ], callback), connect: connWithTimeout(1500) }, 'go-browser-browser': { create: (callback) => series([ - (cb) => getGo([`${base}/ws`], cb), - (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) + (cb) => createGo([`${base}/ws`], cb), + (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ - (cb) => relay.ipfsd.api.swarm.connect(ws(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(wsAddr(nodeA.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(star(nodeB.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(wsStarAddr(nodeB.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) + (cb) => nodeA.ipfsd.api.swarm.connect(circuitAddr(nodeB.addrs), cb) ], callback) }, timeout: 100 * 1000, @@ -198,34 +198,34 @@ const browser = { }, 'js-browser-browser': { create: (callback) => series([ - (cb) => getJs([`${base}/ws`], cb), - (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) + (cb) => createJs([`${base}/ws`], cb), + (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ - (cb) => relay.ipfsd.api.swarm.connect(ws(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(wsAddr(nodeA.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(star(nodeB.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(wsStarAddr(nodeB.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) + (cb) => nodeA.ipfsd.api.swarm.connect(circuitAddr(nodeB.addrs), cb) ], callback) }, timeout: 100 * 1000 }, 'browser-browser-go': { create: (callback) => series([ - (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => getGo([`${base}/ws`], cb) + (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => createGo([`${base}/ws`], cb) ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ - (cb) => relay.ipfsd.api.swarm.connect(star(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(wsStarAddr(nodeA.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(ws(nodeB.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(wsAddr(nodeB.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) + (cb) => nodeA.ipfsd.api.swarm.connect(circuitAddr(nodeB.addrs), cb) ], callback) }, timeout: 100 * 1000, @@ -233,17 +233,17 @@ const browser = { }, 'browser-browser-js': { create: (callback) => series([ - (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => getProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => getJs([`${base}/ws`], cb) + (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => createJs([`${base}/ws`], cb) ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ - (cb) => relay.ipfsd.api.swarm.connect(star(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(wsStarAddr(nodeA.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(ws(nodeB.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(wsAddr(nodeB.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(circuit(nodeB.addrs), cb) + (cb) => nodeA.ipfsd.api.swarm.connect(circuitAddr(nodeB.addrs), cb) ], callback) } } diff --git a/test/utils/circuit.js b/test/utils/circuit.js index 8a133b2a..dc051e33 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -29,7 +29,7 @@ const baseConf = { } } -exports.setUpProcNode = (addrs, callback) => { +exports.createProcNode = (addrs, callback) => { procDf.spawn({ initOptions: { bits: 512 }, config: Object.assign({}, baseConf, { @@ -53,7 +53,7 @@ exports.setUpProcNode = (addrs, callback) => { }) } -exports.setUpJsNode = (addrs, callback) => { +exports.createJsNode = (addrs, callback) => { jsDf.spawn({ initOptions: { bits: 512 }, config: Object.assign({}, baseConf, { @@ -77,7 +77,7 @@ exports.setUpJsNode = (addrs, callback) => { }) } -exports.setUpGoNode = (addrs, callback) => { +exports.createUpGoNode = (addrs, callback) => { goDf.spawn({ initOptions: { bits: 1024 }, config: Object.assign({}, baseConf, { From 59e6a856e7062e9609549a2fec0e8acf5719131c Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Mar 2018 11:22:28 -0600 Subject: [PATCH 36/49] fix: naming of funcs --- test/circuit.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/test/circuit.js b/test/circuit.js index 72142033..c0ae0172 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -18,9 +18,9 @@ const creatProc = utils.createProcNode const createJs = utils.createJsNode const createGo = utils.createUpGoNode -const wsAddr = utils.wsAddr -const wsStarAddr = utils.wsStarAddr -const circuitAddr = utils.circuitAddr +const getWsAddr = utils.wsAddr +const getWsStarAddr = utils.wsStarAddr +const getCircuitAddr = utils.circuitAddr const send = utils.send @@ -33,11 +33,11 @@ const connect = (nodeA, nodeB, relay, timeout, callback) => { } series([ - (cb) => nodeA.ipfsd.api.swarm.connect(wsAddr(relay.addrs), cb), + (cb) => nodeA.ipfsd.api.swarm.connect(getWsAddr(relay.addrs), cb), (cb) => setTimeout(cb, timeout), - (cb) => nodeB.ipfsd.api.swarm.connect(wsAddr(relay.addrs), cb), + (cb) => nodeB.ipfsd.api.swarm.connect(getWsAddr(relay.addrs), cb), (cb) => setTimeout(cb, timeout), - (cb) => nodeA.ipfsd.api.swarm.connect(circuitAddr(nodeB.addrs), cb) + (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) } @@ -186,11 +186,11 @@ const browser = { ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ - (cb) => relay.ipfsd.api.swarm.connect(wsAddr(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(wsStarAddr(nodeB.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(circuitAddr(nodeB.addrs), cb) + (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) }, timeout: 100 * 1000, @@ -204,11 +204,11 @@ const browser = { ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ - (cb) => relay.ipfsd.api.swarm.connect(wsAddr(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(wsStarAddr(nodeB.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(circuitAddr(nodeB.addrs), cb) + (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) }, timeout: 100 * 1000 @@ -221,11 +221,11 @@ const browser = { ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ - (cb) => relay.ipfsd.api.swarm.connect(wsStarAddr(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(wsAddr(nodeB.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(circuitAddr(nodeB.addrs), cb) + (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) }, timeout: 100 * 1000, @@ -239,11 +239,11 @@ const browser = { ], callback), connect: (nodeA, nodeB, relay, callback) => { series([ - (cb) => relay.ipfsd.api.swarm.connect(wsStarAddr(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(wsAddr(nodeB.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(circuitAddr(nodeB.addrs), cb) + (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) } } From e2a007fd03c1c550f8f19f4767d2929ace39062b Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Mar 2018 12:06:00 -0600 Subject: [PATCH 37/49] split circuit tests --- test/circuit.js | 239 +--------------------------------- test/circuit/all-tests.js | 71 ++++++++++ test/circuit/browser-tests.js | 147 +++++++++++++++++++++ test/utils/circuit.js | 44 ++++++- 4 files changed, 264 insertions(+), 237 deletions(-) create mode 100644 test/circuit/all-tests.js create mode 100644 test/circuit/browser-tests.js diff --git a/test/circuit.js b/test/circuit.js index c0ae0172..ae6a95fd 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -8,38 +8,13 @@ const expect = chai.expect chai.use(dirtyChai) const parallel = require('async/parallel') -const series = require('async/series') -const isNode = require('detect-node') - -const utils = require('./utils/circuit') - -const creatProc = utils.createProcNode -const createJs = utils.createJsNode -const createGo = utils.createUpGoNode - -const getWsAddr = utils.wsAddr -const getWsStarAddr = utils.wsStarAddr -const getCircuitAddr = utils.circuitAddr - -const send = utils.send +const all = require('./circuit/all-tests') +const browser = require('./circuit/browser-tests') -const base = '/ip4/127.0.0.1/tcp/0' - -const connect = (nodeA, nodeB, relay, timeout, callback) => { - if (typeof timeout === 'function') { - callback = timeout - timeout = 1000 - } - - series([ - (cb) => nodeA.ipfsd.api.swarm.connect(getWsAddr(relay.addrs), cb), - (cb) => setTimeout(cb, timeout), - (cb) => nodeB.ipfsd.api.swarm.connect(getWsAddr(relay.addrs), cb), - (cb) => setTimeout(cb, timeout), - (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) - ], callback) -} +const isNode = require('detect-node') +const send = require('./utils/circuit').send +const connect = require('./utils/circuit').connect const timeout = 80 * 1000 const baseTest = { @@ -48,208 +23,8 @@ const baseTest = { timeout } -let tests = { - 'go-go-go': { - create: (callback) => series([ - (cb) => createGo([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb) - ], callback) - }, - 'js-go-go': { - create: (callback) => series([ - (cb) => createJs([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb) - ], callback) - }, - 'go-go-js': { - create: (callback) => series([ - (cb) => createGo([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb) - ], callback) - }, - 'js-go-js': { - create: (callback) => series([ - (cb) => createJs([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb) - ], callback) - }, - 'go-js-go': { - create: (callback) => series([ - (cb) => createGo([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb) - ], callback) - }, - 'js-js-go': { - create: (callback) => series([ - (cb) => createJs([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb) - ], callback) - }, - 'go-js-js': { - create: (callback) => series([ - (cb) => createGo([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb) - ], callback) - }, - 'js-js-js': { - create: (callback) => series([ - (cb) => createJs([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb) - ], callback) - } -} - -const connWithTimeout = (timeout) => { - return (nodeA, nodeB, relay, callback) => { - connect(nodeA, nodeB, relay, timeout, callback) - } -} -const browser = { - 'browser-go-js': { - create: - (callback) => series([ - (cb) => creatProc([], cb), - (cb) => createGo([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb) - ], callback), - connect: connWithTimeout(1500) - }, - 'browser-go-go': { - create: (callback) => series([ - (cb) => creatProc([], cb), - (cb) => createGo([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb) - ], callback), - connect: connWithTimeout(1500) - }, - 'browser-js-js': { - create: (callback) => series([ - (cb) => creatProc([], cb), - (cb) => createJs([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb) - ], callback), - connect: connWithTimeout(1500) - }, - 'browser-js-go': { - create: (callback) => series([ - (cb) => creatProc([], cb), - (cb) => createJs([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb) - ], callback), - connect: connWithTimeout(1500) - }, - 'js-go-browser': { - create: (callback) => series([ - (cb) => createJs([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb), - (cb) => creatProc([], cb) - ], callback), - connect: connWithTimeout(1500) - }, - 'go-go-browser': { - create: (callback) => series([ - (cb) => createGo([`${base}/ws`], cb), - (cb) => createGo([`${base}/ws`], cb), - (cb) => creatProc([], cb) - ], callback), - connect: connWithTimeout(1500) - }, - 'js-js-browser': { - create: (callback) => series([ - (cb) => createJs([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb), - (cb) => creatProc([], cb) - ], callback), - connect: connWithTimeout(1500) - }, - 'go-js-browser': { - create: (callback) => series([ - (cb) => createGo([`${base}/ws`], cb), - (cb) => createJs([`${base}/ws`], cb), - (cb) => creatProc([], cb) - ], callback), - connect: connWithTimeout(1500) - }, - 'go-browser-browser': { - create: (callback) => series([ - (cb) => createGo([`${base}/ws`], cb), - (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) - ], callback), - connect: (nodeA, nodeB, relay, callback) => { - series([ - (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), - (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), - (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) - ], callback) - }, - timeout: 100 * 1000, - skip: () => true - }, - 'js-browser-browser': { - create: (callback) => series([ - (cb) => createJs([`${base}/ws`], cb), - (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) - ], callback), - connect: (nodeA, nodeB, relay, callback) => { - series([ - (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), - (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), - (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) - ], callback) - }, - timeout: 100 * 1000 - }, - 'browser-browser-go': { - create: (callback) => series([ - (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => createGo([`${base}/ws`], cb) - ], callback), - connect: (nodeA, nodeB, relay, callback) => { - series([ - (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), - (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), - (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) - ], callback) - }, - timeout: 100 * 1000, - skip: () => true - }, - 'browser-browser-js': { - create: (callback) => series([ - (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => creatProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), - (cb) => createJs([`${base}/ws`], cb) - ], callback), - connect: (nodeA, nodeB, relay, callback) => { - series([ - (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), - (cb) => setTimeout(cb, 2000), - (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), - (cb) => setTimeout(cb, 2000), - (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) - ], callback) - } - } -} - -describe('circuit', () => { +describe.only('circuit', () => { + let tests = all if (!isNode) { tests = Object.assign([], tests, browser) } diff --git a/test/circuit/all-tests.js b/test/circuit/all-tests.js new file mode 100644 index 00000000..d81e599a --- /dev/null +++ b/test/circuit/all-tests.js @@ -0,0 +1,71 @@ +/* eslint max-nested-callbacks: ["error", 8] */ +/* eslint-env mocha */ +'use strict' + +const series = require('async/series') + +const utils = require('../utils/circuit') + +const createJs = utils.createJsNode +const createGo = utils.createUpGoNode + +const base = '/ip4/127.0.0.1/tcp/0' + +module.exports = { + 'go-go-go': { + create: (callback) => series([ + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb) + ], callback) + }, + 'js-go-go': { + create: (callback) => series([ + (cb) => createJs([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb) + ], callback) + }, + 'go-go-js': { + create: (callback) => series([ + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) + ], callback) + }, + 'js-go-js': { + create: (callback) => series([ + (cb) => createJs([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) + ], callback) + }, + 'go-js-go': { + create: (callback) => series([ + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb) + ], callback) + }, + 'js-js-go': { + create: (callback) => series([ + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb) + ], callback) + }, + 'go-js-js': { + create: (callback) => series([ + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) + ], callback) + }, + 'js-js-js': { + create: (callback) => series([ + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) + ], callback) + } +} diff --git a/test/circuit/browser-tests.js b/test/circuit/browser-tests.js new file mode 100644 index 00000000..749a7a33 --- /dev/null +++ b/test/circuit/browser-tests.js @@ -0,0 +1,147 @@ +/* eslint max-nested-callbacks: ["error", 8] */ +/* eslint-env mocha */ +'use strict' + +const series = require('async/series') + +const utils = require('../utils/circuit') + +const createJs = utils.createJsNode +const createProc = utils.createProcNode +const createGo = utils.createUpGoNode +const connWithTimeout = utils.connWithTimeout + +const base = '/ip4/127.0.0.1/tcp/0' + +module.exports = { + 'browser-go-js': { + create: + (callback) => series([ + (cb) => createProc([], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) + ], callback), + connect: connWithTimeout(1500) + }, + 'browser-go-go': { + create: (callback) => series([ + (cb) => createProc([], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb) + ], callback), + connect: connWithTimeout(1500) + }, + 'browser-js-js': { + create: (callback) => series([ + (cb) => createProc([], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) + ], callback), + connect: connWithTimeout(1500) + }, + 'browser-js-go': { + create: (callback) => series([ + (cb) => createProc([], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb) + ], callback), + connect: connWithTimeout(1500) + }, + 'js-go-browser': { + create: (callback) => series([ + (cb) => createJs([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createProc([], cb) + ], callback), + connect: connWithTimeout(1500) + }, + 'go-go-browser': { + create: (callback) => series([ + (cb) => createGo([`${base}/ws`], cb), + (cb) => createGo([`${base}/ws`], cb), + (cb) => createProc([], cb) + ], callback), + connect: connWithTimeout(1500) + }, + 'js-js-browser': { + create: (callback) => series([ + (cb) => createJs([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createProc([], cb) + ], callback), + connect: connWithTimeout(1500) + }, + 'go-js-browser': { + create: (callback) => series([ + (cb) => createGo([`${base}/ws`], cb), + (cb) => createJs([`${base}/ws`], cb), + (cb) => createProc([], cb) + ], callback), + connect: connWithTimeout(1500) + }, + 'go-browser-browser': { + create: (callback) => series([ + (cb) => createGo([`${base}/ws`], cb), + (cb) => createProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => createProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) + ], callback), + connect: (nodeA, nodeB, relay, callback) => { + series([ + (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) + ], callback) + }, + timeout: 100 * 1000, + skip: () => true + }, + 'js-browser-browser': { + create: (callback) => series([ + (cb) => createJs([`${base}/ws`], cb), + (cb) => createProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => createProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb) + ], callback), + connect: (nodeA, nodeB, relay, callback) => { + series([ + (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) + ], callback) + }, + timeout: 100 * 1000 + }, + 'browser-browser-go': { + create: (callback) => series([ + (cb) => createProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => createProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => createGo([`${base}/ws`], cb) + ], callback), + connect: (nodeA, nodeB, relay, callback) => { + series([ + (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) + ], callback) + }, + timeout: 100 * 1000, + skip: () => true + }, + 'browser-browser-js': { + create: (callback) => series([ + (cb) => createProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => createProc([`/ip4/127.0.0.1/tcp/24642/ws/p2p-websocket-star`], cb), + (cb) => createJs([`${base}/ws`], cb) + ], callback), + connect: (nodeA, nodeB, relay, callback) => { + series([ + (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), + (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), + (cb) => setTimeout(cb, 2000), + (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) + ], callback) + } + } +} diff --git a/test/utils/circuit.js b/test/utils/circuit.js index dc051e33..d1cb8519 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -6,6 +6,8 @@ const expect = chai.expect chai.use(dirtyChai) const waterfall = require('async/waterfall') +const series = require('async/series') + const crypto = require('crypto') const IPFS = require('ipfs') @@ -110,24 +112,56 @@ exports.send = (nodeA, nodeB, callback) => { ], callback) } -exports.wsAddr = (addrs) => addrs +const getWsAddr = (addrs) => addrs .map((a) => a.toString()) .find((a) => { return a.includes('/ws') && !a.includes('/p2p-websocket-star') }) -exports.wsStarAddr = (addrs) => addrs +exports.getWsAddr = getWsAddr + +const getWsStarAddr = (addrs) => addrs .map((a) => a.toString()) .find((a) => a.includes('/p2p-websocket-star')) -exports.wrtcStarAddr = (addrs) => addrs +exports.getWsStarAddr = getWsStarAddr + +const getWrtcStarAddr = (addrs) => addrs .map((a) => a.toString()) .find((a) => a.includes('/p2p-webrtc-star')) -exports.tcpAddr = (addrs) => addrs +exports.getWrtcStarAddr = getWrtcStarAddr + +const getTcpAddr = (addrs) => addrs .map((a) => a.toString()) .find((a) => !a.includes('/ws') && !a.includes('/p2p-websocket-star')) -exports.circuitAddr = (addrs) => addrs +exports.getTcpAddr = getTcpAddr + +const getCircuitAddr = (addrs) => addrs .map((a) => a.toString()) .find((a) => a.includes('/p2p-circuit/ipfs')) + +exports.getCircuitAddr = getCircuitAddr + +const connect = (nodeA, nodeB, relay, timeout, callback) => { + if (typeof timeout === 'function') { + callback = timeout + timeout = 1000 + } + + series([ + (cb) => nodeA.ipfsd.api.swarm.connect(getWsAddr(relay.addrs), cb), + (cb) => nodeB.ipfsd.api.swarm.connect(getWsAddr(relay.addrs), cb), + (cb) => setTimeout(cb, timeout), + (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) + ], callback) +} + +exports.connect = connect + +exports.connWithTimeout = (timeout) => { + return (nodeA, nodeB, relay, callback) => { + connect(nodeA, nodeB, relay, timeout, callback) + } +} From c29f3a9671f2cfaeebd62ebc6efd42735822be3f Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Mar 2018 12:14:38 -0600 Subject: [PATCH 38/49] chore: rename files --- test/circuit.js | 4 ++-- test/circuit/{all-tests.js => all.js} | 0 test/circuit/{browser-tests.js => browser.js} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename test/circuit/{all-tests.js => all.js} (100%) rename test/circuit/{browser-tests.js => browser.js} (100%) diff --git a/test/circuit.js b/test/circuit.js index ae6a95fd..98db547f 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -9,8 +9,8 @@ chai.use(dirtyChai) const parallel = require('async/parallel') -const all = require('./circuit/all-tests') -const browser = require('./circuit/browser-tests') +const all = require('./circuit/all') +const browser = require('./circuit/browser') const isNode = require('detect-node') const send = require('./utils/circuit').send diff --git a/test/circuit/all-tests.js b/test/circuit/all.js similarity index 100% rename from test/circuit/all-tests.js rename to test/circuit/all.js diff --git a/test/circuit/browser-tests.js b/test/circuit/browser.js similarity index 100% rename from test/circuit/browser-tests.js rename to test/circuit/browser.js From 9e9c38cddbfcccd91ef56ee335f3874e149183f2 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Mar 2018 12:15:09 -0600 Subject: [PATCH 39/49] increase timeout --- test/circuit/browser.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/circuit/browser.js b/test/circuit/browser.js index 749a7a33..52b99530 100644 --- a/test/circuit/browser.js +++ b/test/circuit/browser.js @@ -89,7 +89,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), - (cb) => setTimeout(cb, 2000), + (cb) => setTimeout(cb, 3000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) }, @@ -106,7 +106,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), - (cb) => setTimeout(cb, 2000), + (cb) => setTimeout(cb, 3000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) }, @@ -122,7 +122,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), - (cb) => setTimeout(cb, 2000), + (cb) => setTimeout(cb, 3000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) }, @@ -139,7 +139,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), - (cb) => setTimeout(cb, 2000), + (cb) => setTimeout(cb, 3000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) } From d5dd246ddf461ae380e6de316bee797a294e8fa3 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Mar 2018 12:31:46 -0600 Subject: [PATCH 40/49] fix: missing import --- test/circuit/browser.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/circuit/browser.js b/test/circuit/browser.js index 52b99530..ab1c6391 100644 --- a/test/circuit/browser.js +++ b/test/circuit/browser.js @@ -11,6 +11,10 @@ const createProc = utils.createProcNode const createGo = utils.createUpGoNode const connWithTimeout = utils.connWithTimeout +const getWsAddr = utils.getWsAddr +const getWsStarAddr = utils.getWsStarAddr +const getCircuitAddr = utils.getCircuitAddr + const base = '/ip4/127.0.0.1/tcp/0' module.exports = { From 4b3ee064054a7961bdaa4516607a05531cc76841 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Mar 2018 12:46:32 -0600 Subject: [PATCH 41/49] chore: remove .only --- test/circuit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/circuit.js b/test/circuit.js index 98db547f..24f5a904 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -23,7 +23,7 @@ const baseTest = { timeout } -describe.only('circuit', () => { +describe('circuit', () => { let tests = all if (!isNode) { tests = Object.assign([], tests, browser) From efcb48e06101c2356890f29b503fefc904f9dc60 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Mar 2018 14:06:36 -0600 Subject: [PATCH 42/49] chore: add TODO regarding CAN_HOP --- test/circuit/browser.js | 4 ++++ test/utils/circuit.js | 1 + 2 files changed, 5 insertions(+) diff --git a/test/circuit/browser.js b/test/circuit/browser.js index ab1c6391..fc999766 100644 --- a/test/circuit/browser.js +++ b/test/circuit/browser.js @@ -93,6 +93,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), + // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg (cb) => setTimeout(cb, 3000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) @@ -110,6 +111,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), + // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg (cb) => setTimeout(cb, 3000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) @@ -126,6 +128,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), + // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg (cb) => setTimeout(cb, 3000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) @@ -143,6 +146,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), + // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg (cb) => setTimeout(cb, 3000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) diff --git a/test/utils/circuit.js b/test/utils/circuit.js index d1cb8519..2d74658b 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -153,6 +153,7 @@ const connect = (nodeA, nodeB, relay, timeout, callback) => { series([ (cb) => nodeA.ipfsd.api.swarm.connect(getWsAddr(relay.addrs), cb), (cb) => nodeB.ipfsd.api.swarm.connect(getWsAddr(relay.addrs), cb), + // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg (cb) => setTimeout(cb, timeout), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) From 51a7118705df8525901e9391be6fe7394afcaaab Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Mar 2018 15:21:50 -0600 Subject: [PATCH 43/49] several small fixes --- package.json | 2 +- test/circuit.js | 4 ++-- test/circuit/all.js | 2 +- test/circuit/browser.js | 2 +- test/utils/circuit.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 06306c45..93c35ab2 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "ipfs-api": "^18.1.1", "ipfsd-ctl": "~0.29.1", "left-pad": "^1.2.0", - "libp2p-websocket-star-rendezvous": "^0.2.2", + "libp2p-websocket-star-rendezvous": "~0.2.2", "lodash": "^4.17.4", "mocha": "^4.0.1", "ncp": "^2.0.0", diff --git a/test/circuit.js b/test/circuit.js index 24f5a904..f591e18e 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -24,9 +24,9 @@ const baseTest = { } describe('circuit', () => { - let tests = all + const tests = all if (!isNode) { - tests = Object.assign([], tests, browser) + Object.assign(tests, browser) } Object.keys(tests).forEach((test) => { diff --git a/test/circuit/all.js b/test/circuit/all.js index d81e599a..1fcbbe0f 100644 --- a/test/circuit/all.js +++ b/test/circuit/all.js @@ -7,7 +7,7 @@ const series = require('async/series') const utils = require('../utils/circuit') const createJs = utils.createJsNode -const createGo = utils.createUpGoNode +const createGo = utils.createGoNode const base = '/ip4/127.0.0.1/tcp/0' diff --git a/test/circuit/browser.js b/test/circuit/browser.js index fc999766..619028e4 100644 --- a/test/circuit/browser.js +++ b/test/circuit/browser.js @@ -8,7 +8,7 @@ const utils = require('../utils/circuit') const createJs = utils.createJsNode const createProc = utils.createProcNode -const createGo = utils.createUpGoNode +const createGo = utils.createGoNode const connWithTimeout = utils.connWithTimeout const getWsAddr = utils.getWsAddr diff --git a/test/utils/circuit.js b/test/utils/circuit.js index 2d74658b..e4798cd2 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -79,7 +79,7 @@ exports.createJsNode = (addrs, callback) => { }) } -exports.createUpGoNode = (addrs, callback) => { +exports.createGoNode = (addrs, callback) => { goDf.spawn({ initOptions: { bits: 1024 }, config: Object.assign({}, baseConf, { From 06a4b9f842207d218efc52fce4d7f2f0c2f1546f Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 7 Mar 2018 02:15:21 -0600 Subject: [PATCH 44/49] fix: pass options --- test/circuit/browser.js | 6 +++--- test/utils/circuit.js | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/circuit/browser.js b/test/circuit/browser.js index 619028e4..134ce637 100644 --- a/test/circuit/browser.js +++ b/test/circuit/browser.js @@ -94,12 +94,12 @@ module.exports = { (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg - (cb) => setTimeout(cb, 3000), + (cb) => setTimeout(cb, 5000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) }, timeout: 100 * 1000, - skip: () => true + skip: () => false }, 'js-browser-browser': { create: (callback) => series([ @@ -129,7 +129,7 @@ module.exports = { (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg - (cb) => setTimeout(cb, 3000), + (cb) => setTimeout(cb, 5000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) }, diff --git a/test/utils/circuit.js b/test/utils/circuit.js index e4798cd2..4c3e51ac 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -34,17 +34,17 @@ const baseConf = { exports.createProcNode = (addrs, callback) => { procDf.spawn({ initOptions: { bits: 512 }, + EXPERIMENTAL: { + relay: { + enabled: true, + hop: { + enabled: true + } + } + }, config: Object.assign({}, baseConf, { Addresses: { Swarm: addrs - }, - EXPERIMENTAL: { - relay: { - enabled: true, - hop: { - enabled: true - } - } } }) }, (err, ipfsd) => { From 1c261a72ea576b89ff522e70584b4d064647dcf0 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 7 Mar 2018 03:25:45 -0600 Subject: [PATCH 45/49] review last commit --- test/utils/circuit.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/utils/circuit.js b/test/utils/circuit.js index 4c3e51ac..e4798cd2 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -34,17 +34,17 @@ const baseConf = { exports.createProcNode = (addrs, callback) => { procDf.spawn({ initOptions: { bits: 512 }, - EXPERIMENTAL: { - relay: { - enabled: true, - hop: { - enabled: true - } - } - }, config: Object.assign({}, baseConf, { Addresses: { Swarm: addrs + }, + EXPERIMENTAL: { + relay: { + enabled: true, + hop: { + enabled: true + } + } } }) }, (err, ipfsd) => { From 650876de82ce7db181e04b8e66e0b5a7b66becfa Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 7 Mar 2018 16:45:43 -0600 Subject: [PATCH 46/49] chore: updated todo --- test/circuit/browser.js | 8 ++++---- test/utils/circuit.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/circuit/browser.js b/test/circuit/browser.js index 134ce637..4b7afd26 100644 --- a/test/circuit/browser.js +++ b/test/circuit/browser.js @@ -93,7 +93,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), - // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg + // TODO: needed until https://github.com/ipfs/interop/issues/17 is resolved (cb) => setTimeout(cb, 5000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) @@ -111,7 +111,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeB.addrs), cb), - // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg + // TODO: needed until https://github.com/ipfs/interop/issues/17 is resolved (cb) => setTimeout(cb, 3000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) @@ -128,7 +128,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), - // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg + // TODO: needed until https://github.com/ipfs/interop/issues/17 is resolved (cb) => setTimeout(cb, 5000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) @@ -146,7 +146,7 @@ module.exports = { series([ (cb) => relay.ipfsd.api.swarm.connect(getWsStarAddr(nodeA.addrs), cb), (cb) => relay.ipfsd.api.swarm.connect(getWsAddr(nodeB.addrs), cb), - // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg + // TODO: needed until https://github.com/ipfs/interop/issues/17 is resolved (cb) => setTimeout(cb, 3000), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) diff --git a/test/utils/circuit.js b/test/utils/circuit.js index e4798cd2..2ae7d5d0 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -153,7 +153,7 @@ const connect = (nodeA, nodeB, relay, timeout, callback) => { series([ (cb) => nodeA.ipfsd.api.swarm.connect(getWsAddr(relay.addrs), cb), (cb) => nodeB.ipfsd.api.swarm.connect(getWsAddr(relay.addrs), cb), - // TODO: timeout is needed to give the nodes time to send the `CAN_HOP` msg + // TODO: needed until https://github.com/ipfs/interop/issues/17 is resolved (cb) => setTimeout(cb, timeout), (cb) => nodeA.ipfsd.api.swarm.connect(getCircuitAddr(nodeB.addrs), cb) ], callback) From 26daf070a438c7ebf2040dfc63f69649fb2b0972 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 17 Mar 2018 17:34:54 -0600 Subject: [PATCH 47/49] chore: up deps --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 93c35ab2..e5176c0b 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "hat": "0.0.3", "ipfs": "~0.28.0", "ipfs-api": "^18.1.1", - "ipfsd-ctl": "~0.29.1", + "ipfsd-ctl": "~0.30.3", "left-pad": "^1.2.0", "libp2p-websocket-star-rendezvous": "~0.2.2", "lodash": "^4.17.4", From 2a686e4a455ded4c54daeaa09f3f98632986e7e9 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 17 Mar 2018 18:33:36 -0600 Subject: [PATCH 48/49] fix: daemon type in tests --- test/exchange-files.js | 10 ++++++---- test/kad-dht.js | 12 +++++++----- test/repo.js | 13 ++++++------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/test/exchange-files.js b/test/exchange-files.js index d1748845..39a78c2e 100644 --- a/test/exchange-files.js +++ b/test/exchange-files.js @@ -5,6 +5,7 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) + const series = require('async/series') const parallel = require('async/parallel') const waterfall = require('async/waterfall') @@ -22,7 +23,8 @@ const isWindows = os.platform() === 'win32' const rmDir = promisify(rimraf) const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const goDf = DaemonFactory.create() +const jsDf = DaemonFactory.create({ type: 'js' }) function tmpDir () { return join(os.tmpdir(), `ipfs_${hat()}`) @@ -59,9 +61,9 @@ describe('exchange files', () => { this.timeout(50 * 1000) parallel([ - (cb) => df.spawn({ initOptions: { bits: 1024 } }, cb), - (cb) => df.spawn({ type: 'js', initOptions: { bits: 512 } }, cb), - (cb) => df.spawn({ type: 'js', initOptions: { bits: 512 } }, cb) + (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb), + (cb) => jsDf.spawn({ type: 'js', initOptions: { bits: 512 } }, cb), + (cb) => jsDf.spawn({ type: 'js', initOptions: { bits: 512 } }, cb) ], (err, n) => { expect(err).to.not.exist() nodes = n diff --git a/test/kad-dht.js b/test/kad-dht.js index 2389dc09..fa65bf53 100644 --- a/test/kad-dht.js +++ b/test/kad-dht.js @@ -5,6 +5,7 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) + const series = require('async/series') const crypto = require('crypto') const parallel = require('async/parallel') @@ -12,7 +13,8 @@ const waterfall = require('async/waterfall') const bl = require('bl') const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const goDf = DaemonFactory.create() +const jsDf = DaemonFactory.create({ type: 'js' }) describe.skip('kad-dht', () => { describe('a JS node in the land of Go', () => { @@ -23,10 +25,10 @@ describe.skip('kad-dht', () => { before((done) => { parallel([ - (cb) => df.spawn({ initOptions: { bits: 1024 } }, cb), - (cb) => df.spawn({ initOptions: { bits: 1024 } }, cb), - (cb) => df.spawn({ initOptions: { bits: 1024 } }, cb), - (cb) => df.spawn({ type: 'js', initOptions: { bits: 512 } }, cb) + (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb), + (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb), + (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb), + (cb) => jsDf.spawn({ initOptions: { bits: 512 } }, cb) ], (err, nodes) => { expect(err).to.not.exist() goD1 = nodes[0] diff --git a/test/repo.js b/test/repo.js index 4177e69a..a318bdc7 100644 --- a/test/repo.js +++ b/test/repo.js @@ -15,7 +15,8 @@ const hat = require('hat') const isWindows = os.platform() === 'win32' const DaemonFactory = require('ipfsd-ctl') -const df = DaemonFactory.create() +const goDf = DaemonFactory.create() +const jsDf = DaemonFactory.create({ type: 'js' }) function catAndCheck (api, hash, data, callback) { api.cat(hash, (err, fileData) => { @@ -42,7 +43,7 @@ describe('repo', () => { let hash series([ - (cb) => df.spawn({ + (cb) => goDf.spawn({ repoPath: dir, disposable: false, initOptions: { bits: 1024 } @@ -59,8 +60,7 @@ describe('repo', () => { }), (cb) => catAndCheck(goDaemon.api, hash, data, cb), (cb) => goDaemon.stop(cb), - (cb) => df.spawn({ - type: 'js', + (cb) => jsDf.spawn({ repoPath: dir, disposable: false, initOptions: { bits: 512 } @@ -89,8 +89,7 @@ describe('repo', () => { let hash series([ - (cb) => df.spawn({ - type: 'js', + (cb) => jsDf.spawn({ repoPath: dir, initOptions: { bits: 512 } }, cb), @@ -104,7 +103,7 @@ describe('repo', () => { catAndCheck(jsDaemon.api, hash, data, cb) }, (cb) => jsDaemon.stop(cb), - (cb) => df.spawn({ + (cb) => goDf.spawn({ repoPath: dir, initOptions: { bits: 1024 } }, cb), From 9a2efbc5804f1eac4203652e794dcf35e540ecdd Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 28 May 2018 06:46:33 +0100 Subject: [PATCH 49/49] test: skip circuit tests. waiting for go-ipfs 0.4.15 --- test/circuit.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/circuit.js b/test/circuit.js index f591e18e..86ced5df 100644 --- a/test/circuit.js +++ b/test/circuit.js @@ -23,7 +23,8 @@ const baseTest = { timeout } -describe('circuit', () => { +// TODO: unskip once go-ipfs 0.4.15 is out +describe.skip('circuit', () => { const tests = all if (!isNode) { Object.assign(tests, browser)