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

chore: async await refactor #562

Merged
merged 45 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2fb718c
chore: bitswap async/await refactor
Nov 20, 2019
14aa336
chore: block async/await refactor
Nov 20, 2019
a22f248
chore: bootstrap async/await refactor
Nov 20, 2019
70f8bc7
chore: config async/await refactor
Nov 20, 2019
fd72f40
chore: dag async/await refactor
Nov 20, 2019
a2c6b12
chore: dht async/await refactor
Nov 20, 2019
8bc5fc9
chore: files-mfs async/await refactor
Nov 20, 2019
2154ebe
chore: files-regular async/await refactor
Nov 20, 2019
7e4eabc
chore: key async/await refactor
Nov 20, 2019
1f810f9
chore: miscellaneous async/await refactor
Nov 20, 2019
7ba7a2d
chore: name-pubsub async/await refactor
Nov 20, 2019
6a4c1bb
chore: name async/await refactor
Nov 20, 2019
3910b68
chore: object async/await refactor
Nov 20, 2019
f8caf5c
chore: pin async/await refactor
Nov 20, 2019
b49666b
chore: ping async/await refactor
Nov 20, 2019
3c9610c
chore: pubsub async/await refactor
Nov 20, 2019
08c455d
chore: repo async/await refactor
Nov 20, 2019
143a2c4
chore: stats async/await refactor
Nov 20, 2019
6d4d5bb
chore: swarm async/await refactor
Nov 20, 2019
abe108d
chore: remove unnecessary util file
Nov 20, 2019
e242e09
chore: update dependencies
Nov 20, 2019
3fd2a8b
refactor: remove async dep and unnecessary utils
Nov 22, 2019
79e4e6b
refactor: bitswap before and after methods to async syntax
Nov 22, 2019
571b35b
refactor: block before and after methods to async syntax
Nov 22, 2019
20e842b
refactor: bootstrap before and after methods to async syntax
Nov 22, 2019
444c6a5
refactor: config before and after methods to async syntax
Nov 22, 2019
ba18c86
refactor: dag before and after methods to async syntax
Nov 22, 2019
bc7dcef
refactor: dht before and after methods to async syntax
Nov 22, 2019
50eabf6
refactor: files-mfs before and after methods to async syntax
Nov 22, 2019
4172720
refactor: files-regular before and after methods to async syntax
Nov 22, 2019
dd446e8
refactor: key before and after methods to async syntax
Nov 22, 2019
1cb16c8
refactor: miscellaneous before and after methods to async syntax
Nov 22, 2019
3f95aab
refactor: name before and after methods to async syntax
Nov 22, 2019
03b5d6f
refactor: name-pubsub before and after methods to async syntax
Nov 22, 2019
187c89e
refactor: object before and after methods to async syntax
Nov 22, 2019
cb07f73
refactor: pin before and after methods to async syntax
Nov 22, 2019
9953c7f
refactor: ping before and after methods to async syntax
Nov 22, 2019
4479df9
refactor: pubsub before and after methods to async syntax
Nov 22, 2019
25a99bf
refactor: repo before and after methods to async syntax
Nov 22, 2019
f00b03d
refactor: stats before and after methods to async syntax
Nov 22, 2019
514ffed
chore: remove 'only' from files-mfs/cp
Nov 22, 2019
a0c1e6a
chore: uncomment bootstrap rm test assertion
Nov 22, 2019
f3a8224
refactor: name resolve test
Nov 22, 2019
2720e57
fix: increase dht findProvs test timeout
Nov 24, 2019
2aaff5e
fix: miscellaneous stop test
Nov 26, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
},
"homepage": "https://github.com/ipfs/interface-ipfs-core#readme",
"dependencies": {
"async": "^2.6.2",
"bl": "^3.0.0",
"bs58": "^4.0.1",
"callbackify": "^1.1.0",
Expand All @@ -47,6 +46,7 @@
"delay": "^4.3.0",
"dirty-chai": "^2.0.1",
"es6-promisify": "^6.0.1",
"get-stream": "^5.1.0",
"hat": "0.0.3",
"ipfs-block": "~0.8.0",
"ipfs-unixfs": "~0.1.16",
Expand All @@ -61,9 +61,15 @@
"multibase": "~0.6.0",
"multihashes": "~0.4.14",
"multihashing-async": "~0.6.0",
"peer-id": "~0.12.0",
"p-each-series": "^2.1.0",
"p-map-series": "^2.1.0",
"p-timeout": "^3.2.0",
"p-times": "^2.1.0",
"p-whilst": "^2.1.0",
"peer-id": "~0.13.5",
"peer-info": "~0.15.0",
"pull-stream": "^3.6.11",
"pull-to-promise": "^1.0.1",
"pump": "^3.0.0",
"readable-stream": "^3.1.1",
"streaming-iterables": "^4.1.0",
Expand Down
52 changes: 12 additions & 40 deletions src/bitswap/stat.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env mocha */
'use strict'

const waterfall = require('async/waterfall')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { expectIsBitswap } = require('../stats/utils')

Expand All @@ -10,53 +9,26 @@ module.exports = (createCommon, options) => {
const it = getIt(options)
const common = createCommon()

describe('.bitswap.stat', () => {
describe('.bitswap.stat', function () {
this.timeout(60 * 1000)
let ipfs

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
done()
})
})
before(async () => {
ipfs = await common.setup()
})

after((done) => common.teardown(done))
after(() => common.teardown())

it('should get bitswap stats', (done) => {
ipfs.bitswap.stat((err, res) => {
expectIsBitswap(err, res)
done()
})
it('should get bitswap stats', async () => {
const res = await ipfs.bitswap.stat()
expectIsBitswap(null, res)
})

it('should get bitswap stats (promised)', () => {
return ipfs.bitswap.stat().then((res) => {
expectIsBitswap(null, res)
})
})
it('should not get bitswap stats when offline', async () => {
const node = await createCommon().setup()
await node.stop()

it('should not get bitswap stats when offline', function (done) {
this.timeout(60 * 1000)

waterfall([
(cb) => createCommon().setup(cb),
(factory, cb) => factory.spawnNode(cb),
(node, cb) => node.stop((err) => cb(err, node))
], (err, node) => {
expect(err).to.not.exist()
node.bitswap.wantlist((err) => {
expect(err).to.exist()
done()
})
})
return expect(node.bitswap.stat()).to.eventually.be.rejected()
})
})
}
35 changes: 12 additions & 23 deletions src/bitswap/utils.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
'use strict'

const until = require('async/until')
const pWhilst = require('p-whilst')

function waitForWantlistKey (ipfs, key, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = {}
}

opts = opts || {}
opts.timeout = opts.timeout || 1000
function waitForWantlistKey (ipfs, key, opts = {}) {
opts.timeout = opts.timeout || 10000

let list = { Keys: [] }
let timedOut = false

setTimeout(() => { timedOut = true }, opts.timeout)
const start = Date.now()
const findKey = () => !list.Keys.some(k => k['/'] === key)

const iteratee = async () => {
if (Date.now() - start > opts.timeout) {
throw new Error(`Timed out waiting for ${key} in wantlist`)
}

const test = () => timedOut ? true : list.Keys.some(k => k['/'] === key)
const iteratee = (cb) => {
ipfs.bitswap.wantlist(opts.peerId, (err, nextList) => {
if (err) return cb(err)
list = nextList
cb()
})
list = await ipfs.bitswap.wantlist(opts.peerId)
}

until(test, iteratee, (err) => {
if (err) return cb(err)
if (timedOut) return cb(new Error(`Timed out waiting for ${key} in wantlist`))
cb()
})
return pWhilst(findKey, iteratee)
}

module.exports.waitForWantlistKey = waitForWantlistKey
63 changes: 17 additions & 46 deletions src/bitswap/wantlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,45 @@
/* eslint max-nested-callbacks: ["error", 6] */
'use strict'

const waterfall = require('async/waterfall')
const { spawnNodesWithId } = require('../utils/spawn')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { waitForWantlistKey } = require('./utils')
const { connect } = require('../utils/swarm')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

describe('.bitswap.wantlist', () => {
describe('.bitswap.wantlist', function () {
this.timeout(60 * 1000)
let ipfsA
let ipfsB
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)
before(async () => {
ipfsA = await common.setup()
ipfsB = await common.setup()

common.setup((err, factory) => {
expect(err).to.not.exist()
// Add key to the wantlist for ipfsB
ipfsB.block.get(key, () => {})

spawnNodesWithId(2, factory, (err, nodes) => {
expect(err).to.not.exist()

ipfsA = nodes[0]
ipfsB = nodes[1]

// Add key to the wantlist for ipfsB
ipfsB.block.get(key, () => {})

connect(ipfsA, ipfsB.peerId.addresses[0], done)
})
})
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
})

after(function (done) {
this.timeout(30 * 1000)
common.teardown(done)
})
after(() => common.teardown())

it('should get the wantlist', (done) => {
waitForWantlistKey(ipfsB, key, done)
it('should get the wantlist', () => {
return waitForWantlistKey(ipfsB, key)
})

it('should get the wantlist by peer ID for a diffreent node', (done) => {
ipfsB.id((err, info) => {
expect(err).to.not.exist()
waitForWantlistKey(ipfsA, key, { peerId: info.id }, done)
})
it('should get the wantlist by peer ID for a diffreent node', () => {
return waitForWantlistKey(ipfsA, key, { peerId: ipfsB.peerId.id })
})

it('should not get the wantlist when offline', function (done) {
this.timeout(60 * 1000)
it('should not get the wantlist when offline', async () => {
const node = await createCommon().setup()
await node.stop()

waterfall([
(cb) => createCommon().setup(cb),
(factory, cb) => factory.spawnNode(cb),
(node, cb) => node.stop((err) => cb(err, node))
], (err, node) => {
expect(err).to.not.exist()
node.bitswap.wantlist((err) => {
expect(err).to.exist()
done()
})
})
return expect(node.bitswap.stat()).to.eventually.be.rejected()
})
})
}
Loading