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

Commit db703b9

Browse files
authored
chore: more test stabilization (#1541)
* chore: increase preload test timeouts Also reduces the umber of bits for the Peer ID generated in bitswap CLI tests. License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * feat: adds waitFor utility Calls back when async func returns true. License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * fix: appease the linter License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * fix: appease linter more License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: increase pin after hook timeout License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: increase default test timeout to 10s License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: cleanup temp repos after tests License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: remove .only License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: appease linter License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: ten seconds is the new default timeout License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * fix: repo in test License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
1 parent bf72f3a commit db703b9

File tree

15 files changed

+192
-85
lines changed

15 files changed

+192
-85
lines changed

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
"scripts": {
2626
"lint": "aegir lint",
2727
"build": "aegir build",
28-
"test": "aegir test -t node -t browser -t webworker --no-cors",
29-
"test:node": "aegir test -t node",
30-
"test:browser": "aegir test -t browser --no-cors",
31-
"test:webworker": "aegir test -t webworker --no-cors",
32-
"test:node:core": "aegir test -t node -f test/core/**/*.js",
33-
"test:node:http": "aegir test -t node -f test/http-api/index.js",
34-
"test:node:gateway": "aegir test -t node -f test/gateway/index.js",
35-
"test:node:cli": "aegir test -t node -f test/cli/index.js",
36-
"test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js",
28+
"test": "aegir test -t node -t browser -t webworker --no-cors --timeout=10000",
29+
"test:node": "aegir test -t node --timeout=10000",
30+
"test:browser": "aegir test -t browser --no-cors --timeout=10000",
31+
"test:webworker": "aegir test -t webworker --no-cors --timeout=10000",
32+
"test:node:core": "aegir test -t node -f test/core/**/*.js --timeout=10000",
33+
"test:node:http": "aegir test -t node -f test/http-api/index.js --timeout=10000",
34+
"test:node:gateway": "aegir test -t node -f test/gateway/index.js --timeout=10000",
35+
"test:node:cli": "aegir test -t node -f test/cli/index.js --timeout=10000",
36+
"test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js --timeout=10000",
3737
"benchmark": "echo \"Error: no benchmarks yet\" && exit 1",
3838
"benchmark:node": "echo \"Error: no benchmarks yet\" && exit 1",
3939
"benchmark:node:core": "echo \"Error: no benchmarks yet\" && exit 1",

test/bootstrapers.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,54 @@ const dirtyChai = require('dirty-chai')
66
const expect = chai.expect
77
chai.use(dirtyChai)
88
const IPFS = require('..')
9-
const list = require('../src/core/runtime/config-browser.js')().Bootstrap
9+
const IPFSFactory = require('ipfsd-ctl')
10+
const bootstrapList = require('../src/core/runtime/config-browser.js')().Bootstrap
11+
const waitFor = require('./utils/wait-for')
1012

1113
/*
1214
* These tests were graciously made for lgierth, so that he can test the
1315
* WebSockets Bootstrappers easily <3
1416
*/
15-
describe('Check that a js-ipfs node can indeed contact the bootstrappers', function () {
16-
this.timeout(60 * 1000)
17+
describe('Check that a js-ipfs node can indeed contact the bootstrappers', () => {
18+
let ipfsd
1719

18-
it('a node connects to bootstrapers', (done) => {
19-
const node = new IPFS({
20+
before(function (done) {
21+
this.timeout(30 * 1000)
22+
23+
const factory = IPFSFactory.create({ type: 'proc', exec: IPFS })
24+
25+
factory.spawn({
2026
config: {
2127
Addresses: {
2228
Swarm: []
2329
}
2430
}
31+
}, (err, node) => {
32+
expect(err).to.not.exist()
33+
ipfsd = node
34+
done()
2535
})
36+
})
2637

27-
node.on('ready', check)
38+
after(done => ipfsd.stop(done))
2839

29-
function check () {
30-
node.swarm.peers((err, peers) => {
31-
expect(err).to.not.exist()
40+
it('a node connects to bootstrappers', function (done) {
41+
this.timeout(2 * 60 * 1000)
3242

33-
if (peers.length !== list.length) {
34-
return setTimeout(check, 2000)
35-
}
43+
const test = (cb) => {
44+
ipfsd.api.swarm.peers((err, peers) => {
45+
if (err) return cb(err)
3646

3747
const peerList = peers.map((peer) => peer.addr.toString())
38-
expect(peers.length).to.equal(list.length)
39-
expect(peerList).to.eql(list)
4048

41-
node.stop(done)
49+
if (peerList.length !== bootstrapList.length) {
50+
return cb(null, false)
51+
}
52+
53+
cb(null, bootstrapList.every(addr => peerList.includes(addr)))
4254
})
4355
}
56+
57+
waitFor(test, { name: 'connect to all bootstrap nodes', timeout: 60 * 1000 }, done)
4458
})
4559
})

test/cli/bitswap.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,46 @@
44
const expect = require('chai').expect
55
const runOn = require('../utils/on-and-off').on
66
const PeerId = require('peer-id')
7+
const waitFor = require('../utils/wait-for')
78

89
describe('bitswap', () => runOn((thing) => {
910
let ipfs
1011
let peerId
1112
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
1213

14+
before(() => {
15+
ipfs = thing.ipfs
16+
})
17+
18+
before(() => {
19+
ipfs('block get ' + key).catch(() => {})
20+
})
21+
1322
before(function (done) {
1423
this.timeout(60 * 1000)
15-
ipfs = thing.ipfs
16-
ipfs('block get ' + key)
17-
.then(() => {})
18-
.catch(() => {})
19-
PeerId.create((err, peer) => {
24+
25+
PeerId.create({ bits: 512 }, (err, peer) => {
2026
expect(err).to.not.exist()
2127
peerId = peer.toB58String()
2228
done()
2329
})
2430
})
2531

32+
before(function (done) {
33+
this.timeout(2 * 60 * 1000)
34+
35+
const test = (cb) => {
36+
ipfs('bitswap wantlist')
37+
.then(out => cb(null, out.includes(key)))
38+
.catch(cb)
39+
}
40+
41+
waitFor(test, {
42+
name: key + ' to be wanted',
43+
timeout: 60 * 1000
44+
}, done)
45+
})
46+
2647
it('wantlist', function () {
2748
this.timeout(20 * 1000)
2849
return ipfs('bitswap wantlist').then((out) => {

test/cli/pin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ describe('pin', () => runOnAndOff(thing => {
2828
})
2929

3030
describe('rm', function () {
31-
it('recursively (default)', function () {
32-
this.timeout(10 * 1000)
31+
it('recursively (default)', () => {
3332
return ipfs(`pin rm ${pins.root}`)
3433
.then(out => expect(out).to.equal(`unpinned ${pins.root}\n`))
3534
})

test/cli/resolve.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ describe('resolve', () => runOnAndOff((thing) => {
1414
ipfs = thing.ipfs
1515
})
1616

17-
it('should resolve an IPFS hash', function () {
18-
this.timeout(10 * 1000)
19-
17+
it('should resolve an IPFS hash', () => {
2018
const filePath = path.join(process.cwd(), '/src/init-files/init-docs/readme')
2119
let hash
2220

@@ -31,9 +29,7 @@ describe('resolve', () => runOnAndOff((thing) => {
3129
})
3230
})
3331

34-
it('should resolve an IPFS path link', function () {
35-
this.timeout(10 * 1000)
36-
32+
it('should resolve an IPFS path link', () => {
3733
const filePath = path.join(process.cwd(), '/src/init-files/init-docs/readme')
3834
let fileHash, rootHash
3935

test/core/create-node.spec.js

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ const IPFS = require('../../src/core')
2020
const createTempRepo = require('../utils/create-repo-nodejs.js')
2121

2222
describe('create node', function () {
23+
let tempRepo
24+
25+
beforeEach(() => {
26+
tempRepo = createTempRepo()
27+
})
28+
29+
afterEach((done) => tempRepo.teardown(done))
30+
2331
it('custom repoPath', function (done) {
2432
this.timeout(80 * 1000)
2533

@@ -49,7 +57,7 @@ describe('create node', function () {
4957
this.timeout(80 * 1000)
5058

5159
const node = new IPFS({
52-
repo: createTempRepo(),
60+
repo: tempRepo,
5361
config: {
5462
Addresses: {
5563
Swarm: []
@@ -73,7 +81,7 @@ describe('create node', function () {
7381
this.timeout(80 * 1000)
7482

7583
const node = IPFS.createNode({
76-
repo: createTempRepo(),
84+
repo: tempRepo,
7785
config: {
7886
Addresses: {
7987
Swarm: []
@@ -100,7 +108,7 @@ describe('create node', function () {
100108
this.timeout(80 * 1000)
101109

102110
const node = new IPFS({
103-
repo: createTempRepo(),
111+
repo: tempRepo,
104112
init: {
105113
bits: 512
106114
},
@@ -127,7 +135,7 @@ describe('create node', function () {
127135
this.timeout(80 * 1000)
128136

129137
const node = new IPFS({
130-
repo: createTempRepo(),
138+
repo: tempRepo,
131139
init: false,
132140
config: {
133141
Addresses: {
@@ -159,7 +167,7 @@ describe('create node', function () {
159167
this.timeout(80 * 1000)
160168

161169
const node = new IPFS({
162-
repo: createTempRepo(),
170+
repo: tempRepo,
163171
init: false,
164172
start: false,
165173
config: {
@@ -189,7 +197,7 @@ describe('create node', function () {
189197
this.timeout(80 * 1000)
190198

191199
const node = new IPFS({
192-
repo: createTempRepo(),
200+
repo: tempRepo,
193201
init: true,
194202
start: false,
195203
config: {
@@ -211,7 +219,7 @@ describe('create node', function () {
211219
this.timeout(80 * 1000)
212220

213221
const node = new IPFS({
214-
repo: createTempRepo(),
222+
repo: tempRepo,
215223
init: true,
216224
start: false,
217225
config: {
@@ -232,7 +240,7 @@ describe('create node', function () {
232240
if (!isNode) { return done() }
233241

234242
const node = new IPFS({
235-
repo: createTempRepo(),
243+
repo: tempRepo,
236244
config: {
237245
Addresses: {
238246
Swarm: ['/ip4/127.0.0.1/tcp/9977']
@@ -258,7 +266,7 @@ describe('create node', function () {
258266
this.timeout(80 * 1000)
259267

260268
const node = new IPFS({
261-
repo: createTempRepo(),
269+
repo: tempRepo,
262270
config: {
263271
Addresses: {
264272
Swarm: []
@@ -279,7 +287,7 @@ describe('create node', function () {
279287
this.timeout(80 * 1000)
280288

281289
const node = new IPFS({
282-
repo: createTempRepo(),
290+
repo: tempRepo,
283291
config: {
284292
Addresses: {
285293
Swarm: []
@@ -299,7 +307,7 @@ describe('create node', function () {
299307
this.timeout(80 * 1000)
300308

301309
const options = {
302-
repo: createTempRepo(),
310+
repo: tempRepo,
303311
config: {
304312
Addresses: {
305313
Swarm: []
@@ -323,13 +331,13 @@ describe('create node', function () {
323331
})
324332

325333
it('does not share identity with a simultaneously created node', function (done) {
326-
this.timeout(80 * 1000)
334+
this.timeout(2 * 60 * 1000)
327335

328336
let _nodeNumber = 0
329-
function createNode () {
337+
function createNode (repo) {
330338
_nodeNumber++
331339
return new IPFS({
332-
repo: createTempRepo(),
340+
repo,
333341
init: { emptyRepo: true },
334342
config: {
335343
Addresses: {
@@ -344,10 +352,19 @@ describe('create node', function () {
344352
})
345353
}
346354

347-
const nodeA = createNode()
348-
const nodeB = createNode()
355+
let repoA
356+
let repoB
357+
let nodeA
358+
let nodeB
349359

350360
waterfall([
361+
(cb) => {
362+
repoA = createTempRepo()
363+
repoB = createTempRepo()
364+
nodeA = createNode(repoA)
365+
nodeB = createNode(repoB)
366+
cb()
367+
},
351368
(cb) => parallel([
352369
(cb) => nodeA.once('start', cb),
353370
(cb) => nodeB.once('start', cb)
@@ -364,7 +381,14 @@ describe('create node', function () {
364381
parallel([
365382
(cb) => nodeA.stop(cb),
366383
(cb) => nodeB.stop(cb)
367-
], (stopError) => done(error || stopError))
384+
], (stopError) => {
385+
parallel([
386+
(cb) => repoA.teardown(cb),
387+
(cb) => repoB.teardown(cb)
388+
], (teardownError) => {
389+
done(error || stopError || teardownError)
390+
})
391+
})
368392
})
369393
})
370394
})

test/core/init.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ describe('init', () => {
7575
})
7676
})
7777

78-
it('pregenerated key is being used', function (done) {
79-
this.timeout(10 * 1000)
80-
78+
it('pregenerated key is being used', (done) => {
8179
ipfs.init({ privateKey }, (err) => {
8280
expect(err).to.not.exist()
8381

test/core/kad-dht.node.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ describe.skip('verify that kad-dht is doing its thing', () => {
7272

7373
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
7474

75-
it.skip('add a file in C, fetch through B in A', function (done) {
76-
this.timeout(10 * 1000)
77-
75+
it.skip('add a file in C, fetch through B in A', (done) => {
7876
const file = {
7977
path: 'testfile.txt',
8078
content: Buffer.from('hello kad')

test/core/key-exchange.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ describe('key exchange', () => {
3030

3131
after((done) => ipfs.stop(done))
3232

33+
after((done) => repo.teardown(done))
34+
3335
it('exports', (done) => {
3436
ipfs.key.export('self', passwordPem, (err, pem) => {
3537
expect(err).to.not.exist()

test/core/pin-set.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ describe('pinSet', function () {
6767
ipfs.stop(done)
6868
})
6969

70+
after((done) => repo.teardown(done))
71+
7072
describe('storeItems', function () {
7173
it('generates a root node with links and hash', function (done) {
7274
const expectedRootHash = 'QmcLiSTjcjoVC2iuGbk6A2PVcWV3WvjZT4jxfNis1vjyrR'

0 commit comments

Comments
 (0)