Log water mark for incoming queue in cacher

This commit is contained in:
Wojciech Tyczynski
2016-09-08 16:33:12 +02:00
parent bf9a62035d
commit 03a23aed09
5 changed files with 62 additions and 55 deletions

View File

@@ -16,7 +16,11 @@ limitations under the License.
package storage
import "testing"
import (
"math/rand"
"sync"
"testing"
)
func TestEtcdParseWatchResourceVersion(t *testing.T) {
testCases := []struct {
@@ -99,3 +103,34 @@ func TestHasPathPrefix(t *testing.T) {
}
}
}
func TestHighWaterMark(t *testing.T) {
var h HighWaterMark
for i := int64(10); i < 20; i++ {
if !h.Update(i) {
t.Errorf("unexpected false for %v", i)
}
if h.Update(i - 1) {
t.Errorf("unexpected true for %v", i-1)
}
}
m := int64(0)
wg := sync.WaitGroup{}
for i := 0; i < 300; i++ {
wg.Add(1)
v := rand.Int63()
go func(v int64) {
defer wg.Done()
h.Update(v)
}(v)
if v > m {
m = v
}
}
wg.Wait()
if m != int64(h) {
t.Errorf("unexpected value, wanted %v, got %v", m, int64(h))
}
}