-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
51 lines (43 loc) · 1.03 KB
/
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
43
44
45
46
47
48
49
50
51
'use strict';
const tap = require('tap');
const sinon = require('sinon');
const clockit = require('clockit');
const gauge = require('.');
if (/^v4/.test(process.version)) {
tap.notOk(gauge.start);
return;
}
tap.test('stub CPU & time', (t) => {
var sandbox = sinon.sandbox.create();
sandbox.stub(process, 'cpuUsage');
sandbox.stub(clockit, 'start');
t.tearDown(() => sandbox.restore());
process.cpuUsage.returns({ user: 100, system: 51 });
clockit.start.returns({ us: 200 });
var cpu = gauge.start();
t.strictSame(cpu.usage(), {
user: 100,
system: 51,
time: 200,
percent: 75.5
});
t.end();
});
tap.test('busy', (t) => {
var json = require('./package.json');
var cpu = gauge.start();
for (var i = 0; i < 1000; ++i) {
JSON.parse(JSON.stringify(json));
}
var usage = cpu.usage();
t.ok(usage.percent > 50, usage);
t.end();
});
tap.test('idle', (t) => {
var cpu = gauge.start();
setTimeout(() => {
var usage = cpu.usage();
t.ok(usage.percent < 50, usage);
t.end();
}, 10);
});