Adds benchmark test

Kubernetes-commit: 21ca6c498aec2879fd7b9796f55743e5f14d5a80
This commit is contained in:
Andy Lindeman 2017-04-27 23:26:05 -04:00 committed by Kubernetes Publisher
parent 1bf81ae841
commit fe9ac9f9c0

View File

@ -18,6 +18,7 @@ package workqueue
import (
"fmt"
"math/rand"
"reflect"
"testing"
"time"
@ -214,6 +215,25 @@ func TestCopyShifting(t *testing.T) {
}
}
func BenchmarkDelayingQueue_AddAfter(b *testing.B) {
r := rand.New(rand.NewSource(time.Now().Unix()))
fakeClock := clock.NewFakeClock(time.Now())
q := newDelayingQueue(fakeClock, "")
// Add items
for n := 0; n < b.N; n++ {
data := fmt.Sprintf("%d", n)
q.AddAfter(data, time.Duration(r.Int63n(int64(10*time.Minute))))
}
// Exercise item removal as well
fakeClock.Step(11 * time.Minute)
for n := 0; n < b.N; n++ {
_, _ = q.Get()
}
}
func waitForAdded(q DelayingInterface, depth int) error {
return wait.Poll(1*time.Millisecond, 10*time.Second, func() (done bool, err error) {
if q.Len() == depth {