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

Commit 5877863

Browse files
authored
Merge pull request #674 from ipfs/feat/add-interop-tests
Set up interop and benchmark tests
2 parents 3e2507b + bddcee7 commit 5877863

File tree

11 files changed

+450
-18
lines changed

11 files changed

+450
-18
lines changed

README.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,58 @@ Every IPFS instance also exposes the libp2p API at `ipfs.libp2p`. The formal int
223223
> npm install
224224
```
225225
226-
### Run Tests
226+
### Run unit tests
227227
228228
```sh
229-
> npm test
229+
# run all the unit tsts
230+
> npm test
231+
232+
# run just IPFS tests in Node.js
233+
> npm run test:unit:node:core
230234

231235
# run just IPFS core tests
232-
> npm run test:node:core
236+
> npm run test:unit:node:core
233237

234238
# run just IPFS HTTP-API tests
235-
> npm run test:node:http
239+
> npm run test:unit:node:http
236240

237241
# run just IPFS CLI tests
238-
> npm run test:node:cli
242+
> npm run test:unit:node:cli
243+
244+
# run just IPFS core tests in the Browser (Chrome)
245+
> npm run test:unit:browser
246+
```
247+
248+
### Run interop tests
249+
250+
```sh
251+
# run all the interop tsts
252+
> npm test:interop
253+
254+
# run just IPFS interop tests in Node.js using one go-ipfs daemon and one js-ipfs daemon
255+
> npm run test:interop:node
256+
257+
# run just IPFS interop testsin the Browser (Chrome) using one instance in the browser and one go-ipfs daemon
258+
> npm run test:interop:browser
259+
```
260+
261+
### Run benchmark tests
262+
263+
```sh
264+
# run all the interop tsts
265+
> npm test:benchmark
266+
267+
# run just IPFS benchmarks in Node.js
268+
> npm run test:benchmark:node
269+
270+
# run just IPFS benchmarks in Node.js for an IPFS instance
271+
> npm run test:benchmark:node:core
272+
273+
# run just IPFS benchmarks in Node.js for an IPFS daemon
274+
> npm run test:benchmark:node:http
239275

240-
# run just IPFS Browser tests
241-
> npm run test:browser
276+
# run just IPFS benchmarks in the browser (Chrome)
277+
> npm run test:benchmark:browser
242278
```
243279
244280
### Lint

package.json

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@
2121
"lint": "aegir-lint",
2222
"coverage": "gulp coverage",
2323
"test": "gulp test",
24-
"test:node": "gulp test:node",
25-
"test:node:core": "TEST=core npm run test:node",
26-
"test:node:http": "TEST=http npm run test:node",
27-
"test:node:cli": "TEST=cli npm run test:node",
28-
"test:browser": "gulp test:browser",
24+
"test:unit:node": "gulp test:node",
25+
"test:unit:node:core": "TEST=core npm run test:node",
26+
"test:unit:node:http": "TEST=http npm run test:node",
27+
"test:unit:node:cli": "TEST=cli npm run test:node",
28+
"test:unit:browser": "gulp test:browser",
29+
"test:interop": "mocha -t 60000 test/interop",
30+
"test:interop:node": "mocha -t 60000 test/interop/node.js",
31+
"test:interop:browser": "mocha test/interop/browser.js",
32+
"test:benchmark": "echo \"Error: no benchmarks yet\" && exit 1",
33+
"test:benchmark:node": "echo \"Error: no benchmarks yet\" && exit 1",
34+
"test:benchmark:node:core": "echo \"Error: no benchmarks yet\" && exit 1",
35+
"test:benchmark:node:http": "echo \"Error: no benchmarks yet\" && exit 1",
36+
"test:benchmark:browser": "echo \"Error: no benchmarks yet\" && exit 1",
2937
"build": "gulp build",
3038
"release": "gulp release",
3139
"release-minor": "gulp release --type minor",
@@ -60,9 +68,11 @@
6068
"form-data": "^2.1.2",
6169
"fs-pull-blob-store": "^0.4.1",
6270
"gulp": "^3.9.1",
63-
"interface-ipfs-core": "^0.22.1",
71+
"interface-ipfs-core": "^0.23.0",
72+
"ipfsd-ctl": "^0.18.0",
6473
"left-pad": "^1.1.3",
6574
"lodash": "^4.17.2",
75+
"mocha": "^3.2.0",
6676
"ncp": "^2.0.0",
6777
"nexpect": "^0.5.0",
6878
"pre-commit": "^1.2.2",
@@ -75,15 +85,15 @@
7585
"async": "^2.1.4",
7686
"bl": "^1.2.0",
7787
"boom": "^4.2.0",
78-
"debug": "^2.4.5",
88+
"debug": "^2.5.1",
7989
"fs-pull-blob-store": "^0.3.0",
8090
"glob": "^7.1.1",
81-
"hapi": "^16.0.1",
91+
"hapi": "^16.0.2",
8292
"hapi-set-header": "^1.0.2",
8393
"idb-pull-blob-store": "^0.5.1",
84-
"ipfs-api": "^12.1.0",
94+
"ipfs-api": "^12.1.2",
8595
"ipfs-bitswap": "^0.8.3",
86-
"ipfs-block": "^0.5.3",
96+
"ipfs-block": "^0.5.4",
8797
"ipfs-block-service": "^0.7.2",
8898
"ipfs-multipart": "^0.1.0",
8999
"ipfs-repo": "^0.11.2",

src/core/components/go-online.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = function goOnline (self) {
1414
}
1515

1616
self._bitswap = new Bitswap(
17-
self._libp2pNode.peerInfo,
17+
{}, // TODO remove when new bitswap is merged
1818
self._libp2pNode,
1919
self._repo.blockstore,
2020
self._libp2pNode.peerBook

test/interop/browser.js

Whitespace-only changes.

test/interop/daemons/go.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'use strict'
2+
3+
const ctl = require('ipfsd-ctl')
4+
const waterfall = require('async/waterfall')
5+
6+
class GoDaemon {
7+
constructor (opts) {
8+
opts = opts || {
9+
disposable: true,
10+
init: true
11+
}
12+
13+
this.init = opts.init
14+
this.path = opts.path
15+
this.disposable = opts.disposable
16+
this.node = null
17+
this.api = null
18+
}
19+
20+
start (callback) {
21+
waterfall([
22+
(cb) => {
23+
if (this.disposable) {
24+
ctl.disposable({init: this.init}, cb)
25+
} else if (this.init) {
26+
ctl.local(this.path, (err, node) => {
27+
if (err) {
28+
return cb(err)
29+
}
30+
node.init((err) => cb(err, node))
31+
})
32+
} else {
33+
ctl.local(this.path, cb)
34+
}
35+
},
36+
(node, cb) => {
37+
this.node = node
38+
this.node.setConfig('Bootstrap', '[]', cb)
39+
},
40+
(res, cb) => this.node.startDaemon(cb),
41+
(api, cb) => {
42+
this.api = api
43+
44+
if (process.env.DEBUG) {
45+
this.api.log.tail((err, stream) => {
46+
if (err) {
47+
return console.error(err)
48+
}
49+
stream.on('data', (chunk) => {
50+
console.log('go-log: %s.%s %s (%s)', chunk.system, chunk.subsystem || '', chunk.event, chunk.error)
51+
})
52+
})
53+
this.node._run(
54+
['log', 'level', 'all', 'debug'],
55+
{env: this.node.env},
56+
cb
57+
)
58+
} else {
59+
cb()
60+
}
61+
}
62+
], (err) => callback(err))
63+
}
64+
65+
stop (callback) {
66+
this.node.stopDaemon(callback)
67+
}
68+
}
69+
70+
module.exports = GoDaemon

test/interop/daemons/js.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
'use strict'
2+
3+
const os = require('os')
4+
const IPFSAPI = require('ipfs-api')
5+
const series = require('async/series')
6+
const rimraf = require('rimraf')
7+
const IPFSRepo = require('ipfs-repo')
8+
9+
const IPFS = require('../../../src/core')
10+
const HTTPAPI = require('../../../src/http-api')
11+
12+
function setPorts (ipfs, port, callback) {
13+
series([
14+
(cb) => ipfs.config.set(
15+
'Addresses.Gateway',
16+
'/ip4/127.0.0.1/tcp/' + (9090 + port),
17+
cb
18+
),
19+
(cb) => ipfs.config.set(
20+
'Addresses.API',
21+
'/ip4/127.0.0.1/tcp/' + (5002 + port),
22+
cb
23+
),
24+
(cb) => ipfs.config.set(
25+
'Addresses.Swarm',
26+
['/ip4/0.0.0.0/tcp/' + (4002 + port)],
27+
cb
28+
)
29+
], callback)
30+
}
31+
32+
class JsDaemon {
33+
constructor (opts) {
34+
opts = Object.assign({}, {
35+
disposable: true,
36+
init: true
37+
}, opts || {})
38+
39+
this.path = opts.path
40+
this.disposable = opts.disposable
41+
this.init = opts.init
42+
this.port = opts.port
43+
44+
this.path = opts.path || os.tmpdir() + `/${Math.ceil(Math.random() * 1000)}`
45+
if (this.init) {
46+
this.ipfs = new IPFS(this.path)
47+
} else {
48+
const repo = new IPFSRepo(this.path, {stores: require('fs-pull-blob-store')})
49+
this.ipfs = new IPFS(repo)
50+
}
51+
this.node = null
52+
this.api = null
53+
}
54+
55+
start (callback) {
56+
console.log('starting js', this.path)
57+
series([
58+
(cb) => {
59+
if (this.init) {
60+
this.ipfs.init(cb)
61+
} else {
62+
cb()
63+
}
64+
},
65+
(cb) => this.ipfs.config.set('Bootstrap', [], cb),
66+
(cb) => {
67+
if (this.port) {
68+
console.log('setting to port', this.port)
69+
setPorts(this.ipfs, this.port, cb)
70+
} else {
71+
cb()
72+
}
73+
},
74+
(cb) => {
75+
this.node = new HTTPAPI(this.ipfs._repo)
76+
this.node.start(cb)
77+
},
78+
(cb) => {
79+
this.api = new IPFSAPI(this.node.apiMultiaddr)
80+
cb()
81+
}
82+
], (err) => callback(err))
83+
}
84+
85+
stop (callback) {
86+
series([
87+
(cb) => this.node.stop(cb),
88+
(cb) => {
89+
if (this.disposable) {
90+
rimraf(this.path, cb)
91+
} else {
92+
cb()
93+
}
94+
}
95+
], (err) => callback(err))
96+
}
97+
}
98+
99+
module.exports = JsDaemon

0 commit comments

Comments
 (0)