@@ -144,6 +144,71 @@ func expectValues(t *testing.T, m *bufferLoadMetric, min15s, min30s, min45s, min
144144 }
145145}
146146
147+ func TestResetBufferLoadMetrics (t * testing.T ) {
148+ m := NewBufferLoadMetric (logrus .New (), false )
149+ c := make (chan time.Time )
150+ tick := & time.Ticker {
151+ C : c ,
152+ }
153+ f := make (chan struct {})
154+ m .start (tick , f )
155+ defer m .Stop ()
156+ defer close (f )
157+
158+ // | 15s | 30s | 45s | 60s
159+ // ----------------------------
160+ // min | 0 | 0 | 0 | 0
161+ // max | 0 | 0 | 0 | 0
162+
163+ m .Inc () // cur = 1
164+ m .Inc () // cur = 2
165+ m .Inc () // cur = 3
166+ m .Inc () // cur = 4
167+ m .Inc () // cur = 5
168+
169+ // | 15s | 30s | 45s | 60s
170+ // ----------------------------
171+ // min | 0 | 0 | 0 | 0
172+ // max | 5 | 5 | 5 | 5
173+
174+ synchronousTick (c , f )
175+ synchronousTick (c , f )
176+ synchronousTick (c , f )
177+ synchronousTick (c , f )
178+
179+ // | 15s | 30s | 45s | 60s
180+ // ----------------------------
181+ // min | 5 | 5 | 5 | 5
182+ // max | 5 | 5 | 5 | 5
183+
184+ m .Set (7 )
185+
186+ // | 15s | 30s | 45s | 60s
187+ // ----------------------------
188+ // min | 5 | 5 | 5 | 5
189+ // max | 7 | 7 | 7 | 7
190+
191+ expectValues (t , m , 5 , 5 , 5 , 5 , 7 , 7 , 7 , 7 )
192+
193+ m .Set (1 )
194+
195+ // | 15s | 30s | 45s | 60s
196+ // ----------------------------
197+ // min | 1 | 1 | 1 | 1
198+ // max | 7 | 7 | 7 | 7
199+
200+ expectValues (t , m , 1 , 1 , 1 , 1 , 7 , 7 , 7 , 7 )
201+
202+ synchronousTick (c , f )
203+
204+ // | 15s | 30s | 45s | 60s
205+ // ----------------------------
206+ // min | 1 | 1 | 1 | 1
207+ // max | 1 | 7 | 7 | 7
208+
209+ expectValues (t , m , 1 , 1 , 1 , 1 , 1 , 7 , 7 , 7 )
210+ }
211+
147212func synchronousTick (c chan time.Time , f chan struct {}) {
148213 c <- time .Now ()
149214 <- f // wait until tick is processed
0 commit comments