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 5, 2018
1 parent 3499fe4 commit 9b33a31
Showing 1 changed file with 61 additions and 0 deletions.
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 9b33a31

Please sign in to comment.