-
Notifications
You must be signed in to change notification settings - Fork 37
observe traffic and expose statistics #243
Changes from 2 commits
494d7fd
758cf2a
0afd916
0f5bfaa
20d6934
7210efc
0eb8c26
84e766b
fa6e377
a1d9014
3d0ad42
7ee4fc5
6ea2061
e692fa2
905680a
f6db42d
ae88175
39f01af
84b00f9
eb2cf59
fb0d209
a2cd482
2ed0cf8
5b3cb3b
6c0ff32
efc7c92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,19 +82,47 @@ describe('Stats', () => { | |
}) | ||
}) | ||
|
||
it('waits a bit', (done) => setTimeout(done, 1900)) | ||
it('waits a bit', (done) => setTimeout(done, 1000)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A test case that just waits? Should fix the tests to not depend on the ordering... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @victorbjelkholm good call! Fixed by moving the preparation code to a before hook. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pgte better to get rid of the after/before hooks we have and have function calls in the test cases that returns what you need. If all tests where shaped like this, we can run tests in parallel and just run one isolated test case if wanted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my case I need something to run once, not for every test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @victorbjelkholm changed to isolated tests for stats, would love your feedback. |
||
|
||
it('A has some stats', () => { | ||
const snapshot = switchA.stats.global.snapshot | ||
console.log('%j', snapshot) | ||
it('both nodes have some global stats', () => { | ||
let snapshot = switchA.stats.global.snapshot | ||
expect(snapshot.dataReceived.toFixed()).to.equal('51') | ||
expect(snapshot.dataSent.toFixed()).to.equal('49') | ||
}) | ||
|
||
it('B has some stats', () => { | ||
const snapshot = switchB.stats.global.snapshot | ||
console.log('%j', snapshot) | ||
snapshot = switchB.stats.global.snapshot | ||
expect(snapshot.dataReceived.toFixed()).to.equal('51') | ||
expect(snapshot.dataSent.toFixed()).to.equal('49') | ||
}) | ||
|
||
it('both nodes know some transports', () => { | ||
const expectedTransports = [ | ||
'/mplex/6.7.0', | ||
'/secio/1.0.0' | ||
] | ||
expect(switchA.stats.transports().sort()).to.deep.equal(expectedTransports) | ||
expect(switchB.stats.transports().sort()).to.deep.equal(expectedTransports) | ||
}) | ||
|
||
it('both nodes know some protocols', () => { | ||
const expectedProtocols = [ | ||
'/echo/1.0.0', | ||
'/mplex/6.7.0' | ||
] | ||
expect(switchA.stats.protocols().sort()).to.deep.equal(expectedProtocols) | ||
expect(switchB.stats.protocols().sort()).to.deep.equal(expectedProtocols) | ||
}) | ||
|
||
it('both nodes know about each other', () => { | ||
expect(switchA.stats.peers().sort()).to.deep.equal([switchB._peerInfo.id.toB58String()]) | ||
expect(switchB.stats.peers().sort()).to.deep.equal([switchA._peerInfo.id.toB58String()]) | ||
}) | ||
|
||
it('both have transport-specific stats', () => { | ||
let snapshot = switchA.stats.forTransport('/secio/1.0.0').snapshot | ||
expect(snapshot.dataReceived.toFixed()).to.equal('92') | ||
expect(snapshot.dataSent.toFixed()).to.equal('90') | ||
snapshot = switchB.stats.forTransport('/secio/1.0.0').snapshot | ||
expect(snapshot.dataReceived.toFixed()).to.equal('92') | ||
expect(snapshot.dataSent.toFixed()).to.equal('90') | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does one "clear" previous stats from a peer?