Browse Source

Merge pull request #7632 from xiang90/fix_periodic

compactor: fix TestPeriodic
Xiang Li 8 years ago
parent
commit
ca22c4c384
1 changed files with 13 additions and 3 deletions
  1. 13 3
      compactor/compactor_test.go

+ 13 - 3
compactor/compactor_test.go

@@ -42,13 +42,17 @@ func TestPeriodic(t *testing.T) {
 	n := int(time.Hour / checkCompactionInterval)
 	// collect 3 hours of revisions
 	for i := 0; i < 3; i++ {
-		// advance one hour, one revision for each interval
-		for j := 0; j < n; j++ {
-			fc.Advance(checkCompactionInterval)
+		// advance one (hour - checkCompactionInterval), one revision for each interval
+		for j := 0; j < n-1; j++ {
 			_, err := rg.Wait(1)
 			if err != nil {
 				t.Fatal(err)
 			}
+			fc.Advance(checkCompactionInterval)
+		}
+		_, err := rg.Wait(1)
+		if err != nil {
+			t.Fatal(err)
 		}
 		// ready to acknowledge hour "i"
 		// block until compactor calls clock.After()
@@ -63,6 +67,12 @@ func TestPeriodic(t *testing.T) {
 			t.Errorf("compact request = %v, want %v", a[0].Params[0], &pb.CompactionRequest{Revision: int64(i*n) + 1})
 		}
 	}
+
+	// unblock the rev getter, so we can stop the compactor routine.
+	_, err := rg.Wait(1)
+	if err != nil {
+		t.Fatal(err)
+	}
 }
 
 func TestPeriodicPause(t *testing.T) {