forked from Netflix/spectator-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
counter.test.js
42 lines (33 loc) · 1.04 KB
/
counter.test.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
'use strict';
const chai = require('chai');
const assert = chai.assert;
const Counter = require('../src/Counter');
const MeterId = require('../src/meter_id');
describe('Counters', () => {
it('should record values', () => {
const id = new MeterId('c');
const counter = new Counter(id);
// quick sanity check
assert.equal(counter.count, 0);
counter.add(100);
assert.equal(counter.count, 100);
// 0 counts towards total number of events
counter.increment();
assert.equal(counter.count, 101);
counter.increment(101);
assert.equal(counter.count, 202);
// ignores negative values
counter.add(-1);
assert.equal(counter.count, 202);
});
it('should report proper measurements', () => {
const id = new MeterId('c');
const counter = new Counter(id);
assert.lengthOf(counter.measure(), 0);
counter.add(2);
counter.increment();
const ms = counter.measure();
assert.lengthOf(counter.measure(), 0); // resets
assert.deepEqual([{id: id.withStat('count'), v: 3}], ms);
});
});