Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 22d1ab5

Browse files
Pedro Santosachingbrain
Pedro Santos
authored andcommitted
chore: add tests timeouts as they were previously (#564)
* chore: add tests timeouts as they were previously * chore: code review changes * chore: downgrade peer-id dep * fix: promisify callback method * fix: use proper promisify export * chore: control peer id/info versions * chore: increase timeout for bitswap tests * fix: remove .only * fix: swap arrow for function * fix: remove the setup of extra nodes We previously set this node up and attempted to dial it without a relay node being present which failed and we accidentally-on-purpose ignored the error by resolving a promise with an error instead of rejecting it. The test does not assert anything to do with the other node, and the `allowOffline` option should allow us to publish IPNS names without having any peers so the other node is redundant and can be removed. * fix: increase timeout for want list wait * fix: simpler wait for want list * fix: await delay * chore: guard on list.Keys being set * fix: start the other node for go-ipfs only
1 parent 691d0b6 commit 22d1ab5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+657
-218
lines changed

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@
6565
"p-map-series": "^2.1.0",
6666
"p-timeout": "^3.2.0",
6767
"p-times": "^2.1.0",
68-
"p-whilst": "^2.1.0",
69-
"peer-id": "~0.13.5",
70-
"peer-info": "~0.15.0",
68+
"peer-id": "~0.12.2",
69+
"peer-info": "~0.15.1",
7170
"pull-stream": "^3.6.11",
7271
"pull-to-promise": "^1.0.1",
7372
"pump": "^3.0.0",

src/bitswap/stat.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ module.exports = (createCommon, options) => {
99
const it = getIt(options)
1010
const common = createCommon()
1111

12-
describe('.bitswap.stat', function () {
13-
this.timeout(60 * 1000)
12+
describe('.bitswap.stat', () => {
1413
let ipfs
1514

16-
before(async () => {
15+
before(async function () {
16+
// CI takes longer to instantiate the daemon, so we need to increase the
17+
// timeout for the before step
18+
this.timeout(60 * 1000)
19+
1720
ipfs = await common.setup()
1821
})
1922

@@ -24,7 +27,9 @@ module.exports = (createCommon, options) => {
2427
expectIsBitswap(null, res)
2528
})
2629

27-
it('should not get bitswap stats when offline', async () => {
30+
it('should not get bitswap stats when offline', async function () {
31+
this.timeout(60 * 1000)
32+
2833
const node = await createCommon().setup()
2934
await node.stop()
3035

src/bitswap/utils.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
'use strict'
22

3-
const pWhilst = require('p-whilst')
3+
const delay = require('delay')
44

5-
function waitForWantlistKey (ipfs, key, opts = {}) {
5+
async function waitForWantlistKey (ipfs, key, opts = {}) {
66
opts.timeout = opts.timeout || 10000
7+
const end = Date.now() + opts.timeout
78

8-
let list = { Keys: [] }
9+
while (Date.now() < end) {
10+
const list = await ipfs.bitswap.wantlist(opts.peerId)
911

10-
const start = Date.now()
11-
const findKey = () => !list.Keys.some(k => k['/'] === key)
12-
13-
const iteratee = async () => {
14-
if (Date.now() - start > opts.timeout) {
15-
throw new Error(`Timed out waiting for ${key} in wantlist`)
12+
if (list && list.Keys && list.Keys.some(k => k['/'] === key)) {
13+
return
1614
}
1715

18-
list = await ipfs.bitswap.wantlist(opts.peerId)
16+
await delay(500)
1917
}
2018

21-
return pWhilst(findKey, iteratee)
19+
throw new Error(`Timed out waiting for ${key} in wantlist`)
2220
}
2321

2422
module.exports.waitForWantlistKey = waitForWantlistKey

src/bitswap/wantlist.js

+24-10
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,51 @@ module.exports = (createCommon, options) => {
99
const it = getIt(options)
1010
const common = createCommon()
1111

12-
describe('.bitswap.wantlist', function () {
13-
this.timeout(60 * 1000)
12+
describe('.bitswap.wantlist', () => {
1413
let ipfsA
1514
let ipfsB
1615
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
1716

18-
before(async () => {
17+
before(async function () {
18+
// CI takes longer to instantiate the daemon, so we need to increase the
19+
// timeout for the before step
20+
this.timeout(60 * 1000)
21+
1922
ipfsA = await common.setup()
2023
ipfsB = await common.setup()
2124

2225
// Add key to the wantlist for ipfsB
23-
ipfsB.block.get(key, () => {})
26+
ipfsB.block.get(key).catch(() => {})
2427

2528
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
2629
})
2730

28-
after(() => common.teardown())
31+
after(function () {
32+
this.timeout(30 * 1000)
33+
34+
return common.teardown()
35+
})
2936

30-
it('should get the wantlist', () => {
37+
it('should get the wantlist', function () {
38+
this.timeout(60 * 1000)
3139
return waitForWantlistKey(ipfsB, key)
3240
})
3341

34-
it('should get the wantlist by peer ID for a diffreent node', () => {
35-
return waitForWantlistKey(ipfsA, key, { peerId: ipfsB.peerId.id })
42+
it('should get the wantlist by peer ID for a different node', function () {
43+
this.timeout(60 * 1000)
44+
return waitForWantlistKey(ipfsA, key, {
45+
peerId: ipfsB.peerId.id,
46+
timeout: 60 * 1000
47+
})
3648
})
3749

38-
it('should not get the wantlist when offline', async () => {
50+
it('should not get the wantlist when offline', async function () {
51+
this.timeout(60 * 1000)
52+
3953
const node = await createCommon().setup()
4054
await node.stop()
4155

42-
return expect(node.bitswap.stat()).to.eventually.be.rejected()
56+
return expect(node.bitswap.wantlist()).to.eventually.be.rejected()
4357
})
4458
})
4559
}

src/block/get.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ module.exports = (createCommon, options) => {
1010
const it = getIt(options)
1111
const common = createCommon()
1212

13-
describe('.block.get', function () {
14-
this.timeout(60 * 1000)
13+
describe('.block.get', () => {
1514
const data = Buffer.from('blorb')
1615
let ipfs, hash
1716

18-
before(async () => {
17+
before(async function () {
18+
// CI takes longer to instantiate the daemon, so we need to increase the
19+
// timeout for the before step
20+
this.timeout(60 * 1000)
21+
1922
ipfs = await common.setup()
2023
const block = await ipfs.block.put(data)
2124
hash = block.cid.multihash

src/block/put.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ module.exports = (createCommon, options) => {
1111
const it = getIt(options)
1212
const common = createCommon()
1313

14-
describe('.block.put', function () {
15-
this.timeout(60 * 1000)
14+
describe('.block.put', () => {
1615
let ipfs
1716

18-
before(async () => {
17+
before(async function () {
18+
// CI takes longer to instantiate the daemon, so we need to increase the
19+
// timeout for the before step
20+
this.timeout(60 * 1000)
21+
1922
ipfs = await common.setup()
2023
})
2124

src/block/rm.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ module.exports = (createCommon, options) => {
99
const it = getIt(options)
1010
const common = createCommon()
1111

12-
describe('.block.rm', function () {
13-
this.timeout(60 * 1000)
12+
describe('.block.rm', () => {
1413
let ipfs
1514

16-
before(async () => {
15+
before(async function () {
16+
// CI takes longer to instantiate the daemon, so we need to increase the
17+
// timeout for the before step
18+
this.timeout(60 * 1000)
19+
1720
ipfs = await common.setup()
1821
})
1922

src/block/stat.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ module.exports = (createCommon, options) => {
99
const it = getIt(options)
1010
const common = createCommon()
1111

12-
describe('.block.stat', function () {
13-
this.timeout(60 * 1000)
12+
describe('.block.stat', () => {
1413
const data = Buffer.from('blorb')
1514
let ipfs, hash
1615

17-
before(async () => {
16+
before(async function () {
17+
// CI takes longer to instantiate the daemon, so we need to increase the
18+
// timeout for the before step
19+
this.timeout(60 * 1000)
20+
1821
ipfs = await common.setup()
1922
const block = await ipfs.block.put(data)
2023
hash = block.cid.multihash

src/bootstrap/add.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ module.exports = (createCommon, options) => {
1616

1717
let ipfs
1818

19-
before(async () => {
19+
before(async function () {
20+
// CI takes longer to instantiate the daemon, so we need to increase the
21+
// timeout for the before step
22+
this.timeout(60 * 1000)
23+
2024
ipfs = await common.setup()
2125
})
2226

src/bootstrap/list.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ module.exports = (createCommon, options) => {
1313

1414
let ipfs
1515

16-
before(async () => {
16+
before(async function () {
17+
// CI takes longer to instantiate the daemon, so we need to increase the
18+
// timeout for the before step
19+
this.timeout(60 * 1000)
20+
1721
ipfs = await common.setup()
1822
})
1923

src/bootstrap/rm.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ module.exports = (createCommon, options) => {
1616

1717
let ipfs
1818

19-
before(async () => {
19+
before(async function () {
20+
// CI takes longer to instantiate the daemon, so we need to increase the
21+
// timeout for the before step
22+
this.timeout(60 * 1000)
23+
2024
ipfs = await common.setup()
2125
})
2226

src/config/get.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ module.exports = (createCommon, options) => {
1010
const common = createCommon()
1111

1212
describe('.config.get', function () {
13-
this.timeout(60 * 1000)
13+
this.timeout(30 * 1000)
1414
let ipfs
1515

16-
before(async () => {
16+
before(async function () {
17+
// CI takes longer to instantiate the daemon, so we need to increase the
18+
// timeout for the before step
19+
this.timeout(60 * 1000)
20+
1721
ipfs = await common.setup()
1822
})
1923

src/config/profiles/apply.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ module.exports = (createCommon, options) => {
1212
this.timeout(30 * 1000)
1313
let ipfs
1414

15-
before(async () => {
15+
before(async function () {
16+
// CI takes longer to instantiate the daemon, so we need to increase the
17+
// timeout for the before step
18+
this.timeout(60 * 1000)
19+
1620
ipfs = await common.setup()
1721
})
1822

src/config/profiles/list.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ module.exports = (createCommon, options) => {
99
const common = createCommon()
1010

1111
describe('.config.profiles.list', function () {
12-
this.timeout(60 * 1000)
12+
this.timeout(30 * 1000)
1313
let ipfs
1414

15-
before(async () => {
15+
before(async function () {
16+
// CI takes longer to instantiate the daemon, so we need to increase the
17+
// timeout for the before step
18+
this.timeout(60 * 1000)
19+
1620
ipfs = await common.setup()
1721
})
1822

src/config/replace.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ module.exports = (createCommon, options) => {
99
const common = createCommon()
1010

1111
describe('.config.replace', function () {
12-
this.timeout(60 * 1000)
12+
this.timeout(30 * 1000)
1313
let ipfs
1414

15-
before(async () => {
15+
before(async function () {
16+
// CI takes longer to instantiate the daemon, so we need to increase the
17+
// timeout for the before step
18+
this.timeout(60 * 1000)
19+
1620
ipfs = await common.setup()
1721
})
1822

src/config/set.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ module.exports = (createCommon, options) => {
99
const common = createCommon()
1010

1111
describe('.config.set', function () {
12-
this.timeout(60 * 1000)
12+
this.timeout(30 * 1000)
1313
let ipfs
1414

15-
before(async () => {
15+
before(async function () {
16+
// CI takes longer to instantiate the daemon, so we need to increase the
17+
// timeout for the before step
18+
this.timeout(60 * 1000)
19+
1620
ipfs = await common.setup()
1721
})
1822

src/dag/get.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ module.exports = (createCommon, options) => {
1414
const it = getIt(options)
1515
const common = createCommon()
1616

17-
describe('.dag.get', function () {
18-
this.timeout(60 * 1000)
17+
describe('.dag.get', () => {
1918
let ipfs
2019

21-
before(async () => { ipfs = await common.setup() })
20+
before(async function () {
21+
// CI takes longer to instantiate the daemon, so we need to increase the
22+
// timeout for the before step
23+
this.timeout(60 * 1000)
24+
25+
ipfs = await common.setup()
26+
})
2227

2328
after(() => common.teardown())
2429

src/dag/put.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ module.exports = (createCommon, options) => {
1313
const it = getIt(options)
1414
const common = createCommon()
1515

16-
describe('.dag.put', function () {
17-
this.timeout(60 * 1000)
16+
describe('.dag.put', () => {
1817
let ipfs
1918

20-
before(async () => { ipfs = await common.setup() })
19+
before(async function () {
20+
// CI takes longer to instantiate the daemon, so we need to increase the
21+
// timeout for the before step
22+
this.timeout(60 * 1000)
23+
24+
ipfs = await common.setup()
25+
})
2126

2227
after(() => common.teardown())
2328

src/dag/tree.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ module.exports = (createCommon, options) => {
1212
const it = getIt(options)
1313
const common = createCommon()
1414

15-
describe('.dag.tree', function () {
16-
this.timeout(60 * 1000)
15+
describe('.dag.tree', () => {
1716
let ipfs
1817

19-
before(async () => { ipfs = await common.setup() })
18+
before(async function () {
19+
// CI takes longer to instantiate the daemon, so we need to increase the
20+
// timeout for the before step
21+
this.timeout(60 * 1000)
22+
23+
ipfs = await common.setup()
24+
})
2025

2126
after(() => common.teardown())
2227

0 commit comments

Comments
 (0)