This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: refactor and add moar tests * feat: update to latest js-libp2p, peer-info, peer-book
- Loading branch information
Showing
11 changed files
with
1,079 additions
and
553 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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
const expect = chai.expect | ||
const signalling = require('libp2p-webrtc-star/src/sig-server') | ||
const parallel = require('async/parallel') | ||
const utils = require('./utils') | ||
const createNode = utils.createNode | ||
const echo = utils.echo | ||
|
||
describe('discovery', () => { | ||
let nodeA | ||
let nodeB | ||
let ss | ||
|
||
function setup (options) { | ||
before((done) => { | ||
parallel([ | ||
(cb) => { | ||
signalling.start({ port: 24642 }, (err, server) => { | ||
expect(err).to.not.exist() | ||
ss = server | ||
cb() | ||
}) | ||
}, | ||
(cb) => createNode([ | ||
'/ip4/0.0.0.0/tcp/0', | ||
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws' | ||
], options, (err, node) => { | ||
expect(err).to.not.exist() | ||
nodeA = node | ||
node.handle('/echo/1.0.0', echo) | ||
node.start(cb) | ||
}), | ||
(cb) => createNode([ | ||
'/ip4/0.0.0.0/tcp/0', | ||
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws' | ||
], options, (err, node) => { | ||
expect(err).to.not.exist() | ||
nodeB = node | ||
node.handle('/echo/1.0.0', echo) | ||
node.start(cb) | ||
}) | ||
], done) | ||
}) | ||
|
||
after((done) => { | ||
parallel([ | ||
(cb) => nodeA.stop(cb), | ||
(cb) => nodeB.stop(cb), | ||
(cb) => ss.stop(done) | ||
], done) | ||
}) | ||
} | ||
|
||
describe('MulticastDNS', () => { | ||
setup({ mdns: true }) | ||
|
||
it('find a peer', (done) => { | ||
nodeA.once('peer:discovery', (peerInfo) => { | ||
expect(nodeB.peerInfo.id.toB58String()) | ||
.to.eql(peerInfo.id.toB58String()) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
// TODO needs a delay (this test is already long) | ||
describe.skip('WebRTCStar', () => { | ||
setup({ webRTCStar: true }) | ||
|
||
it('find a peer', (done) => { | ||
nodeA.once('peer:discovery', (peerInfo) => { | ||
expect(nodeB.peerInfo.id.toB58String()) | ||
.to.eql(peerInfo.id.toB58String()) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('MulticastDNS + WebRTCStar', () => { | ||
setup({ | ||
webRTCStar: true, | ||
mdns: true | ||
}) | ||
|
||
it('find a peer', (done) => { | ||
nodeA.once('peer:discovery', (peerInfo) => { | ||
expect(nodeB.peerInfo.id.toB58String()) | ||
.to.eql(peerInfo.id.toB58String()) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.