This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: convert tests to async/await (#562)
* chore: bitswap async/await refactor * chore: block async/await refactor * chore: bootstrap async/await refactor * chore: config async/await refactor * chore: dag async/await refactor * chore: dht async/await refactor * chore: files-mfs async/await refactor * chore: files-regular async/await refactor * chore: key async/await refactor * chore: miscellaneous async/await refactor * chore: name-pubsub async/await refactor * chore: name async/await refactor * chore: object async/await refactor * chore: pin async/await refactor * chore: ping async/await refactor * chore: pubsub async/await refactor * chore: repo async/await refactor * chore: stats async/await refactor * chore: swarm async/await refactor * chore: remove unnecessary util file * chore: update dependencies * refactor: remove async dep and unnecessary utils * refactor: bitswap before and after methods to async syntax * refactor: block before and after methods to async syntax * refactor: bootstrap before and after methods to async syntax * refactor: config before and after methods to async syntax * refactor: dag before and after methods to async syntax * refactor: dht before and after methods to async syntax * refactor: files-mfs before and after methods to async syntax * refactor: files-regular before and after methods to async syntax * refactor: key before and after methods to async syntax * refactor: miscellaneous before and after methods to async syntax * refactor: name before and after methods to async syntax * refactor: name-pubsub before and after methods to async syntax * refactor: object before and after methods to async syntax * refactor: pin before and after methods to async syntax * refactor: ping before and after methods to async syntax * refactor: pubsub before and after methods to async syntax * refactor: repo before and after methods to async syntax * refactor: stats before and after methods to async syntax * chore: remove 'only' from files-mfs/cp * chore: uncomment bootstrap rm test assertion The assertion was commented out temporarly due to bootstrap.rm bug that was fixed here ipfs/js-ipfs#2626 * refactor: name resolve test * fix: increase dht findProvs test timeout * fix: miscellaneous stop test
- Loading branch information
Pedro Santos
authored and
Alan Shaw
committed
Nov 26, 2019
1 parent
c766dbf
commit 2ede15d
Showing
115 changed files
with
2,627 additions
and
5,943 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.