|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const chai = require('chai') |
| 5 | +chai.use(require('dirty-chai')) |
| 6 | +const expect = chai.expect |
| 7 | +const parallel = require('async/parallel') |
| 8 | + |
| 9 | +const createNode = require('./utils/create-node.js') |
| 10 | +const echo = require('./utils/echo') |
| 11 | + |
| 12 | +describe('ping', () => { |
| 13 | + let nodeA |
| 14 | + let nodeB |
| 15 | + |
| 16 | + before((done) => { |
| 17 | + parallel([ |
| 18 | + (cb) => createNode('/ip4/0.0.0.0/tcp/0', (err, node) => { |
| 19 | + expect(err).to.not.exist() |
| 20 | + nodeA = node |
| 21 | + node.handle('/echo/1.0.0', echo) |
| 22 | + node.start(cb) |
| 23 | + }), |
| 24 | + (cb) => createNode('/ip4/0.0.0.0/tcp/0', (err, node) => { |
| 25 | + expect(err).to.not.exist() |
| 26 | + nodeB = node |
| 27 | + node.handle('/echo/1.0.0', echo) |
| 28 | + node.start(cb) |
| 29 | + }) |
| 30 | + ], done) |
| 31 | + }) |
| 32 | + |
| 33 | + after((done) => { |
| 34 | + parallel([ |
| 35 | + (cb) => nodeA.stop(cb), |
| 36 | + (cb) => nodeB.stop(cb) |
| 37 | + ], done) |
| 38 | + }) |
| 39 | + |
| 40 | + it('should be able to ping another node', (done) => { |
| 41 | + nodeA.ping(nodeB.peerInfo, (err, ping) => { |
| 42 | + expect(err).to.not.exist() |
| 43 | + ping.once('ping', (time) => { |
| 44 | + expect(time).to.exist() |
| 45 | + ping.stop() |
| 46 | + done() |
| 47 | + }) |
| 48 | + |
| 49 | + ping.start() |
| 50 | + }) |
| 51 | + }) |
| 52 | + |
| 53 | + it('should be not be able to ping when stopped', (done) => { |
| 54 | + nodeA.stop(() => { |
| 55 | + nodeA.ping(nodeB.peerInfo, (err) => { |
| 56 | + expect(err).to.exist() |
| 57 | + done() |
| 58 | + }) |
| 59 | + }) |
| 60 | + }) |
| 61 | +}) |
0 commit comments