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 pathstats.js
122 lines (102 loc) · 2.69 KB
/
stats.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'
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) => {
describe('.stats', () => {
let ipfs
let withGo
before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)
common.setup((err, factory) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
node.id((err, id) => {
expect(err).to.not.exist()
withGo = id.agentVersion.startsWith('go-ipfs')
done()
})
})
})
})
after((done) => {
common.teardown(done)
})
it('.bitswap', (done) => {
ipfs.stats.bitswap((err, res) => {
statsTests.expectIsBitswap(err, res)
done()
})
})
it('.bitswap Promise', () => {
return ipfs.stats.bitswap().then((res) => {
statsTests.expectIsBitswap(null, res)
})
})
it('.bw', function (done) {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
this.skip()
}
ipfs.stats.bw((err, res) => {
statsTests.expectIsBandwidth(err, res)
done()
})
})
it('.bw Promise', function (done) {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
this.skip()
}
return ipfs.stats.bw().then((res) => {
statsTests.expectIsBandwidth(null, res)
})
})
it('.bwReadableStream', function (done) {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
this.skip()
}
const stream = ipfs.stats.bwReadableStream()
stream.once('data', (data) => {
statsTests.expectIsBandwidth(null, data)
stream.destroy()
done()
})
})
it('.bwPullStream', function (done) {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
this.skip()
}
const stream = ipfs.stats.bwPullStream()
pull(
stream,
pull.collect((err, data) => {
statsTests.expectIsBandwidth(err, data[0])
done()
})
)
})
it('.repo', (done) => {
ipfs.stats.repo((err, res) => {
statsTests.expectIsRepo(err, res)
done()
})
})
it('.repo Promise', () => {
return ipfs.stats.repo().then((res) => {
statsTests.expectIsRepo(null, res)
})
})
})
}