@@ -11,72 +11,72 @@ class RumInjectorMetricsTest extends Specification {
11
11
def statsD = Mock (StatsDClient )
12
12
13
13
@Subject
14
- def healthMetrics = new RumInjectorMetrics (statsD)
14
+ def metrics = new RumInjectorMetrics (statsD)
15
15
16
16
def " test onInjectionSucceed" () {
17
17
setup :
18
18
def latch = new CountDownLatch (1 )
19
- def healthMetrics = new RumInjectorMetrics (new Latched (statsD, latch), 10 , TimeUnit . MILLISECONDS )
20
- healthMetrics . start()
19
+ def metrics = new RumInjectorMetrics (new Latched (statsD, latch), 10 , TimeUnit . MILLISECONDS )
20
+ metrics . start()
21
21
22
22
when :
23
- healthMetrics . onInjectionSucceed()
23
+ metrics . onInjectionSucceed()
24
24
latch. await(5 , TimeUnit . SECONDS )
25
25
26
26
then :
27
27
1 * statsD. count(' rum.injection.succeed' , 1 , _)
28
28
0 * _
29
29
30
30
cleanup :
31
- healthMetrics . close()
31
+ metrics . close()
32
32
}
33
33
34
34
def " test onInjectionFailed" () {
35
35
setup :
36
36
def latch = new CountDownLatch (1 )
37
- def healthMetrics = new RumInjectorMetrics (new Latched (statsD, latch), 10 , TimeUnit . MILLISECONDS )
38
- healthMetrics . start()
37
+ def metrics = new RumInjectorMetrics (new Latched (statsD, latch), 10 , TimeUnit . MILLISECONDS )
38
+ metrics . start()
39
39
40
40
when :
41
- healthMetrics . onInjectionFailed()
41
+ metrics . onInjectionFailed()
42
42
latch. await(5 , TimeUnit . SECONDS )
43
43
44
44
then :
45
45
1 * statsD. count(' rum.injection.failed' , 1 , _)
46
46
0 * _
47
47
48
48
cleanup :
49
- healthMetrics . close()
49
+ metrics . close()
50
50
}
51
51
52
52
def " test onInjectionSkipped" () {
53
53
setup :
54
54
def latch = new CountDownLatch (1 )
55
- def healthMetrics = new RumInjectorMetrics (new Latched (statsD, latch), 10 , TimeUnit . MILLISECONDS )
56
- healthMetrics . start()
55
+ def metrics = new RumInjectorMetrics (new Latched (statsD, latch), 10 , TimeUnit . MILLISECONDS )
56
+ metrics . start()
57
57
58
58
when :
59
- healthMetrics . onInjectionSkipped()
59
+ metrics . onInjectionSkipped()
60
60
latch. await(5 , TimeUnit . SECONDS )
61
61
62
62
then :
63
63
1 * statsD. count(' rum.injection.skipped' , 1 , _)
64
64
0 * _
65
65
66
66
cleanup :
67
- healthMetrics . close()
67
+ metrics . close()
68
68
}
69
69
70
- def " test multiple events" () {
70
+ def " test flushing multiple events" () {
71
71
setup :
72
72
def latch = new CountDownLatch (3 ) // expecting 3 metric types
73
- def healthMetrics = new RumInjectorMetrics (new Latched (statsD, latch), 10 , TimeUnit . MILLISECONDS )
74
- healthMetrics . start()
73
+ def metrics = new RumInjectorMetrics (new Latched (statsD, latch), 10 , TimeUnit . MILLISECONDS )
74
+ metrics . start()
75
75
76
76
when :
77
- healthMetrics . onInjectionSucceed()
78
- healthMetrics . onInjectionFailed()
79
- healthMetrics . onInjectionSkipped()
77
+ metrics . onInjectionSucceed()
78
+ metrics . onInjectionFailed()
79
+ metrics . onInjectionSkipped()
80
80
latch. await(5 , TimeUnit . SECONDS )
81
81
82
82
then :
@@ -86,23 +86,59 @@ class RumInjectorMetricsTest extends Specification {
86
86
0 * _
87
87
88
88
cleanup :
89
- healthMetrics . close()
89
+ metrics . close()
90
90
}
91
91
92
- def " test summary" () {
92
+ def " test that flushing only reports non-zero deltas" () {
93
+ setup :
94
+ def latch = new CountDownLatch (1 ) // expecting only 1 metric call (non-zero delta)
95
+ def metrics = new RumInjectorMetrics (new Latched (statsD, latch), 10 , TimeUnit . MILLISECONDS )
96
+ metrics. start()
97
+
93
98
when :
94
- healthMetrics. onInjectionSucceed()
95
- healthMetrics. onInjectionFailed()
96
- healthMetrics. onInjectionSkipped()
97
- def summary = healthMetrics. summary()
99
+ metrics. onInjectionSucceed()
100
+ metrics. onInjectionSucceed()
101
+ latch. await(5 , TimeUnit . SECONDS )
98
102
99
103
then :
100
- summary. contains(" injectionSucceed=1" )
101
- summary. contains(" injectionFailed=1" )
104
+ 1 * statsD. count(' rum.injection.succeed' , 2 , _)
105
+ // should not be called since they have delta of 0
106
+ 0 * statsD. count(' rum.injection.failed' , _, _)
107
+ 0 * statsD. count(' rum.injection.skipped' , _, _)
108
+ 0 * _
109
+
110
+ cleanup :
111
+ metrics. close()
112
+ }
113
+
114
+ def " test summary with multiple events" () {
115
+ when :
116
+ metrics. onInjectionSucceed()
117
+ metrics. onInjectionFailed()
118
+ metrics. onInjectionSucceed()
119
+ metrics. onInjectionFailed()
120
+ metrics. onInjectionSucceed()
121
+ metrics. onInjectionSkipped()
122
+ def summary = metrics. summary()
123
+
124
+ then :
125
+ summary. contains(" injectionSucceed=3" )
126
+ summary. contains(" injectionFailed=2" )
102
127
summary. contains(" injectionSkipped=1" )
103
128
0 * _
104
129
}
105
130
131
+ def " test metrics start at zero" () {
132
+ when :
133
+ def summary = metrics. summary()
134
+
135
+ then :
136
+ summary. contains(" injectionSucceed=0" )
137
+ summary. contains(" injectionFailed=0" )
138
+ summary. contains(" injectionSkipped=0" )
139
+ 0 * _
140
+ }
141
+
106
142
// taken from HealthMetricsTest
107
143
private static class Latched implements StatsDClient {
108
144
final StatsDClient delegate
0 commit comments