http_listener input unit tests

This commit is contained in:
Cameron Sparr
2016-10-24 16:15:46 +01:00
parent 097b1e09db
commit c849b58de9
5 changed files with 136 additions and 29 deletions

View File

@@ -14,7 +14,7 @@ type Buffer struct {
// total metrics added
total int
sync.Mutex
mu sync.Mutex
}
// NewBuffer returns a Buffer
@@ -65,13 +65,13 @@ func (b *Buffer) Add(metrics ...telegraf.Metric) {
// the batch will be of maximum length batchSize. It can be less than batchSize,
// if the length of Buffer is less than batchSize.
func (b *Buffer) Batch(batchSize int) []telegraf.Metric {
b.Lock()
b.mu.Lock()
n := min(len(b.buf), batchSize)
out := make([]telegraf.Metric, n)
for i := 0; i < n; i++ {
out[i] = <-b.buf
}
b.Unlock()
b.mu.Unlock()
return out
}