UNPKG

2.74 kBJavaScriptView Raw
1'use strict'
2
3const test = require('tap').test
4const util = require('util')
5const analyseCPU = util.promisify(require('../analysis/analyse-cpu.js'))
6const generateProcessStat = require('./generate-process-stat.js')
7
8test('analyse cpu - one mode', async function (t) {
9 for (const noise of [0, 0.1, 0.3, 0.5]) {
10 const goodCPU = generateProcessStat({
11 cpu: [100, 100, 120, 100, 110, 100, 100, 110, 90, 110]
12 }, noise)
13 t.strictEqual(await analyseCPU(goodCPU, []), false)
14
15 const badCPU = generateProcessStat({
16 cpu: [50, 40, 10, 10, 80, 50, 40, 1, 10, 30, 10]
17 }, noise)
18 t.strictEqual(await analyseCPU(badCPU, []), true)
19 }
20
21 t.end()
22})
23
24test('analyse cpu - two mode', async function (t) {
25 for (const noise of [0, 0.1, 0.3, 0.5]) {
26 const goodCPU = generateProcessStat({
27 cpu: [200, 200, 100, 90, 190, 200, 80, 110, 190, 200]
28 }, noise)
29 t.strictEqual(await analyseCPU(goodCPU, []), false)
30
31 const badCPU = generateProcessStat({
32 cpu: [200, 200, 15, 10, 190, 200, 5, 15, 190, 200]
33 }, noise)
34 t.strictEqual(await analyseCPU(badCPU, []), true)
35 }
36
37 t.end()
38})
39
40test('analyse cpu - two mode - opposite clusters', async function (t) {
41 // Test the `summary0.mean() < summary1.mean()` is true case in
42 // summaryAplication = summary0.mean() < summary1.mean() ? summary0 : summary1
43 for (const noise of [0, 0.1, 0.3, 0.5]) {
44 const goodCPU = generateProcessStat({
45 cpu: [
46 200, 200, 100, 90, 190, 200, 80, 110, 190, 200,
47 200, 200, 100, 90, 190, 200, 80, 110, 190, 200
48 ]
49 }, noise)
50 t.strictEqual(await analyseCPU(goodCPU, []), false)
51
52 const badCPU = generateProcessStat({
53 cpu: [
54 200, 200, 15, 10, 190, 200, 5, 15, 190, 200,
55 200, 200, 15, 10, 190, 200, 5, 15, 190, 200
56 ]
57 }, noise)
58 t.strictEqual(await analyseCPU(badCPU, []), true)
59 }
60
61 t.end()
62})
63
64test('analyse cpu - little data', async function (t) {
65 for (const noise of [0, 0.1, 0.3, 0.5]) {
66 const goodCPU = generateProcessStat({
67 cpu: [100, 100, 120]
68 }, noise)
69 t.strictEqual(await analyseCPU(goodCPU, []), false)
70
71 const badCPU = generateProcessStat({
72 cpu: [50, 40, 10]
73 }, noise)
74 t.strictEqual(await analyseCPU(badCPU, []), true)
75 }
76
77 t.end()
78})
79
80test('analyse cpu - small cluster data', async function (t) {
81 for (const noise of [0, 0.1, 0.3, 0.5]) {
82 const goodCPU = generateProcessStat({
83 cpu: [200, 200, 100, 90, 190, 200, 80, 110, 190, 0]
84 }, noise)
85 t.strictEqual(await analyseCPU(goodCPU, []), false)
86
87 const badCPU = generateProcessStat({
88 cpu: [50, 40, 10, 10, 200, 50, 40, 10, 10, 30, 10]
89 }, noise)
90 t.strictEqual(await analyseCPU(badCPU, []), true)
91 }
92
93 t.end()
94})