-
Notifications
You must be signed in to change notification settings - Fork 4
/
summary_test.ts
108 lines (88 loc) · 2.29 KB
/
summary_test.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { assertEquals, assertThrows, test } from "./test_deps.ts";
import { delay } from "https://deno.land/std/async/delay.ts";
import { Summary } from "./summary.ts";
import { Registry } from "./registry.ts";
test({
name: "Summary.with",
fn() {
const summary = Summary.with({
name: "summary_withouts_labels_and_percentiles",
help: "help",
});
assertEquals(summary.expose(), undefined);
assertThrows(() => {
Summary.with({
name: "summary_withouts_labels_and_percentiles",
help: "help",
});
});
},
});
test({
name: "Summary.observe",
fn() {
const summary = Summary.with({
name: "summary_withouts_labels_and_percentiles",
help: "help",
registry: [new Registry()],
});
assertEquals(summary.expose(), undefined);
const count = 10;
let sum = 0;
const values = [];
for (let i = 0; i < count; i++) {
sum += i;
values.push(i);
summary.observe(i);
}
assertEquals(summary.getValues(), values);
assertEquals(summary.getCount(), 10);
assertEquals(summary.getSum(), sum);
},
});
test({
name: "Summary.observe (maxAge)",
async fn() {
const summary = Summary.with({
name: "summary_withouts_labels_and_percentiles",
help: "help",
maxAge: 3000, // ms
registry: [new Registry()],
});
const count = 3;
let sum = 0;
const values = [1, 2, 3];
for (let i = 0; i < count; i++) {
summary.observe(i);
}
await delay(3000);
for (let i = 0; i < count; i++) {
sum += i;
summary.observe(i + 1);
}
assertEquals(summary.getValues(), values);
assertEquals(summary.getCount(), count);
assertEquals(summary.getSum(), values.reduce((s, v) => s + v, 0));
},
});
test({
name: "Summary.observe (ageBuckets)",
fn() {
const summary = Summary.with({
name: "summary_withouts_labels_and_percentiles",
help: "help",
ageBuckets: 3,
registry: [new Registry()],
});
const count = 10;
let sum = 0;
const values = [7, 8, 9];
for (let i = 0; i < count; i++) {
sum += i;
summary.observe(i);
}
assertEquals(summary.getValues(), values);
assertEquals(summary.getCount(), 3);
assertEquals(summary.getSum(), values.reduce((s, v) => s + v, 0));
},
});