From 6ef8b9329f676d042c1a914f254f8cf9399d2330 Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Fri, 15 Nov 2019 11:55:35 +0000 Subject: [PATCH 1/4] test: add human readable test to bitswap stat --- src/bitswap/stat.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/bitswap/stat.js b/src/bitswap/stat.js index 024612474..0fec7a525 100644 --- a/src/bitswap/stat.js +++ b/src/bitswap/stat.js @@ -43,6 +43,35 @@ module.exports = (createCommon, options) => { }) }) + it.only('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) + }) + it('should not get bitswap stats when offline', function (done) { this.timeout(60 * 1000) From add56ed3ec24be0a03496c4075b6988d6078bd98 Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Mon, 18 Nov 2019 16:15:06 +0000 Subject: [PATCH 2/4] fix: swarm stats provideBufLen assertion --- src/stats/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stats/utils.js b/src/stats/utils.js index fd7a1d62a..0d4772d6b 100644 --- a/src/stats/utils.js +++ b/src/stats/utils.js @@ -19,9 +19,9 @@ exports.expectIsBitswap = (err, stats) => { expect(stats).to.have.a.property('dupBlksReceived') expect(stats).to.have.a.property('dupDataReceived') - expect(stats.provideBufLen).to.a('number') expect(stats.wantlist).to.be.an('array') expect(stats.peers).to.be.an('array') + expect(isBigInt(stats.provideBufLen)).to.eql(true) expect(isBigInt(stats.blocksReceived)).to.eql(true) expect(isBigInt(stats.dataReceived)).to.eql(true) expect(isBigInt(stats.blocksSent)).to.eql(true) From 7cf67824f7b3b5f6ad4716aa73db894b5970b401 Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Mon, 18 Nov 2019 16:35:48 +0000 Subject: [PATCH 3/4] chore: remove 'only' method from test --- src/bitswap/stat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitswap/stat.js b/src/bitswap/stat.js index 0fec7a525..0cd9bfef4 100644 --- a/src/bitswap/stat.js +++ b/src/bitswap/stat.js @@ -43,7 +43,7 @@ module.exports = (createCommon, options) => { }) }) - it.only('should get human readable bitswap stats', async () => { + it('should get human readable bitswap stats', async () => { const stats = await ipfs.bitswap.stat({ human: true }) expect(stats).to.exist() From f834e73834de6f0285beae057655c501e40de96e Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Tue, 19 Nov 2019 08:58:10 +0000 Subject: [PATCH 4/4] test: add human readable test to stats bitswap --- src/bitswap/stat.js | 27 ++------------------------- src/stats/bitswap.js | 8 +++++++- src/stats/utils.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/bitswap/stat.js b/src/bitswap/stat.js index 0cd9bfef4..569fc4143 100644 --- a/src/bitswap/stat.js +++ b/src/bitswap/stat.js @@ -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) @@ -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) { diff --git a/src/stats/bitswap.js b/src/stats/bitswap.js index b0e57f38b..d3a4a2628 100644 --- a/src/stats/bitswap.js +++ b/src/stats/bitswap.js @@ -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) @@ -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) + }) }) } diff --git a/src/stats/utils.js b/src/stats/utils.js index 0d4772d6b..dbbbcb18d 100644 --- a/src/stats/utils.js +++ b/src/stats/utils.js @@ -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()