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

Commit af39873

Browse files
committed
fix: circuit tests
1 parent 93cc273 commit af39873

File tree

5 files changed

+88
-37
lines changed

5 files changed

+88
-37
lines changed

.aegir.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ function start (done) {
1818
(cb) => js([`${base}/10012`, `${base}/20012/ws`], true, 31012, 32012, cb),
1919
(cb) => js([`${base}/10013`, `${base}/20013/ws`], true, 31013, 32013, cb),
2020
(cb) => js([`${base}/10014`, `${base}/20014/ws`], true, 31014, 32014, cb),
21-
(cb) => js([`${base}/10015`, `${base}/20015/ws`], true, 31015, 32015, cb)
21+
(cb) => js([`${base}/10015`, `${base}/20015/ws`], true, 31015, 32015, cb),
22+
(cb) => go([`${base}/10027`, `${base}/20027/ws`], true, 33027, 44027, cb), // we need this for circuit for now
2223
], done)
2324
} else if (process.env.IPFS_TEST === 'interop') {
2425
parallel([
@@ -38,9 +39,9 @@ module.exports = {
3839
pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*',
3940
watched: false,
4041
served: true,
41-
included: false,
42-
singleRun: false
43-
}]
42+
included: false
43+
}],
44+
singleRun: true
4445
},
4546
hooks: {
4647
pre: start,

test/core/circuit-relay.spec.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const parallel = require('async/parallel')
1010
const series = require('async/series')
1111
const waterfall = require('async/waterfall')
1212
const API = require('ipfs-api')
13-
const bl = require('bl')
1413
const PeerInfo = require('peer-info')
1514
const PeerId = require('peer-id')
1615
const multiaddr = require('multiaddr')
@@ -34,7 +33,7 @@ describe.skip('circuit', function () {
3433
let factory
3534

3635
let jsRelay = new API(`/ip4/127.0.0.1/tcp/31015`)
37-
// let goRelay = new API(`/ip4/127.0.0.1/tcp/33031`)
36+
let goRelay = new API(`/ip4/127.0.0.1/tcp/33027`)
3837
let node1
3938
let node2
4039

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

5251
const base = {
5352
EXPERIMENTAL: {
54-
Relay: {
55-
Enabled: true
53+
relay: {
54+
enabled: true
5655
}
5756
},
5857
Addresses: {
@@ -63,12 +62,12 @@ describe.skip('circuit', function () {
6362
parallel([
6463
(cb) => factory.spawnNode(null, Object.assign(base, {
6564
Addresses: {
66-
Swarm: [ (isNode ? `/ip4/127.0.0.1/tcp/0` : '') ]
65+
Swarm: [(isNode ? `/ip4/127.0.0.1/tcp/0` : '')]
6766
}
6867
}), cb),
6968
(cb) => factory.spawnNode(null, Object.assign(base, {
7069
Addresses: {
71-
Swarm: [ (isNode ? `/ip4/127.0.0.1/tcp/0/ws` : '') ]
70+
Swarm: [(isNode ? `/ip4/127.0.0.1/tcp/0/ws` : '')]
7271
}
7372
}), cb)
7473
], (err, nodes) => {
@@ -78,20 +77,20 @@ describe.skip('circuit', function () {
7877

7978
parallel([
8079
(cb) => jsRelay.id(cb),
81-
// (cb) => goRelay.id(cb),
80+
(cb) => goRelay.id(cb),
8281
(cb) => node1.id(cb),
8382
(cb) => node2.id(cb)
8483
], (err, res2) => {
8584
expect(err).to.not.exist()
8685
parallel([
8786
(cb) => peerInfoFromObj(res2[0], cb),
88-
// (cb) => peerInfoFromObj(res2[1], cb),
87+
(cb) => peerInfoFromObj(res2[1], cb),
8988
(cb) => peerInfoFromObj(res2[1], cb),
9089
(cb) => peerInfoFromObj(res2[2], cb)
9190
], (err, res3) => {
9291
expect(err).to.not.exist()
9392
jsRelayId = res3[0]
94-
// goRelayId = res3[1]
93+
goRelayId = res3[1]
9594
// nodeId1 = res3[2]
9695
nodeId2 = res3[2]
9796
done()
@@ -102,9 +101,7 @@ describe.skip('circuit', function () {
102101

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

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

110107
series([
@@ -115,15 +112,19 @@ describe.skip('circuit', function () {
115112
(cb) => node1.swarm.connect(nodeId2, cb)
116113
], (err) => {
117114
expect(err).to.not.exist()
115+
118116
waterfall([
119117
(cb) => node1.files.add(data, cb),
120118
(filesAdded, cb) => node2.files.cat(filesAdded[0].hash, cb),
121-
(stream, cb) => stream.pipe(bl(cb))
119+
(buffer, cb) => {
120+
expect(buffer).to.deep.equal(data)
121+
cb()
122+
}
122123
], done)
123124
})
124125
})
125126

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

129130
series([
@@ -138,7 +139,10 @@ describe.skip('circuit', function () {
138139
waterfall([
139140
(cb) => node1.files.add(data, cb),
140141
(filesAdded, cb) => node2.files.cat(filesAdded[0].hash, cb),
141-
(stream, cb) => stream.pipe(bl(cb))
142+
(buffer, cb) => {
143+
expect(buffer).to.deep.equal(data)
144+
cb()
145+
}
142146
], done)
143147
})
144148
})

test/interop/circuit-relay.js

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const expect = chai.expect
88
chai.use(dirtyChai)
99
const parallel = require('async/parallel')
1010
const series = require('async/series')
11-
const bl = require('bl')
1211
const waterfall = require('async/waterfall')
1312
const multiaddr = require('multiaddr')
1413
const crypto = require('crypto')
@@ -18,7 +17,7 @@ const js = ads.spawnJsNode
1817
const go = ads.spawnGoNode
1918
const stop = ads.stopNodes
2019

21-
describe.skip('circuit interop', () => {
20+
describe('circuit interop', () => {
2221
let jsTCP
2322
let jsTCPAddrs
2423
let jsWS
@@ -33,7 +32,8 @@ describe.skip('circuit interop', () => {
3332
let goWSAddrs
3433
let goWS
3534

36-
beforeEach((done) => {
35+
beforeEach(function (done) {
36+
this.timeout(20 * 1000)
3737
const base = '/ip4/127.0.0.1/tcp'
3838

3939
parallel([
@@ -61,7 +61,7 @@ describe.skip('circuit interop', () => {
6161
})
6262
})
6363

64-
afterEach(() => stop())
64+
afterEach((done) => stop(done))
6565

6666
it('jsWS <-> jsRelay <-> jsTCP', (done) => {
6767
const data = crypto.randomBytes(128)
@@ -75,7 +75,10 @@ describe.skip('circuit interop', () => {
7575
waterfall([
7676
(cb) => jsTCP.files.add(data, cb),
7777
(res, cb) => jsWS.files.cat(res[0].hash, cb),
78-
(stream, cb) => stream.pipe(bl(cb))
78+
(buffer, cb) => {
79+
expect(buffer).to.deep.equal(data)
80+
cb()
81+
}
7982
], done)
8083
})
8184
})
@@ -92,7 +95,10 @@ describe.skip('circuit interop', () => {
9295
waterfall([
9396
(cb) => goTCP.files.add(data, cb),
9497
(res, cb) => goWS.files.cat(res[0].hash, cb),
95-
(stream, cb) => stream.pipe(bl(cb))
98+
(buffer, cb) => {
99+
expect(buffer).to.deep.equal(data)
100+
cb()
101+
}
96102
], done)
97103
})
98104
})
@@ -109,24 +115,31 @@ describe.skip('circuit interop', () => {
109115
waterfall([
110116
(cb) => goTCP.files.add(data, cb),
111117
(res, cb) => jsWS.files.cat(res[0].hash, cb),
112-
(stream, cb) => stream.pipe(bl(cb))
118+
(buffer, cb) => {
119+
expect(buffer).to.deep.equal(data)
120+
cb()
121+
}
113122
], done)
114123
})
115124
})
116125

117126
it('jsTCP <-> goRelay <-> jsWS', (done) => {
118127
const data = crypto.randomBytes(128)
119128
series([
120-
(cb) => jsTCP.swarm.connect(goRelayAddrs[2], cb),
129+
(cb) => jsTCP.swarm.connect(goRelayAddrs[1], cb),
121130
(cb) => jsWS.swarm.connect(goRelayAddrs[0], cb),
131+
(cb) => jsTCP.swarm.connect(goRelayAddrs[1], cb),
122132
(cb) => setTimeout(cb, 1000),
123133
(cb) => jsWS.swarm.connect(jsTCPAddrs[0], cb)
124134
], (err) => {
125135
expect(err).to.not.exist()
126136
waterfall([
127137
(cb) => jsTCP.files.add(data, cb),
128138
(res, cb) => jsWS.files.cat(res[0].hash, cb),
129-
(stream, cb) => stream.pipe(bl(cb))
139+
(buffer, cb) => {
140+
expect(buffer).to.deep.equal(data)
141+
cb()
142+
}
130143
], done)
131144
})
132145
})
@@ -135,15 +148,18 @@ describe.skip('circuit interop', () => {
135148
const data = crypto.randomBytes(128)
136149
series([
137150
(cb) => goWS.swarm.connect(goRelayAddrs[0], cb),
138-
(cb) => goTCP.swarm.connect(goRelayAddrs[2], cb),
151+
(cb) => goTCP.swarm.connect(goRelayAddrs[1], cb),
139152
(cb) => setTimeout(cb, 1000),
140153
(cb) => goWS.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(goTCPAddrs[0]).getPeerId()}`, cb)
141154
], (err) => {
142155
expect(err).to.not.exist()
143156
waterfall([
144157
(cb) => goTCP.files.add(data, cb),
145158
(res, cb) => goWS.files.cat(res[0].hash, cb),
146-
(stream, cb) => stream.pipe(bl(cb))
159+
(buffer, cb) => {
160+
expect(buffer).to.deep.equal(data)
161+
cb()
162+
}
147163
], done)
148164
})
149165
})
@@ -152,15 +168,18 @@ describe.skip('circuit interop', () => {
152168
const data = crypto.randomBytes(128)
153169
series([
154170
(cb) => jsWS.swarm.connect(goRelayAddrs[0], cb),
155-
(cb) => goTCP.swarm.connect(goRelayAddrs[2], cb),
171+
(cb) => goTCP.swarm.connect(goRelayAddrs[1], cb),
156172
(cb) => setTimeout(cb, 1000),
157173
(cb) => goTCP.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(jsWSAddrs[0]).getPeerId()}`, cb)
158174
], (err) => {
159175
expect(err).to.not.exist()
160176
waterfall([
161177
(cb) => goTCP.files.add(data, cb),
162178
(res, cb) => jsWS.files.cat(res[0].hash, cb),
163-
(stream, cb) => stream.pipe(bl(cb))
179+
(buffer, cb) => {
180+
expect(buffer).to.deep.equal(data)
181+
cb()
182+
}
164183
], done)
165184
})
166185
})

test/interop/exchange-files.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ describe('exchange files', () => {
179179
})
180180
})
181181

182-
it(`js -> go: depth: 5, num: ${num}`, () => {
182+
it(`js -> go: depth: 5, num: ${num}`, function () {
183+
this.timeout(6000)
184+
183185
const dir = tmpDir()
184186
return randomFs({
185187
path: dir,
@@ -196,7 +198,9 @@ describe('exchange files', () => {
196198
})
197199
})
198200

199-
it(`js -> js: depth: 5, num: ${num}`, () => {
201+
it(`js -> js: depth: 5, num: ${num}`, function () {
202+
this.timeout(6000)
203+
200204
const dir = tmpDir()
201205
return randomFs({
202206
path: dir,

test/utils/another-daemon-spawner.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ exports.spawnGoNode = (addrs, hop, api, gateway, callback) => {
4545
DisableNatPortMap: false,
4646
DisableRelay: false,
4747
EnableRelayHop: hop
48+
},
49+
API: {
50+
HTTPHeaders: {
51+
'Access-Control-Allow-Origin': ['*'],
52+
'Access-Control-Allow-Methods': [
53+
'PUT',
54+
'POST',
55+
'GET'
56+
]
57+
}
4858
}
4959
}
5060
})
@@ -92,10 +102,23 @@ exports.spawnJsNode = (addrs, hop, api, gateway, callback) => {
92102
API: `/ip4/0.0.0.0/tcp/${api}`,
93103
Gateway: `/ip4/0.0.0.0/tcp/${gateway}`
94104
},
105+
API: {
106+
HTTPHeaders: {
107+
'Access-Control-Allow-Origin': ['*'],
108+
'Access-Control-Allow-Methods': [
109+
'PUT',
110+
'POST',
111+
'GET'
112+
]
113+
}
114+
},
95115
EXPERIMENTAL: {
96-
Swarm: {
97-
DisableRelay: false,
98-
EnableRelayHop: hop
116+
relay: {
117+
enabled: true,
118+
hop: {
119+
enabled: hop,
120+
active: false
121+
}
99122
}
100123
}
101124
}), cb),

0 commit comments

Comments
 (0)