Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: avoid spawning nodes that not used
  • Loading branch information
daviddias committed Nov 8, 2017
commit 492fa162cacb9fbbecf3a7182fe77cf9eff2ddd6
66 changes: 19 additions & 47 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,28 @@
'use strict'

const parallel = require('async/parallel')

const spawnJsNode = require('./test/utils/spawn-tools').spawnJsNode
const spawnGoNode = require('./test/utils/spawn-tools').spawnGoNode
const stopNodes = require('./test/utils/spawn-tools').stopNodes
const spawnTools = require('./test/utils/spawn-tools')
const js = spawnTools.spawnJsNode
// const go = spawnTools.spawnGoNode
const stop = spawnTools.stopNodes

/*
* spawns a daemon with ports numbers starting in 10 and ending in `num`
*/
const before = (done) => {
function pre (done) {
const base = '/ip4/127.0.0.1/tcp'

parallel([
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10007`,
`/ip4/127.0.0.1/tcp/20007/ws`
], true, 31007, 32007, cb),
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10008`,
`/ip4/127.0.0.1/tcp/20008/ws`
], true, 31008, 32008, cb),
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10012`,
`/ip4/127.0.0.1/tcp/20012/ws`
], true, 31012, 32012, cb),
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10013`,
`/ip4/127.0.0.1/tcp/20013/ws`
], true, 31013, 32013, cb),
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10014`,
`/ip4/127.0.0.1/tcp/20014/ws`
], true, 31014, 32014, cb),
(cb) => spawnJsNode([
`/ip4/127.0.0.1/tcp/10015`,
`/ip4/127.0.0.1/tcp/20015/ws`
], true, 31015, 32015, cb),
(cb) => spawnGoNode([
`/ip4/127.0.0.1/tcp/10027`,
`/ip4/127.0.0.1/tcp/20027/ws`
], true, 33027, 44027, cb),
(cb) => spawnGoNode([
`/ip4/127.0.0.1/tcp/10028`,
`/ip4/127.0.0.1/tcp/20028/ws`
], true, 33028, 44028, cb),
(cb) => spawnGoNode([
`/ip4/127.0.0.1/tcp/10031`,
`/ip4/127.0.0.1/tcp/20031/ws`
], true, 33031, 44031, cb),
(cb) => spawnGoNode([
`/ip4/127.0.0.1/tcp/10032`,
`/ip4/127.0.0.1/tcp/20032/ws`
], true, 33032, 44032, cb)
(cb) => js([`${base}/10007`, `${base}/20007/ws`], true, 31007, 32007, cb),
(cb) => js([`${base}/10008`, `${base}/20008/ws`], true, 31008, 32008, cb),
(cb) => js([`${base}/10012`, `${base}/20012/ws`], true, 31012, 32012, cb),
(cb) => js([`${base}/10013`, `${base}/20013/ws`], true, 31013, 32013, cb),
(cb) => js([`${base}/10014`, `${base}/20014/ws`], true, 31014, 32014, cb),
(cb) => js([`${base}/10015`, `${base}/20015/ws`], true, 31015, 32015, cb)
// (cb) => go([`${base}/10027`, `${base}/20027/ws`], true, 33027, 44027, cb),
// (cb) => go([`${base}/10028`, `${base}/20028/ws`], true, 33028, 44028, cb),
// (cb) => go([`${base}/10031`, `${base}/20031/ws`], true, 33031, 44031, cb),
// (cb) => go([`${base}/10032`, `${base}/20032/ws`], true, 33032, 44032, cb)
], done)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you make these spawn daemon tools part of test/utils? This file should have a very declarative feel and just inform the dev what is going to be spawned for testing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I'll move them over.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't the "Spawner" use IPFS Factory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what are the magic numbers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The numbers are the preexisting port numbers that this daemons were being started with - I kept them because I believe some other tests might rely on them.


Expand All @@ -65,7 +37,7 @@ module.exports = {
}]
},
hooks: {
pre: before,
post: stopNodes
pre: pre,
post: stop
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dignifiedquire is there a way to select custom .aegir.js for different runs? Goal here is to have one for interop and another for unit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, we can have browser.hooks, but not sure if we can have custom tags.

83 changes: 41 additions & 42 deletions test/core/circuit.spec.js → test/core/circuit-relay.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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')
Expand All @@ -14,10 +15,8 @@ const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const multiaddr = require('multiaddr')
const isNode = require('detect-node')
const IPFSFactory = require('../utils/ipfs-factory-instance')
const crypto = require('crypto')

chai.use(dirtyChai)
const IPFSFactory = require('../utils/ipfs-factory-instance')

function peerInfoFromObj (obj, callback) {
waterfall([
Expand Down Expand Up @@ -45,40 +44,36 @@ describe('circuit', function () {
// let nodeId1
let nodeId2

before(function (done) {
before((done) => {
factory = new IPFSFactory()

const base = {
EXPERIMENTAL: {
Relay: {
Enabled: true
}
},
Addresses: {
Swarm: []
}
}

parallel([
(cb) => factory.spawnNode(null, {
EXPERIMENTAL: {
Relay: {
Enabled: true
}
},
Addresses:
{
Swarm: [
(isNode ? `/ip4/127.0.0.1/tcp/0` : '')
]
}
}, cb),
(cb) => factory.spawnNode(null, {
EXPERIMENTAL: {
Relay: {
Enabled: true
}
},
Addresses:
{
Swarm: [
(isNode ? `/ip4/127.0.0.1/tcp/0/ws` : '')
]
}
}, cb)
], (err, res1) => {
(cb) => factory.spawnNode(null, Object.assign(base, {
Addresses: {
Swarm: [ (isNode ? `/ip4/127.0.0.1/tcp/0` : '') ]
}
}), cb),
(cb) => factory.spawnNode(null, Object.assign(base, {
Addresses: {
Swarm: [ (isNode ? `/ip4/127.0.0.1/tcp/0/ws` : '') ]
}
}), cb)
], (err, nodes) => {
expect(err).to.not.exist()
node1 = res1[0]
node2 = res1[1]
node1 = nodes[0]
node2 = nodes[1]

parallel([
(cb) => jsRelay.id(cb),
// (cb) => goRelay.id(cb),
Expand All @@ -105,38 +100,42 @@ describe('circuit', function () {

after((done) => factory.dismantle(done))

// TODO: figure out why this test hangs randomly
it.skip('node1 <-> goRelay <-> node2', function (done) {
// TODO: 1) figure out why this test hangs randomly
// TODO: 2) move this test to the interop batch
it.skip('node1 <-> goRelay <-> node2', (done) => {
const data = crypto.randomBytes(128)

series([
(cb) => node1.swarm.connect(goRelayId, cb),
(cb) => setTimeout(cb, 2000),
(cb) => setTimeout(cb, 1000),
(cb) => node2.swarm.connect(goRelayId, cb),
(cb) => setTimeout(cb, 2000),
(cb) => setTimeout(cb, 1000),
(cb) => node1.swarm.connect(nodeId2, cb)
], (err) => {
expect(err).to.not.exist()
waterfall([
(cb) => node1.files.add(data, cb),
(res, cb) => node2.files.cat(res[0].hash, cb),
(filesAdded, cb) => node2.files.cat(filesAdded[0].hash, cb),
(stream, cb) => stream.pipe(bl(cb))
], done)
})
})

it('node1 <-> jsRelay <-> node2', function (done) {
it('node1 <-> jsRelay <-> node2', (done) => {
const data = crypto.randomBytes(128)

series([
(cb) => node1.swarm.connect(jsRelayId, cb),
(cb) => setTimeout(cb, 2000),
(cb) => setTimeout(cb, 1000),
(cb) => node2.swarm.connect(jsRelayId, cb),
(cb) => setTimeout(cb, 2000),
(cb) => setTimeout(cb, 1000),
(cb) => node1.swarm.connect(nodeId2, cb)
], (err) => {
expect(err).to.not.exist()

waterfall([
(cb) => node1.files.add(data, cb),
(res, cb) => node2.files.cat(res[0].hash, cb),
(filesAdded, cb) => node2.files.cat(filesAdded[0].hash, cb),
(stream, cb) => stream.pipe(bl(cb))
], done)
})
Expand Down