This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathping.js
54 lines (42 loc) · 1.51 KB
/
ping.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-env mocha */
'use strict'
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { expectIsPingResponse, isPong } = require('./utils')
const all = require('it-all')
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
describe('.ping', function () {
this.timeout(60 * 1000)
let ipfsA
let ipfsB
before(async () => {
ipfsA = (await common.spawn()).api
ipfsB = (await common.spawn()).api
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
})
after(() => common.clean())
it('should send the specified number of packets', async () => {
const count = 3
const responses = await all(ipfsA.ping(ipfsB.peerId.id, { count }))
responses.forEach(expectIsPingResponse)
const pongs = responses.filter(isPong)
expect(pongs.length).to.equal(count)
})
it('should fail when pinging a peer that is not available', () => {
const notAvailablePeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn'
const count = 2
return expect(all(ipfsA.ping(notAvailablePeerId, { count }))).to.eventually.be.rejected()
})
it('should fail when pinging an invalid peer Id', () => {
const invalidPeerId = 'not a peer ID'
const count = 2
return expect(all(ipfsA.ping(invalidPeerId, { count }))).to.eventually.be.rejected()
})
})
}