diff --git a/buffer.go b/buffer.go index a275dea..8cecfb9 100644 --- a/buffer.go +++ b/buffer.go @@ -56,7 +56,10 @@ func (b *Buffer) Flush() { } go b.fn(sbuffer) + b.Clear() +} +func (b *Buffer) Clear() { b.series = make(map[string]*influxdb.Series) b.size = 0 } diff --git a/buffer_test.go b/buffer_test.go index 4826264..a7ea5af 100644 --- a/buffer_test.go +++ b/buffer_test.go @@ -53,6 +53,21 @@ func TestFlush(t *testing.T) { } } +func TestClear(t *testing.T) { + fn := func(series []*influxdb.Series) {} + b := NewBuffer(10, fn) + defer b.Close() + b.Add(&influxdb.Series{}) + + if b.Size() != 1 { + t.Error("Expected buffer to contain 1 series before clearing, got %d", b.Size()) + } + b.Clear() + if b.Size() != 0 { + t.Error("Expected buffer to be empty after clearing, got %d series", b.Size()) + } +} + func TestLookup(t *testing.T) { fn := func(series []*influxdb.Series) {} b := NewBuffer(10, fn)