Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: stats tests #1226

Merged
merged 2 commits into from
Feb 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,11 @@ describe('bitswap', function () {
expect(() => node.bitswap.wantlist()).to.throw(/online/)
})

it('.stat throws while offline', () => {
expect(() => node.bitswap.stat()).to.throw(/online/)
it('.stat gives error while offline', () => {
node.bitswap.stat((err, stats) => {
expect(err).to.exist()
expect(stats).to.not.exist()
})
})

it('throws if offline', () => {
Expand All @@ -279,22 +282,22 @@ describe('bitswap', function () {
expect(node.bitswap.wantlist()).to.eql([])
})

it('returns the stats', () => {
let stats = node.bitswap.stat()

expect(stats).to.have.keys([
'blocksReceived',
'blocksSent',
'dataReceived',
'dataSent',
'wantListLength',
'wantlist',
'peerCount',
'peers',
'providesBufferLength',
'dupDataReceived',
'dupBlksReceived'
])
it('returns the stats', (done) => {
node.bitswap.stat((err, stats) => {
expect(err).to.not.exist()
expect(stats).to.have.keys([
'blocksReceived',
'blocksSent',
'dataReceived',
'dataSent',
'wantlist',
'peers',
'provideBufLen',
'dupDataReceived',
'dupBlksReceived'
])
done()
})
})
})
})
Expand Down
17 changes: 9 additions & 8 deletions test/http-api/spec/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ module.exports = (http) => {
url: '/api/v0/bitswap/stat'
}, (res) => {
expect(res.statusCode).to.equal(200)

expect(res.result).to.have.keys([
'BlocksReceived',
'Wantlist',
'Peers',
'DupBlksReceived',
'DupDataReceived'
])
expect(res.result).to.have.property('ProvideBufLen')
expect(res.result).to.have.property('BlocksReceived')
expect(res.result).to.have.property('Wantlist')
expect(res.result).to.have.property('Peers')
expect(res.result).to.have.property('DupBlksReceived')
expect(res.result).to.have.property('DupDataReceived')
expect(res.result).to.have.property('DataReceived')
expect(res.result).to.have.property('BlocksSent')
expect(res.result).to.have.property('DataSent')
done()
})
})
Expand Down