From a1d823c2aabeb72ec193b56bc5fcb10ee3e4b675 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Mon, 18 Jul 2016 16:10:14 -0700 Subject: [PATCH] compactor: make event ordering well-defined in TestPeriodicPause Fixes #5847 --- compactor/compactor_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/compactor/compactor_test.go b/compactor/compactor_test.go index 3390a24de..b15f892d0 100644 --- a/compactor/compactor_test.go +++ b/compactor/compactor_test.go @@ -70,11 +70,13 @@ func TestPeriodicPause(t *testing.T) { tb.Run() tb.Pause() + // tb will collect 3 hours of revisions but not compact since paused n := int(time.Hour / checkCompactionInterval) for i := 0; i < 3*n; i++ { - rg.Wait(1) fc.Advance(checkCompactionInterval) + rg.Wait(1) } + // tb ends up waiting for the clock select { case a := <-compactable.Chan(): @@ -82,16 +84,19 @@ func TestPeriodicPause(t *testing.T) { case <-time.After(10 * time.Millisecond): } + // tb resumes to being blocked on the clock tb.Resume() - rg.Wait(1) - fc.Advance(checkCompactionInterval) + // unblock clock, will kick off a compaction at hour 3 + fc.Advance(checkCompactionInterval) a, err := compactable.Wait(1) if err != nil { t.Fatal(err) } - if !reflect.DeepEqual(a[0].Params[0], &pb.CompactionRequest{Revision: int64(2*n) + 2}) { - t.Errorf("compact request = %v, want %v", a[0].Params[0], &pb.CompactionRequest{Revision: int64(2*n) + 2}) + // compact the revision from hour 2 + wreq := &pb.CompactionRequest{Revision: int64(2*n + 1)} + if !reflect.DeepEqual(a[0].Params[0], wreq) { + t.Errorf("compact request = %v, want %v", a[0].Params[0], wreq.Revision) } }