From 1af7c400d11ffb0f7348a48d9de1ea6f970967cf Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 1 Jul 2016 16:48:05 -0700 Subject: [PATCH] compactor: make tests deterministic Fixes #5847 --- compactor/compactor_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compactor/compactor_test.go b/compactor/compactor_test.go index 771013120..3390a24de 100644 --- a/compactor/compactor_test.go +++ b/compactor/compactor_test.go @@ -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 }