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

Commit

Permalink
statsss
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Feb 6, 2018
1 parent c76eab4 commit aed0bb7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
3 changes: 1 addition & 2 deletions SPEC/STATS.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ Options are described on [`ipfs.stats.bw`](#bw).

```JavaScript
const stream = ipfs.stats.bwReadableStream({ poll: true })
const bl = require('bl')

stream.pipe(bl((err, data) => {
stream.on('data', (data) => {
console.log(data)
}))

Expand Down
45 changes: 20 additions & 25 deletions js/src/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const chai = require('chai')
const dirtyChai = require('dirty-chai')
const statsTests = require('./utils/stats')
const expect = chai.expect
const pull = require('pull-stream')
chai.use(dirtyChai)

module.exports = (common) => {
Expand Down Expand Up @@ -72,50 +73,44 @@ module.exports = (common) => {
})
})

it('.bw Poll', (done) => {
it('.bw Promise', () => {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
return done()
return
}

ipfs.stats.bw({poll: true}, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()

res.once('data', (data) => {
statsTests.expectIsBandwidth(null, data)
done()
res.destroy()
})
return ipfs.stats.bw().then((res) => {
statsTests.expectIsBandwidth(null, res)
})
})

it('.bw Promise', () => {
it('.bwReadableStream', (done) => {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
return
return done()
}

return ipfs.stats.bw().then((res) => {
statsTests.expectIsBandwidth(null, res)
const stream = ipfs.stats.bwReadableStream()

stream.once('data', (data) => {
statsTests.expectIsBandwidth(null, data)
stream.destroy()
done()
})
})

it('.bw Promise Poll', (done) => {
it('.bwPullStream', (done) => {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
return
return done()
}

ipfs.stats.bw({poll: true}).then((res) => {
expect(res).to.exist()
const stream = ipfs.stats.bwPullStream()

res.once('data', (data) => {
statsTests.expectIsBandwidth(null, data)
done()
res.destroy()
})
}).catch(done)
pull(
stream,
pull.log()
)
})

it('.repo', (done) => {
Expand Down
9 changes: 2 additions & 7 deletions js/src/utils/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ const Big = require('big.js')
const { expect } = require('chai')

const isBigInt = (n) => {
try {
new Big(n)
return true
} catch (e) {
return false
}
return n.constructor.name === 'Big'
}

module.exports.expectIsBitswap = (err, stats) => {
Expand All @@ -28,7 +23,7 @@ module.exports.expectIsBitswap = (err, stats) => {
expect(stats).to.have.a.property('dupBlksReceived')
expect(stats).to.have.a.property('dupDataReceived')

expect(isBigInt(stats.provideBufLen)).to.eql(true)
expect(stats.provideBufLen).to.a('number')
expect(stats.wantlist).to.be.an('array')
expect(stats.peers).to.be.an('array')
expect(isBigInt(stats.blocksReceived)).to.eql(true)
Expand Down

0 comments on commit aed0bb7

Please sign in to comment.