Browse Source

Merge pull request #5978 from heyitsanthony/fix-compactor

compactor: make event ordering well-defined in TestPeriodicPause
Anthony Romano 9 years ago
parent
commit
d914502090
1 changed files with 10 additions and 5 deletions
  1. 10 5
      compactor/compactor_test.go

+ 10 - 5
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)
 	}
 }