Skip to content

Commit

Permalink
test: add ping tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed Oct 17, 2018
1 parent 35e1a43 commit b6fec69
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ require('./pnet.node')
require('./transports.node')
require('./stream-muxing.node')
require('./peer-discovery.node')
require('./pubsub.node')
require('./peer-routing.node')
require('./ping.node')
require('./pubsub.node')
require('./content-routing.node')
require('./circuit-relay.node')
require('./multiaddr-trim.node')
Expand Down
61 changes: 61 additions & 0 deletions test/ping.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const parallel = require('async/parallel')

const createNode = require('./utils/create-node.js')
const echo = require('./utils/echo')

describe('ping', () => {
let nodeA
let nodeB

before((done) => {
parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', (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', (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)
], done)
})

it('should be able to ping another node', (done) => {
nodeA.ping(nodeB.peerInfo, (err, ping) => {
expect(err).to.not.exist()
ping.once('ping', (time) => {
expect(time).to.exist()
ping.stop()
done()
})

ping.start()
})
})

it('should be not be able to ping when stopped', (done) => {
nodeA.stop(() => {
nodeA.ping(nodeB.peerInfo, (err) => {
expect(err).to.exist()
done()
})
})
})
})

0 comments on commit b6fec69

Please sign in to comment.