Skip to content

Commit f6cf484

Browse files
committed
#55 test max_lines_in_buffer
1 parent 6f7d651 commit f6cf484

File tree

2 files changed

+76
-9
lines changed

2 files changed

+76
-9
lines changed

exporter/bufferLoadMetric_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
147212
func synchronousTick(c chan time.Time, f chan struct{}) {
148213
c <- time.Now()
149214
<-f // wait until tick is processed

tailer/lineBuffer_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@ func TestLineBufferParallel(t *testing.T) {
6969
func TestLineBufferClear(t *testing.T) {
7070
buf := NewLineBuffer()
7171
defer buf.Close()
72-
for i := 1; i <= 7; i++ {
73-
buf.Push(&fswatcher.Line{Line: fmt.Sprintf("This is line number %v.", i)})
74-
}
75-
if buf.Len() != 7 {
76-
t.Fatalf("Expected %v lines in buffer, but got %v", 7, buf.Len())
77-
}
78-
buf.Clear()
79-
if buf.Len() != 0 {
80-
t.Fatalf("Expected %v lines in buffer, but got %v", 0, buf.Len())
72+
for linesInBuffer := 0; linesInBuffer < 10; linesInBuffer++ {
73+
for i := 1; i <= linesInBuffer; i++ {
74+
buf.Push(&fswatcher.Line{Line: fmt.Sprintf("This is line number %v of %v.", i, linesInBuffer)})
75+
}
76+
if buf.Len() != linesInBuffer {
77+
t.Fatalf("Expected %v lines in buffer, but got %v", linesInBuffer, buf.Len())
78+
}
79+
buf.Clear()
80+
if buf.Len() != 0 {
81+
t.Fatalf("Expected %v lines in buffer, but got %v", 0, buf.Len())
82+
}
8183
}
8284
}
8385

0 commit comments

Comments
 (0)