mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-23 08:56:31 +01:00
4628deecd1
Thanks to @dxtrzhang for the original idea at https://github.com/VictoriaMetrics/VictoriaMetrics/pull/688 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/689
37 lines
694 B
Go
37 lines
694 B
Go
package leveledbytebufferpool
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestGetPutConcurrent(t *testing.T) {
|
|
const concurrency = 10
|
|
doneCh := make(chan struct{}, concurrency)
|
|
for i := 0; i < concurrency; i++ {
|
|
go func() {
|
|
for capacity := -1; capacity < 100; capacity++ {
|
|
bb := Get(capacity)
|
|
if len(bb.B) > 0 {
|
|
panic(fmt.Errorf("len(bb.B) must be zero; got %d", len(bb.B)))
|
|
}
|
|
if capacity < 0 {
|
|
capacity = 0
|
|
}
|
|
bb.B = append(bb.B, make([]byte, capacity)...)
|
|
Put(bb)
|
|
}
|
|
doneCh <- struct{}{}
|
|
}()
|
|
}
|
|
tc := time.After(10 * time.Second)
|
|
for i := 0; i < concurrency; i++ {
|
|
select {
|
|
case <-tc:
|
|
t.Fatalf("timeout")
|
|
case <-doneCh:
|
|
}
|
|
}
|
|
}
|