Adds benchmark test

This commit is contained in:
Andy Lindeman 2017-04-27 23:26:05 -04:00
parent 2c8a156579
commit 21ca6c498a
No known key found for this signature in database
GPG Key ID: DF5317422B93F579

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 {