Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
test: add human readable test to stats bitswap
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Santos committed Nov 19, 2019
1 parent 7cf6782 commit f834e73
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
27 changes: 2 additions & 25 deletions src/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const waterfall = require('async/waterfall')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { expectIsBitswap } = require('../stats/utils')
const { expectIsBitswap, expectIsBitswapHumanReadable } = require('../stats/utils')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
Expand Down Expand Up @@ -46,30 +46,7 @@ module.exports = (createCommon, options) => {
it('should get human readable bitswap stats', async () => {
const stats = await ipfs.bitswap.stat({ human: true })

expect(stats).to.exist()
expect(stats).to.have.a.property('provideBufLen')
.and.to.be.a('number')
expect(stats).to.have.a.property('blocksReceived')
.and.to.be.a('number')
expect(stats).to.have.a.property('wantlist')
.and.to.be.a('string')
.and.to.match(/\[\d+\skeys\]$/gm)
expect(stats).to.have.a.property('peers')
.and.to.be.a('string')
.and.to.match(/\[\d+\]$/gm)
expect(stats).to.have.a.property('dupBlksReceived')
.and.to.be.a('number')
expect(stats).to.have.a.property('dupDataReceived')
.and.to.be.a('string')
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
expect(stats).to.have.a.property('dataReceived')
.and.to.be.a('string')
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
expect(stats).to.have.a.property('blocksSent')
.and.to.be.a('number')
expect(stats).to.have.a.property('dataSent')
.and.to.be.a('string')
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
expectIsBitswapHumanReadable(null, stats)
})

it('should not get bitswap stats when offline', function (done) {
Expand Down
8 changes: 7 additions & 1 deletion src/stats/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict'

const { getDescribe, getIt, expect } = require('../utils/mocha')
const { expectIsBitswap } = require('./utils')
const { expectIsBitswap, expectIsBitswapHumanReadable } = require('./utils')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
Expand Down Expand Up @@ -41,5 +41,11 @@ module.exports = (createCommon, options) => {
expectIsBitswap(null, res)
})
})

it('should get human readable bitswap stats', async () => {
const stats = await ipfs.stats.bitswap({ human: true })

expectIsBitswapHumanReadable(null, stats)
})
})
}
28 changes: 28 additions & 0 deletions src/stats/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ exports.expectIsBitswap = (err, stats) => {
expect(isBigInt(stats.dupDataReceived)).to.eql(true)
}

exports.expectIsBitswapHumanReadable = (err, stats) => {
expect(err).to.not.exist()
expect(stats).to.exist()
expect(stats).to.have.a.property('provideBufLen')
.and.to.be.a('number')
expect(stats).to.have.a.property('blocksReceived')
.and.to.be.a('number')
expect(stats).to.have.a.property('wantlist')
.and.to.be.a('string')
.and.to.match(/\[\d+\skeys\]$/gm)
expect(stats).to.have.a.property('peers')
.and.to.be.a('string')
.and.to.match(/\[\d+\]$/gm)
expect(stats).to.have.a.property('dupBlksReceived')
.and.to.be.a('number')
expect(stats).to.have.a.property('dupDataReceived')
.and.to.be.a('string')
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
expect(stats).to.have.a.property('dataReceived')
.and.to.be.a('string')
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
expect(stats).to.have.a.property('blocksSent')
.and.to.be.a('number')
expect(stats).to.have.a.property('dataSent')
.and.to.be.a('string')
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
}

exports.expectIsBandwidth = (err, stats) => {
expect(err).to.not.exist()
expect(stats).to.exist()
Expand Down

0 comments on commit f834e73

Please sign in to comment.