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

Commit

Permalink
fix: interop tests with multiplex passing
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire authored Feb 22, 2017
1 parent f620d71 commit cb109fc
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 26 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@
"ncp": "^2.0.0",
"nexpect": "^0.5.0",
"pre-commit": "^1.2.2",
"pretty-bytes": "^4.0.2",
"qs": "^6.3.0",
"random-fs": "^1.0.3",
"rimraf": "^2.5.4",
"stream-to-promise": "^2.2.0",
"transform-loader": "^0.2.3"
Expand All @@ -100,7 +102,7 @@
"hoek": "^4.1.0",
"idb-pull-blob-store": "~0.5.1",
"ipfs-api": "^12.1.7",
"ipfs-bitswap": "~0.9.3",
"ipfs-bitswap": "~0.9.4",
"ipfs-block": "~0.5.5",
"ipfs-block-service": "~0.8.3",
"ipfs-multipart": "~0.1.0",
Expand Down Expand Up @@ -175,4 +177,4 @@
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
]
}
}
9 changes: 6 additions & 3 deletions src/core/components/go-online.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ module.exports = (self) => {
self._bitswap = new Bitswap(
self._libp2pNode,
self._repo.blockstore,
self._libp2pNode.peerBook
self._peerInfoBook
)

self._pubsub = new FloodSub(self._libp2pNode)
const pubsub = self._configOpts.EXPERIMENTAL.pubsub

if (pubsub) {
self._pubsub = new FloodSub(self._libp2pNode)
}
series([
(cb) => {
self._bitswap.start()
Expand All @@ -32,7 +35,7 @@ module.exports = (self) => {
cb()
},
(cb) => {
if (self._configOpts.EXPERIMENTAL.pubsub) {
if (pubsub) {
self._pubsub.start(cb)
} else {
cb()
Expand Down
6 changes: 3 additions & 3 deletions src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function libp2p (self) {
bootstrap: config.Bootstrap
}

self._libp2pNode = new Node(self._peerInfo, undefined, options)
self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options)

self._libp2pNode.start((err) => {
if (err) {
Expand All @@ -31,11 +31,11 @@ module.exports = function libp2p (self) {
})

self._libp2pNode.discovery.on('peer', (peerInfo) => {
self._libp2pNode.peerBook.put(peerInfo)
self._peerInfoBook.put(peerInfo)
self._libp2pNode.dialByPeerInfo(peerInfo, () => {})
})
self._libp2pNode.swarm.on('peer-mux-established', (peerInfo) => {
self._libp2pNode.peerBook.put(peerInfo)
self._peerInfoBook.put(peerInfo)
})

callback()
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function swarm (self) {
// TODO: return latency and streams when verbose is set
// we currently don't have this information

const peers = self._libp2pNode.peerBook.getAll()
const peers = self._peerInfoBook.getAll()
const keys = Object.keys(peers)

const peerList = flatMap(keys, (id) => {
Expand Down Expand Up @@ -52,7 +52,7 @@ module.exports = function swarm (self) {
return callback(OFFLINE_ERROR)
}

const peers = values(self._libp2pNode.peerBook.getAll())
const peers = values(self._peerInfoBook.getAll())
callback(null, peers)
}),

Expand Down
4 changes: 3 additions & 1 deletion test/interop/daemons/go.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const ctl = require('ipfsd-ctl')
const waterfall = require('async/waterfall')

const flags = ['--enable-mplex-experiment']

class GoDaemon {
constructor (opts) {
opts = opts || {
Expand Down Expand Up @@ -37,7 +39,7 @@ class GoDaemon {
this.node = node
this.node.setConfig('Bootstrap', '[]', cb)
},
(res, cb) => this.node.startDaemon(cb),
(res, cb) => this.node.startDaemon(flags, cb),
(api, cb) => {
this.api = api

Expand Down
14 changes: 10 additions & 4 deletions test/interop/daemons/js.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const os = require('os')
const IPFSAPI = require('ipfs-api')
const series = require('async/series')
const rimraf = require('rimraf')
const IPFSRepo = require('ipfs-repo')
const tmpDir = require('../util').tmpDir

const IPFS = require('../../../src/core')
const HTTPAPI = require('../../../src/http-api')
Expand All @@ -23,7 +23,10 @@ function setPorts (ipfs, port, callback) {
),
(cb) => ipfs.config.set(
'Addresses.Swarm',
['/ip4/0.0.0.0/tcp/' + (4002 + port)],
[
'/ip4/0.0.0.0/tcp/' + (4003 + port),
'/ip4/0.0.0.0/tcp/' + (4004 + port) + '/ws'
],
cb
)
], callback)
Expand All @@ -41,15 +44,18 @@ class JsDaemon {
this.init = opts.init
this.port = opts.port

this.path = opts.path || os.tmpdir() + `/${Math.ceil(Math.random() * 10000)}`
this.path = opts.path || tmpDir()
if (this.init) {
this.ipfs = new IPFS({
repo: this.path
})
} else {
const repo = new IPFSRepo(this.path, {stores: require('fs-pull-blob-store')})
this.ipfs = new IPFS({
repo: repo
repo: repo,
EXPERIMENTAL: {
pubsub: true
}
})
}
this.node = null
Expand Down
75 changes: 71 additions & 4 deletions test/interop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const parallel = require('async/parallel')
const waterfall = require('async/waterfall')
const bl = require('bl')
const crypto = require('crypto')
const pretty = require('pretty-bytes')
const randomFs = require('random-fs')
const promisify = require('promisify-es6')
const rimraf = require('rimraf')

const rmDir = promisify(rimraf)

const tmpDir = require('./util').tmpDir

const GoDaemon = require('./daemons/go')
const JsDaemon = require('./daemons/js')
Expand All @@ -19,12 +27,18 @@ const sizes = [
1024 * 512,
1024 * 768,
1024 * 1023,
// starts failing with multiplex
1024 * 1024,
1024 * 1024 * 4,
1024 * 1024 * 8
]

const dirs = [
5,
10,
50,
100
]

describe('basic', () => {
let goDaemon
let jsDaemon
Expand Down Expand Up @@ -107,7 +121,7 @@ describe('basic', () => {
})

describe('cat file', () => sizes.forEach((size) => {
it(`go -> js: ${size}bytes`, (done) => {
it(`go -> js: ${pretty(size)}`, (done) => {
const data = crypto.randomBytes(size)
waterfall([
(cb) => goDaemon.api.add(data, cb),
Expand All @@ -120,7 +134,7 @@ describe('basic', () => {
})
})

it(`js -> go: ${size}bytes`, (done) => {
it(`js -> go: ${pretty(size)}`, (done) => {
const data = crypto.randomBytes(size)
waterfall([
(cb) => jsDaemon.api.add(data, cb),
Expand All @@ -133,7 +147,7 @@ describe('basic', () => {
})
})

it(`js -> js: ${size}bytes`, (done) => {
it(`js -> js: ${pretty(size)}`, (done) => {
const data = crypto.randomBytes(size)
waterfall([
(cb) => js2Daemon.api.add(data, cb),
Expand All @@ -146,4 +160,57 @@ describe('basic', () => {
})
})
}))

describe('get directory', () => dirs.forEach((num) => {
it(`go -> js: depth: 5, num: ${num}`, () => {
const dir = tmpDir()
return randomFs({
path: dir,
depth: 5,
number: num
}).then(() => {
return goDaemon.api.util.addFromFs(dir, {recursive: true})
}).then((res) => {
const hash = res[res.length - 1].hash
return jsDaemon.api.object.get(hash)
}).then((res) => {
expect(res).to.exist
return rmDir(dir)
})
})

it(`js -> go: depth: 5, num: ${num}`, () => {
const dir = tmpDir()
return randomFs({
path: dir,
depth: 5,
number: num
}).then(() => {
return jsDaemon.api.util.addFromFs(dir, {recursive: true})
}).then((res) => {
const hash = res[res.length - 1].hash
return goDaemon.api.object.get(hash)
}).then((res) => {
expect(res).to.exist
return rmDir(dir)
})
})

it(`js -> js: depth: 5, num: ${num}`, () => {
const dir = tmpDir()
return randomFs({
path: dir,
depth: 5,
number: num
}).then(() => {
return js2Daemon.api.util.addFromFs(dir, {recursive: true})
}).then((res) => {
const hash = res[res.length - 1].hash
return jsDaemon.api.object.get(hash)
}).then((res) => {
expect(res).to.exist
return rmDir(dir)
})
})
}))
})
13 changes: 13 additions & 0 deletions test/interop/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

const os = require('os')
const crypto = require('libp2p-crypto')
const path = require('path')

exports.tmpDir = (prefix) => {
return path.join(
os.tmpdir(),
prefix || 'tmp',
crypto.randomBytes(32).toString('hex')
)
}
15 changes: 8 additions & 7 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ let testCLI = true

if (process.env.TEST) {
switch (process.env.TEST) {
case 'core': {
case 'core':
testHTTP = false
testCLI = false
} break
case 'http': {
break
case 'http':
testCore = false
testCLI = false
} break
case 'cli': {
break
case 'cli':
testCore = false
testHTTP = false
} break
default: break
break
default:
break
}
}

Expand Down

0 comments on commit cb109fc

Please sign in to comment.