Skip to content

Commit

Permalink
wip: tests cleaup
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Aug 16, 2017
1 parent 19ff1f4 commit c165e2e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 86 deletions.
5 changes: 1 addition & 4 deletions test/nodejs-bundle/circuit/dial-over-any-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,10 @@ describe('test connecting over any relay', function () {
utils.dialAndReverse(
testNodes.nodeB,
testNodes.nodeA,
['hello', 'hello1', 'hello2', 'hello3'],
['hello'],
(err, result) => {
expect(err).to.be.null()
expect(result[0]).to.equal('hello'.split('').reverse('').join(''))
expect(result[1]).to.equal('hello1'.split('').reverse('').join(''))
expect(result[2]).to.equal('hello2'.split('').reverse('').join(''))
expect(result[3]).to.equal('hello3'.split('').reverse('').join(''))
done()
})
})
Expand Down
47 changes: 0 additions & 47 deletions test/nodejs-bundle/circuit/dial-over-specific-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,51 +158,4 @@ describe(`listen on an explicit relay addr`, function () {
})
})
})

// describe.skip(`active`, function () {
// beforeEach(function (done) {
// active = true
// setUpNodes(multiplex, () => {
// setTimeout(done, 1000) // give the nodes time to startup
// })
// })
//
// afterEach(function circuitTests (done) {
// relaySpy1.reset()
// relaySpy2.reset()
// utils.stopNodes(testNodes, done)
// })
//
// it('dial over the correct relay', function (done) {
// utils.dialAndReverse(testNodes['nodeA'], testNodes['nodeB'], ['hello'], (err, result) => {
// expect(err).to.be.null()
// expect(relaySpy2.called).to.be.not.ok()
// expect(relaySpy1.called).to.be.ok()
//
// expect(relaySpy1.args[0][1].toString())
// .to
// .equal((`/ipfs/${testNodes['nodeB'].peerInfo.id.toB58String()}`))
//
// expect(result[0]).to.equal('hello'.split('').reverse('').join(''))
//
// done(err)
// })
// })
//
// it('dial over the correct relay and transport', function (done) {
// utils.dialAndReverse(testNodes['nodeB'], testNodes['nodeA'], ['hello'], (err, result) => {
// expect(err).to.be.null()
// expect(relaySpy1.called).to.be.not.ok()
// expect(relaySpy2.called).to.be.ok()
//
// expect(relaySpy2.args[0][1].toString())
// .to
// .equal((`/ipfs/${testNodes['nodeA'].peerInfo.id.toB58String()}`))
//
// expect(result[0]).to.equal('hello'.split('').reverse('').join(''))
//
// done(err)
// })
// })
// })
})
37 changes: 7 additions & 30 deletions test/nodejs-bundle/circuit/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,20 @@ const pull = require('pull-stream')

exports.createNodes = function createNodes (configNodes, callback) {
const nodes = {}
eachAsync(Object.keys(configNodes), (key, cb1) => {
eachAsync(Object.keys(configNodes), (key, cb) => {
let config = configNodes[key]

const setup = (err, peer) => {
if (err) {
callback(err)
}

eachAsync(config.addrs, (addr, cb2) => {
config.addrs.forEach((addr) => {
peer.multiaddrs.add(addr)
cb2()
}, (err) => {
if (err) {
return callback(err)
}

nodes[key] = new TestNode(peer, config.transports, config.muxer, config.config)
cb1()
})

nodes[key] = new TestNode(peer, config.transports, config.muxer, config.config)
cb()
}

if (config.id) {
Expand All @@ -53,29 +48,11 @@ exports.createNodes = function createNodes (configNodes, callback) {
}

function startNodes (nodes, callback) {
eachAsync(Object.keys(nodes),
(key, cb) => {
nodes[key].start(cb)
},
(err) => {
if (err) {
return callback(err)
}
callback(null)
})
eachAsync(Object.keys(nodes), (key, cb) => nodes[key].start(cb), callback)
}

exports.stopNodes = function stopNodes (nodes, callback) {
eachAsync(Object.keys(nodes),
(key, cb) => {
nodes[key].stop(cb)
},
(err) => {
if (err) {
return callback(err)
}
callback()
})
eachAsync(Object.keys(nodes), (key, cb) => nodes[key].stop(cb), callback)
}

function reverse (protocol, conn) {
Expand Down
10 changes: 6 additions & 4 deletions test/nodejs-bundle/nodejs-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ function mapMuxers (list) {
return pref
}
switch (pref.trim().toLowerCase()) {
case 'spdy': return spdy
case 'multiplex': return multiplex
case 'spdy':
return spdy
case 'multiplex':
return multiplex
default:
throw new Error(pref + ' muxer not available')
}
Expand All @@ -40,13 +42,13 @@ class Node extends libp2p {
options = options || {}

const modules = {
transport: [
transport: options.transports || [
new TCP(),
new WS()
],
connection: {
muxer: getMuxers(options.muxer),
crypto: [ secio ]
crypto: [secio]
},
discovery: []
}
Expand Down
2 changes: 1 addition & 1 deletion test/nodejs-bundle/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function createNode (multiaddrs, options, callback) {
}

waterfall([
(cb) => PeerId.create({ bits: 1024 }, cb),
(cb) => options.id ? PeerId.createFromB58String(options.id) : PeerId.create({bits: 1024}, cb),
(peerId, cb) => PeerInfo.create(peerId, cb),
(peerInfo, cb) => {
multiaddrs.map((ma) => peerInfo.multiaddrs.add(ma))
Expand Down

0 comments on commit c165e2e

Please sign in to comment.