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

Commit aed0bb7

Browse files
committed
statsss
1 parent c76eab4 commit aed0bb7

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

SPEC/STATS.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ Options are described on [`ipfs.stats.bw`](#bw).
9292

9393
```JavaScript
9494
const stream = ipfs.stats.bwReadableStream({ poll: true })
95-
const bl = require('bl')
9695

97-
stream.pipe(bl((err, data) => {
96+
stream.on('data', (data) => {
9897
console.log(data)
9998
}))
10099

js/src/stats.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const chai = require('chai')
77
const dirtyChai = require('dirty-chai')
88
const statsTests = require('./utils/stats')
99
const expect = chai.expect
10+
const pull = require('pull-stream')
1011
chai.use(dirtyChai)
1112

1213
module.exports = (common) => {
@@ -72,50 +73,44 @@ module.exports = (common) => {
7273
})
7374
})
7475

75-
it('.bw Poll', (done) => {
76+
it('.bw Promise', () => {
7677
if (!withGo) {
7778
console.log('Not supported in js-ipfs yet')
78-
return done()
79+
return
7980
}
8081

81-
ipfs.stats.bw({poll: true}, (err, res) => {
82-
expect(err).to.not.exist()
83-
expect(res).to.exist()
84-
85-
res.once('data', (data) => {
86-
statsTests.expectIsBandwidth(null, data)
87-
done()
88-
res.destroy()
89-
})
82+
return ipfs.stats.bw().then((res) => {
83+
statsTests.expectIsBandwidth(null, res)
9084
})
9185
})
9286

93-
it('.bw Promise', () => {
87+
it('.bwReadableStream', (done) => {
9488
if (!withGo) {
9589
console.log('Not supported in js-ipfs yet')
96-
return
90+
return done()
9791
}
9892

99-
return ipfs.stats.bw().then((res) => {
100-
statsTests.expectIsBandwidth(null, res)
93+
const stream = ipfs.stats.bwReadableStream()
94+
95+
stream.once('data', (data) => {
96+
statsTests.expectIsBandwidth(null, data)
97+
stream.destroy()
98+
done()
10199
})
102100
})
103101

104-
it('.bw Promise Poll', (done) => {
102+
it('.bwPullStream', (done) => {
105103
if (!withGo) {
106104
console.log('Not supported in js-ipfs yet')
107-
return
105+
return done()
108106
}
109107

110-
ipfs.stats.bw({poll: true}).then((res) => {
111-
expect(res).to.exist()
108+
const stream = ipfs.stats.bwPullStream()
112109

113-
res.once('data', (data) => {
114-
statsTests.expectIsBandwidth(null, data)
115-
done()
116-
res.destroy()
117-
})
118-
}).catch(done)
110+
pull(
111+
stream,
112+
pull.log()
113+
)
119114
})
120115

121116
it('.repo', (done) => {

js/src/utils/stats.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ const Big = require('big.js')
77
const { expect } = require('chai')
88

99
const isBigInt = (n) => {
10-
try {
11-
new Big(n)
12-
return true
13-
} catch (e) {
14-
return false
15-
}
10+
return n.constructor.name === 'Big'
1611
}
1712

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

31-
expect(isBigInt(stats.provideBufLen)).to.eql(true)
26+
expect(stats.provideBufLen).to.a('number')
3227
expect(stats.wantlist).to.be.an('array')
3328
expect(stats.peers).to.be.an('array')
3429
expect(isBigInt(stats.blocksReceived)).to.eql(true)

0 commit comments

Comments
 (0)