compactor: make tests deterministic

Fixes #5847
This commit is contained in:
Anthony Romano 2016-07-01 16:48:05 -07:00
parent 66d195ff75
commit 1af7c400d1

View File

@ -27,11 +27,12 @@ import (
func TestPeriodic(t *testing.T) {
fc := clockwork.NewFakeClock()
rg := &fakeRevGetter{testutil.NewRecorderStream(), 0}
compactable := &fakeCompactable{testutil.NewRecorderStream()}
tb := &Periodic{
clock: fc,
periodInHour: 1,
rg: &fakeRevGetter{},
rg: rg,
c: compactable,
}
@ -41,7 +42,7 @@ func TestPeriodic(t *testing.T) {
n := int(time.Hour / checkCompactionInterval)
for i := 0; i < 3; i++ {
for j := 0; j < n; j++ {
time.Sleep(5 * time.Millisecond)
rg.Wait(1)
fc.Advance(checkCompactionInterval)
}
@ -58,10 +59,11 @@ func TestPeriodic(t *testing.T) {
func TestPeriodicPause(t *testing.T) {
fc := clockwork.NewFakeClock()
compactable := &fakeCompactable{testutil.NewRecorderStream()}
rg := &fakeRevGetter{testutil.NewRecorderStream(), 0}
tb := &Periodic{
clock: fc,
periodInHour: 1,
rg: &fakeRevGetter{},
rg: rg,
c: compactable,
}
@ -70,7 +72,7 @@ func TestPeriodicPause(t *testing.T) {
n := int(time.Hour / checkCompactionInterval)
for i := 0; i < 3*n; i++ {
time.Sleep(5 * time.Millisecond)
rg.Wait(1)
fc.Advance(checkCompactionInterval)
}
@ -81,6 +83,7 @@ func TestPeriodicPause(t *testing.T) {
}
tb.Resume()
rg.Wait(1)
fc.Advance(checkCompactionInterval)
a, err := compactable.Wait(1)
@ -102,10 +105,12 @@ func (fc *fakeCompactable) Compact(ctx context.Context, r *pb.CompactionRequest)
}
type fakeRevGetter struct {
testutil.Recorder
rev int64
}
func (fr *fakeRevGetter) Rev() int64 {
fr.Record(testutil.Action{Name: "g"})
fr.rev++
return fr.rev
}