1 | 'use strict'
|
2 |
|
3 | const test = require('tap').test
|
4 | const util = require('util')
|
5 | const analyseCPU = util.promisify(require('../analysis/analyse-cpu.js'))
|
6 | const generateProcessStat = require('./generate-process-stat.js')
|
7 |
|
8 | test('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, []), 'none')
|
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, []), 'performance')
|
19 | }
|
20 |
|
21 | t.end()
|
22 | })
|
23 |
|
24 | test('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, []), 'none')
|
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, []), 'performance')
|
35 | }
|
36 |
|
37 | t.end()
|
38 | })
|
39 |
|
40 | test('analyse cpu - two mode - opposite clusters', async function (t) {
|
41 |
|
42 |
|
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, []), 'none')
|
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, []), 'performance')
|
59 | }
|
60 |
|
61 | t.end()
|
62 | })
|
63 |
|
64 | test('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, []), 'data')
|
70 |
|
71 | const badCPU = generateProcessStat({
|
72 | cpu: [50, 40, 10]
|
73 | }, noise)
|
74 | t.strictEqual(await analyseCPU({}, badCPU, []), 'data')
|
75 | }
|
76 |
|
77 | t.end()
|
78 | })
|
79 |
|
80 | test('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, []), 'none')
|
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, []), 'performance')
|
91 | }
|
92 |
|
93 | t.end()
|
94 | })
|