mirror of
https://github.com/grafana/grafana.git
synced 2025-01-24 15:27:01 -06:00
e6ead667b3
* added pkg/util/rinq package to handle queueing of notifications * fix linters * Fix typo in comment Co-authored-by: Dan Cech <dcech@grafana.com> * improve allocation strategy for Enqueue; remove unnecessary clearing of slice * Update pkg/util/ringq/dyn_chan_bench_test.go Co-authored-by: Dan Cech <dcech@grafana.com> * Update pkg/util/ringq/ringq.go Co-authored-by: Dan Cech <dcech@grafana.com> * refactor to move stats and shrinking into Ring * add missing error assertions in tests * add missing error assertions in tests and linting issues * simplify controller closed check * improve encapsulation of internal state in Ring * use (*Ring).Len for clarity instead of stats --------- Co-authored-by: Dan Cech <dcech@grafana.com>
74 lines
1.1 KiB
Go
74 lines
1.1 KiB
Go
package ring
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkAdaptiveChanBaseline(b *testing.B) {
|
|
in, out, _ := AdaptiveChan[int]()
|
|
in <- 1
|
|
<-out
|
|
b.Cleanup(func() {
|
|
close(in)
|
|
})
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
in <- i
|
|
val := <-out
|
|
if val != i {
|
|
b.Fatalf("expected 1, got %d", val)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkAdaptiveChanWithStatsRead(b *testing.B) {
|
|
var stats AdaptiveChanStats
|
|
in, out, sr := AdaptiveChan[int]()
|
|
in <- 1
|
|
<-out
|
|
ctx := context.Background()
|
|
b.Cleanup(func() {
|
|
close(in)
|
|
})
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
in <- 1
|
|
val := <-out
|
|
if val != 1 {
|
|
b.Fatalf("expected 1, got %d", val)
|
|
}
|
|
err := sr.WriteStats(ctx, &stats)
|
|
if err != nil {
|
|
b.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if stats.Enqueued == 0 {
|
|
b.Fatalf("unexpected stats: %v", stats)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkGoChanBaseline(b *testing.B) {
|
|
c := make(chan int, 1)
|
|
b.Cleanup(func() {
|
|
close(c)
|
|
})
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
c <- 1
|
|
val := <-c
|
|
if val != 1 {
|
|
b.Fatalf("expected 1, got %d", val)
|
|
}
|
|
}
|
|
}
|