This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
refactor: async #10
Merged
Merged
refactor: async #10
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,8 @@ | ||
dist | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
**/node_modules/ | ||
**/*.log | ||
package-lock.json | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
docs | ||
dist |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
language: node_js | ||
cache: npm | ||
stages: | ||
- check | ||
- test | ||
- cov | ||
|
||
node_js: | ||
- '10' | ||
- '12' | ||
|
||
os: | ||
- linux | ||
- osx | ||
- windows | ||
|
||
script: npx nyc -s npm run test:node -- --bail | ||
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov | ||
|
||
jobs: | ||
include: | ||
- stage: check | ||
script: | ||
- npx aegir dep-check | ||
- npm run lint | ||
|
||
- stage: test | ||
name: chrome | ||
addons: | ||
chrome: stable | ||
script: npx aegir test -t browser -t webworker | ||
|
||
- stage: test | ||
name: firefox | ||
addons: | ||
firefox: latest | ||
script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless | ||
|
||
notifications: | ||
email: false |
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 |
---|---|---|
|
@@ -5,22 +5,29 @@ | |
"leadMaintainer": "Vasco Santos <[email protected]>", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"lint": "aegir-lint", | ||
"build": "aegir-build", | ||
"test": "exit 0", | ||
"release": "aegir-release", | ||
"release-minor": "aegir-release --type minor", | ||
"release-major": "aegir-release --type major" | ||
"lint": "aegir lint", | ||
"build": "aegir build", | ||
"test": "aegir test", | ||
"test:node": "aegir test -t node", | ||
"test:browser": "aegir test -t browser -t webworker", | ||
"release": "aegir release", | ||
"release-minor": "aegir release --type minor", | ||
"release-major": "aegir release --type major" | ||
}, | ||
"pre-commit": [ | ||
"lint", | ||
"test" | ||
"pre-push": [ | ||
"lint" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/libp2p/interface-peer-discovery.git" | ||
}, | ||
"keywords": [ | ||
"libp2p", | ||
"network", | ||
"p2p", | ||
"peer", | ||
"discovery", | ||
"peer-to-peer", | ||
"IPFS" | ||
], | ||
"author": "David Dias <[email protected]>", | ||
|
@@ -31,13 +38,17 @@ | |
"homepage": "https://github.com/libp2p/interface-peer-discovery", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"aegir": "^18.2.2" | ||
"aegir": "^20.3.1", | ||
"chai": "^4.2.0", | ||
"dirty-chai": "^2.0.1", | ||
"peer-id": "^0.13.3", | ||
"peer-info": "^0.17.0" | ||
}, | ||
"engines": { | ||
"node": ">=4.0.0", | ||
"npm": ">=3.0.0" | ||
"node": ">=10.0.0", | ||
"npm": ">=6.0.0" | ||
}, | ||
"contributors": [ | ||
"David Dias <[email protected]>" | ||
] | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
module.exports = (common) => { | ||
describe('interface-peer-discovery', () => { | ||
let discovery | ||
|
||
before(() => { | ||
discovery = common.setup() | ||
}) | ||
|
||
after(() => common.teardown && common.teardown()) | ||
|
||
it('can start the service', async () => { | ||
await discovery.start() | ||
}) | ||
|
||
it('can start and stop the service', async () => { | ||
await discovery.start() | ||
await discovery.stop() | ||
}) | ||
|
||
it('should not fail to stop the service if it was not started', async () => { | ||
await discovery.stop() | ||
}) | ||
|
||
it('should not fail to start the service if it is already started', async () => { | ||
await discovery.start() | ||
await discovery.start() | ||
}) | ||
}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const tests = require('../src') | ||
const MockDiscovery = require('./mock-discovery') | ||
|
||
describe('compliance tests', () => { | ||
tests({ | ||
setup () { | ||
return new MockDiscovery() | ||
} | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict' | ||
|
||
const { EventEmitter } = require('events') | ||
|
||
const PeerId = require('peer-id') | ||
const PeerInfo = require('peer-info') | ||
|
||
/** | ||
* Emits 'peer' events on discovery. | ||
*/ | ||
class MockDiscovery extends EventEmitter { | ||
/** | ||
* Constructs a new Bootstrap. | ||
* | ||
* @param {Object} options | ||
* @param {number} options.discoveryDelay - the delay to find a peer (in milli-seconds) | ||
*/ | ||
constructor (options = {}) { | ||
super() | ||
|
||
this.options = options | ||
this._isRunning = false | ||
this._timer = null | ||
} | ||
|
||
start () { | ||
this._isRunning = true | ||
this._discoverPeer() | ||
} | ||
|
||
stop () { | ||
clearTimeout(this._timer) | ||
this._isRunning = false | ||
} | ||
|
||
async _discoverPeer () { | ||
if (!this._isRunning) return | ||
|
||
const peerId = await PeerId.create({ bits: 512 }) | ||
const peerInfo = new PeerInfo(peerId) | ||
|
||
this._timer = setTimeout(() => { | ||
this.emit('peer', peerInfo) | ||
}, this.options.discoveryDelay || 1000) | ||
} | ||
} | ||
|
||
module.exports = MockDiscovery |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discovery.on
anddiscovery.removeListener
should get added as well, but those can wait until we add a proper test suite here, since they'll get tested as a part of that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yap, I plan to add them in a next step, once we are working more closely with all the other peer discovery protocols.
Things are slightly different for each of them, and I need to have a better context on all of them to create a generic test setup for all. This way, I think we can start with this for the
*-star
, and then upgrade them once we get intodht
andmdns
ones