Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: circuit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Nov 24, 2017
1 parent 93cc273 commit af39873
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 37 deletions.
9 changes: 5 additions & 4 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function start (done) {
(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) => js([`${base}/10015`, `${base}/20015/ws`], true, 31015, 32015, cb),
(cb) => go([`${base}/10027`, `${base}/20027/ws`], true, 33027, 44027, cb), // we need this for circuit for now
], done)
} else if (process.env.IPFS_TEST === 'interop') {
parallel([
Expand All @@ -38,9 +39,9 @@ module.exports = {
pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*',
watched: false,
served: true,
included: false,
singleRun: false
}]
included: false
}],
singleRun: true
},
hooks: {
pre: start,
Expand Down
34 changes: 19 additions & 15 deletions test/core/circuit-relay.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const parallel = require('async/parallel')
const series = require('async/series')
const waterfall = require('async/waterfall')
const API = require('ipfs-api')
const bl = require('bl')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const multiaddr = require('multiaddr')
Expand All @@ -34,7 +33,7 @@ describe.skip('circuit', function () {
let factory

let jsRelay = new API(`/ip4/127.0.0.1/tcp/31015`)
// let goRelay = new API(`/ip4/127.0.0.1/tcp/33031`)
let goRelay = new API(`/ip4/127.0.0.1/tcp/33027`)
let node1
let node2

Expand All @@ -51,8 +50,8 @@ describe.skip('circuit', function () {

const base = {
EXPERIMENTAL: {
Relay: {
Enabled: true
relay: {
enabled: true
}
},
Addresses: {
Expand All @@ -63,12 +62,12 @@ describe.skip('circuit', function () {
parallel([
(cb) => factory.spawnNode(null, Object.assign(base, {
Addresses: {
Swarm: [ (isNode ? `/ip4/127.0.0.1/tcp/0` : '') ]
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` : '') ]
Swarm: [(isNode ? `/ip4/127.0.0.1/tcp/0/ws` : '')]
}
}), cb)
], (err, nodes) => {
Expand All @@ -78,20 +77,20 @@ describe.skip('circuit', function () {

parallel([
(cb) => jsRelay.id(cb),
// (cb) => goRelay.id(cb),
(cb) => goRelay.id(cb),
(cb) => node1.id(cb),
(cb) => node2.id(cb)
], (err, res2) => {
expect(err).to.not.exist()
parallel([
(cb) => peerInfoFromObj(res2[0], cb),
// (cb) => peerInfoFromObj(res2[1], cb),
(cb) => peerInfoFromObj(res2[1], cb),
(cb) => peerInfoFromObj(res2[1], cb),
(cb) => peerInfoFromObj(res2[2], cb)
], (err, res3) => {
expect(err).to.not.exist()
jsRelayId = res3[0]
// goRelayId = res3[1]
goRelayId = res3[1]
// nodeId1 = res3[2]
nodeId2 = res3[2]
done()
Expand All @@ -102,9 +101,7 @@ describe.skip('circuit', function () {

after((done) => factory.dismantle(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) => {
it('node1 <-> goRelay <-> node2', (done) => {
const data = crypto.randomBytes(128)

series([
Expand All @@ -115,15 +112,19 @@ describe.skip('circuit', function () {
(cb) => node1.swarm.connect(nodeId2, cb)
], (err) => {
expect(err).to.not.exist()

waterfall([
(cb) => node1.files.add(data, cb),
(filesAdded, cb) => node2.files.cat(filesAdded[0].hash, cb),
(stream, cb) => stream.pipe(bl(cb))
(buffer, cb) => {
expect(buffer).to.deep.equal(data)
cb()
}
], done)
})
})

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

series([
Expand All @@ -138,7 +139,10 @@ describe.skip('circuit', function () {
waterfall([
(cb) => node1.files.add(data, cb),
(filesAdded, cb) => node2.files.cat(filesAdded[0].hash, cb),
(stream, cb) => stream.pipe(bl(cb))
(buffer, cb) => {
expect(buffer).to.deep.equal(data)
cb()
}
], done)
})
})
Expand Down
45 changes: 32 additions & 13 deletions test/interop/circuit-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const expect = chai.expect
chai.use(dirtyChai)
const parallel = require('async/parallel')
const series = require('async/series')
const bl = require('bl')
const waterfall = require('async/waterfall')
const multiaddr = require('multiaddr')
const crypto = require('crypto')
Expand All @@ -18,7 +17,7 @@ const js = ads.spawnJsNode
const go = ads.spawnGoNode
const stop = ads.stopNodes

describe.skip('circuit interop', () => {
describe('circuit interop', () => {
let jsTCP
let jsTCPAddrs
let jsWS
Expand All @@ -33,7 +32,8 @@ describe.skip('circuit interop', () => {
let goWSAddrs
let goWS

beforeEach((done) => {
beforeEach(function (done) {
this.timeout(20 * 1000)
const base = '/ip4/127.0.0.1/tcp'

parallel([
Expand Down Expand Up @@ -61,7 +61,7 @@ describe.skip('circuit interop', () => {
})
})

afterEach(() => stop())
afterEach((done) => stop(done))

it('jsWS <-> jsRelay <-> jsTCP', (done) => {
const data = crypto.randomBytes(128)
Expand All @@ -75,7 +75,10 @@ describe.skip('circuit interop', () => {
waterfall([
(cb) => jsTCP.files.add(data, cb),
(res, cb) => jsWS.files.cat(res[0].hash, cb),
(stream, cb) => stream.pipe(bl(cb))
(buffer, cb) => {
expect(buffer).to.deep.equal(data)
cb()
}
], done)
})
})
Expand All @@ -92,7 +95,10 @@ describe.skip('circuit interop', () => {
waterfall([
(cb) => goTCP.files.add(data, cb),
(res, cb) => goWS.files.cat(res[0].hash, cb),
(stream, cb) => stream.pipe(bl(cb))
(buffer, cb) => {
expect(buffer).to.deep.equal(data)
cb()
}
], done)
})
})
Expand All @@ -109,24 +115,31 @@ describe.skip('circuit interop', () => {
waterfall([
(cb) => goTCP.files.add(data, cb),
(res, cb) => jsWS.files.cat(res[0].hash, cb),
(stream, cb) => stream.pipe(bl(cb))
(buffer, cb) => {
expect(buffer).to.deep.equal(data)
cb()
}
], done)
})
})

it('jsTCP <-> goRelay <-> jsWS', (done) => {
const data = crypto.randomBytes(128)
series([
(cb) => jsTCP.swarm.connect(goRelayAddrs[2], cb),
(cb) => jsTCP.swarm.connect(goRelayAddrs[1], cb),
(cb) => jsWS.swarm.connect(goRelayAddrs[0], cb),
(cb) => jsTCP.swarm.connect(goRelayAddrs[1], cb),
(cb) => setTimeout(cb, 1000),
(cb) => jsWS.swarm.connect(jsTCPAddrs[0], cb)
], (err) => {
expect(err).to.not.exist()
waterfall([
(cb) => jsTCP.files.add(data, cb),
(res, cb) => jsWS.files.cat(res[0].hash, cb),
(stream, cb) => stream.pipe(bl(cb))
(buffer, cb) => {
expect(buffer).to.deep.equal(data)
cb()
}
], done)
})
})
Expand All @@ -135,15 +148,18 @@ describe.skip('circuit interop', () => {
const data = crypto.randomBytes(128)
series([
(cb) => goWS.swarm.connect(goRelayAddrs[0], cb),
(cb) => goTCP.swarm.connect(goRelayAddrs[2], cb),
(cb) => goTCP.swarm.connect(goRelayAddrs[1], cb),
(cb) => setTimeout(cb, 1000),
(cb) => goWS.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(goTCPAddrs[0]).getPeerId()}`, cb)
], (err) => {
expect(err).to.not.exist()
waterfall([
(cb) => goTCP.files.add(data, cb),
(res, cb) => goWS.files.cat(res[0].hash, cb),
(stream, cb) => stream.pipe(bl(cb))
(buffer, cb) => {
expect(buffer).to.deep.equal(data)
cb()
}
], done)
})
})
Expand All @@ -152,15 +168,18 @@ describe.skip('circuit interop', () => {
const data = crypto.randomBytes(128)
series([
(cb) => jsWS.swarm.connect(goRelayAddrs[0], cb),
(cb) => goTCP.swarm.connect(goRelayAddrs[2], cb),
(cb) => goTCP.swarm.connect(goRelayAddrs[1], cb),
(cb) => setTimeout(cb, 1000),
(cb) => goTCP.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(jsWSAddrs[0]).getPeerId()}`, cb)
], (err) => {
expect(err).to.not.exist()
waterfall([
(cb) => goTCP.files.add(data, cb),
(res, cb) => jsWS.files.cat(res[0].hash, cb),
(stream, cb) => stream.pipe(bl(cb))
(buffer, cb) => {
expect(buffer).to.deep.equal(data)
cb()
}
], done)
})
})
Expand Down
8 changes: 6 additions & 2 deletions test/interop/exchange-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ describe('exchange files', () => {
})
})

it(`js -> go: depth: 5, num: ${num}`, () => {
it(`js -> go: depth: 5, num: ${num}`, function () {
this.timeout(6000)

const dir = tmpDir()
return randomFs({
path: dir,
Expand All @@ -196,7 +198,9 @@ describe('exchange files', () => {
})
})

it(`js -> js: depth: 5, num: ${num}`, () => {
it(`js -> js: depth: 5, num: ${num}`, function () {
this.timeout(6000)

const dir = tmpDir()
return randomFs({
path: dir,
Expand Down
29 changes: 26 additions & 3 deletions test/utils/another-daemon-spawner.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ exports.spawnGoNode = (addrs, hop, api, gateway, callback) => {
DisableNatPortMap: false,
DisableRelay: false,
EnableRelayHop: hop
},
API: {
HTTPHeaders: {
'Access-Control-Allow-Origin': ['*'],
'Access-Control-Allow-Methods': [
'PUT',
'POST',
'GET'
]
}
}
}
})
Expand Down Expand Up @@ -92,10 +102,23 @@ exports.spawnJsNode = (addrs, hop, api, gateway, callback) => {
API: `/ip4/0.0.0.0/tcp/${api}`,
Gateway: `/ip4/0.0.0.0/tcp/${gateway}`
},
API: {
HTTPHeaders: {
'Access-Control-Allow-Origin': ['*'],
'Access-Control-Allow-Methods': [
'PUT',
'POST',
'GET'
]
}
},
EXPERIMENTAL: {
Swarm: {
DisableRelay: false,
EnableRelayHop: hop
relay: {
enabled: true,
hop: {
enabled: hop,
active: false
}
}
}
}), cb),
Expand Down

0 comments on commit af39873

Please sign in to comment.