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

Commit cb109fc

Browse files
fix: interop tests with multiplex passing
1 parent f620d71 commit cb109fc

File tree

9 files changed

+120
-26
lines changed

9 files changed

+120
-26
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
"ncp": "^2.0.0",
8484
"nexpect": "^0.5.0",
8585
"pre-commit": "^1.2.2",
86+
"pretty-bytes": "^4.0.2",
8687
"qs": "^6.3.0",
88+
"random-fs": "^1.0.3",
8789
"rimraf": "^2.5.4",
8890
"stream-to-promise": "^2.2.0",
8991
"transform-loader": "^0.2.3"
@@ -100,7 +102,7 @@
100102
"hoek": "^4.1.0",
101103
"idb-pull-blob-store": "~0.5.1",
102104
"ipfs-api": "^12.1.7",
103-
"ipfs-bitswap": "~0.9.3",
105+
"ipfs-bitswap": "~0.9.4",
104106
"ipfs-block": "~0.5.5",
105107
"ipfs-block-service": "~0.8.3",
106108
"ipfs-multipart": "~0.1.0",
@@ -175,4 +177,4 @@
175177
"npmcdn-to-unpkg-bot <[email protected]>",
176178
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <[email protected]>"
177179
]
178-
}
180+
}

src/core/components/go-online.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ module.exports = (self) => {
1717
self._bitswap = new Bitswap(
1818
self._libp2pNode,
1919
self._repo.blockstore,
20-
self._libp2pNode.peerBook
20+
self._peerInfoBook
2121
)
2222

23-
self._pubsub = new FloodSub(self._libp2pNode)
23+
const pubsub = self._configOpts.EXPERIMENTAL.pubsub
2424

25+
if (pubsub) {
26+
self._pubsub = new FloodSub(self._libp2pNode)
27+
}
2528
series([
2629
(cb) => {
2730
self._bitswap.start()
@@ -32,7 +35,7 @@ module.exports = (self) => {
3235
cb()
3336
},
3437
(cb) => {
35-
if (self._configOpts.EXPERIMENTAL.pubsub) {
38+
if (pubsub) {
3639
self._pubsub.start(cb)
3740
} else {
3841
cb()

src/core/components/libp2p.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = function libp2p (self) {
1919
bootstrap: config.Bootstrap
2020
}
2121

22-
self._libp2pNode = new Node(self._peerInfo, undefined, options)
22+
self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options)
2323

2424
self._libp2pNode.start((err) => {
2525
if (err) {
@@ -31,11 +31,11 @@ module.exports = function libp2p (self) {
3131
})
3232

3333
self._libp2pNode.discovery.on('peer', (peerInfo) => {
34-
self._libp2pNode.peerBook.put(peerInfo)
34+
self._peerInfoBook.put(peerInfo)
3535
self._libp2pNode.dialByPeerInfo(peerInfo, () => {})
3636
})
3737
self._libp2pNode.swarm.on('peer-mux-established', (peerInfo) => {
38-
self._libp2pNode.peerBook.put(peerInfo)
38+
self._peerInfoBook.put(peerInfo)
3939
})
4040

4141
callback()

src/core/components/swarm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = function swarm (self) {
2323
// TODO: return latency and streams when verbose is set
2424
// we currently don't have this information
2525

26-
const peers = self._libp2pNode.peerBook.getAll()
26+
const peers = self._peerInfoBook.getAll()
2727
const keys = Object.keys(peers)
2828

2929
const peerList = flatMap(keys, (id) => {
@@ -52,7 +52,7 @@ module.exports = function swarm (self) {
5252
return callback(OFFLINE_ERROR)
5353
}
5454

55-
const peers = values(self._libp2pNode.peerBook.getAll())
55+
const peers = values(self._peerInfoBook.getAll())
5656
callback(null, peers)
5757
}),
5858

test/interop/daemons/go.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const ctl = require('ipfsd-ctl')
44
const waterfall = require('async/waterfall')
55

6+
const flags = ['--enable-mplex-experiment']
7+
68
class GoDaemon {
79
constructor (opts) {
810
opts = opts || {
@@ -37,7 +39,7 @@ class GoDaemon {
3739
this.node = node
3840
this.node.setConfig('Bootstrap', '[]', cb)
3941
},
40-
(res, cb) => this.node.startDaemon(cb),
42+
(res, cb) => this.node.startDaemon(flags, cb),
4143
(api, cb) => {
4244
this.api = api
4345

test/interop/daemons/js.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict'
22

3-
const os = require('os')
43
const IPFSAPI = require('ipfs-api')
54
const series = require('async/series')
65
const rimraf = require('rimraf')
76
const IPFSRepo = require('ipfs-repo')
7+
const tmpDir = require('../util').tmpDir
88

99
const IPFS = require('../../../src/core')
1010
const HTTPAPI = require('../../../src/http-api')
@@ -23,7 +23,10 @@ function setPorts (ipfs, port, callback) {
2323
),
2424
(cb) => ipfs.config.set(
2525
'Addresses.Swarm',
26-
['/ip4/0.0.0.0/tcp/' + (4002 + port)],
26+
[
27+
'/ip4/0.0.0.0/tcp/' + (4003 + port),
28+
'/ip4/0.0.0.0/tcp/' + (4004 + port) + '/ws'
29+
],
2730
cb
2831
)
2932
], callback)
@@ -41,15 +44,18 @@ class JsDaemon {
4144
this.init = opts.init
4245
this.port = opts.port
4346

44-
this.path = opts.path || os.tmpdir() + `/${Math.ceil(Math.random() * 10000)}`
47+
this.path = opts.path || tmpDir()
4548
if (this.init) {
4649
this.ipfs = new IPFS({
4750
repo: this.path
4851
})
4952
} else {
5053
const repo = new IPFSRepo(this.path, {stores: require('fs-pull-blob-store')})
5154
this.ipfs = new IPFS({
52-
repo: repo
55+
repo: repo,
56+
EXPERIMENTAL: {
57+
pubsub: true
58+
}
5359
})
5460
}
5561
this.node = null

test/interop/index.js

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ const parallel = require('async/parallel')
77
const waterfall = require('async/waterfall')
88
const bl = require('bl')
99
const crypto = require('crypto')
10+
const pretty = require('pretty-bytes')
11+
const randomFs = require('random-fs')
12+
const promisify = require('promisify-es6')
13+
const rimraf = require('rimraf')
14+
15+
const rmDir = promisify(rimraf)
16+
17+
const tmpDir = require('./util').tmpDir
1018

1119
const GoDaemon = require('./daemons/go')
1220
const JsDaemon = require('./daemons/js')
@@ -19,12 +27,18 @@ const sizes = [
1927
1024 * 512,
2028
1024 * 768,
2129
1024 * 1023,
22-
// starts failing with multiplex
2330
1024 * 1024,
2431
1024 * 1024 * 4,
2532
1024 * 1024 * 8
2633
]
2734

35+
const dirs = [
36+
5,
37+
10,
38+
50,
39+
100
40+
]
41+
2842
describe('basic', () => {
2943
let goDaemon
3044
let jsDaemon
@@ -107,7 +121,7 @@ describe('basic', () => {
107121
})
108122

109123
describe('cat file', () => sizes.forEach((size) => {
110-
it(`go -> js: ${size}bytes`, (done) => {
124+
it(`go -> js: ${pretty(size)}`, (done) => {
111125
const data = crypto.randomBytes(size)
112126
waterfall([
113127
(cb) => goDaemon.api.add(data, cb),
@@ -120,7 +134,7 @@ describe('basic', () => {
120134
})
121135
})
122136

123-
it(`js -> go: ${size}bytes`, (done) => {
137+
it(`js -> go: ${pretty(size)}`, (done) => {
124138
const data = crypto.randomBytes(size)
125139
waterfall([
126140
(cb) => jsDaemon.api.add(data, cb),
@@ -133,7 +147,7 @@ describe('basic', () => {
133147
})
134148
})
135149

136-
it(`js -> js: ${size}bytes`, (done) => {
150+
it(`js -> js: ${pretty(size)}`, (done) => {
137151
const data = crypto.randomBytes(size)
138152
waterfall([
139153
(cb) => js2Daemon.api.add(data, cb),
@@ -146,4 +160,57 @@ describe('basic', () => {
146160
})
147161
})
148162
}))
163+
164+
describe('get directory', () => dirs.forEach((num) => {
165+
it(`go -> js: depth: 5, num: ${num}`, () => {
166+
const dir = tmpDir()
167+
return randomFs({
168+
path: dir,
169+
depth: 5,
170+
number: num
171+
}).then(() => {
172+
return goDaemon.api.util.addFromFs(dir, {recursive: true})
173+
}).then((res) => {
174+
const hash = res[res.length - 1].hash
175+
return jsDaemon.api.object.get(hash)
176+
}).then((res) => {
177+
expect(res).to.exist
178+
return rmDir(dir)
179+
})
180+
})
181+
182+
it(`js -> go: depth: 5, num: ${num}`, () => {
183+
const dir = tmpDir()
184+
return randomFs({
185+
path: dir,
186+
depth: 5,
187+
number: num
188+
}).then(() => {
189+
return jsDaemon.api.util.addFromFs(dir, {recursive: true})
190+
}).then((res) => {
191+
const hash = res[res.length - 1].hash
192+
return goDaemon.api.object.get(hash)
193+
}).then((res) => {
194+
expect(res).to.exist
195+
return rmDir(dir)
196+
})
197+
})
198+
199+
it(`js -> js: depth: 5, num: ${num}`, () => {
200+
const dir = tmpDir()
201+
return randomFs({
202+
path: dir,
203+
depth: 5,
204+
number: num
205+
}).then(() => {
206+
return js2Daemon.api.util.addFromFs(dir, {recursive: true})
207+
}).then((res) => {
208+
const hash = res[res.length - 1].hash
209+
return jsDaemon.api.object.get(hash)
210+
}).then((res) => {
211+
expect(res).to.exist
212+
return rmDir(dir)
213+
})
214+
})
215+
}))
149216
})

test/interop/util.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict'
2+
3+
const os = require('os')
4+
const crypto = require('libp2p-crypto')
5+
const path = require('path')
6+
7+
exports.tmpDir = (prefix) => {
8+
return path.join(
9+
os.tmpdir(),
10+
prefix || 'tmp',
11+
crypto.randomBytes(32).toString('hex')
12+
)
13+
}

test/node.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ let testCLI = true
66

77
if (process.env.TEST) {
88
switch (process.env.TEST) {
9-
case 'core': {
9+
case 'core':
1010
testHTTP = false
1111
testCLI = false
12-
} break
13-
case 'http': {
12+
break
13+
case 'http':
1414
testCore = false
1515
testCLI = false
16-
} break
17-
case 'cli': {
16+
break
17+
case 'cli':
1818
testCore = false
1919
testHTTP = false
20-
} break
21-
default: break
20+
break
21+
default:
22+
break
2223
}
2324
}
2425

0 commit comments

Comments
 (0)