Browse Source

lib/watchaggregator: Don't delay mixed events only (#5094)

Also fix a minor bug in testing failure output.
Simon Frei 7 years ago
parent
commit
c55c0c8c28
2 changed files with 21 additions and 4 deletions
  1. 2 2
      lib/watchaggregator/aggregator.go
  2. 19 2
      lib/watchaggregator/aggregator_test.go

+ 2 - 2
lib/watchaggregator/aggregator.go

@@ -308,8 +308,8 @@ func (a *aggregator) actOnTimer(out chan<- []string) {
 	}
 	oldEvents := make(map[string]*aggregatedEvent, c)
 	a.popOldEventsTo(oldEvents, a.root, ".", time.Now(), true)
-	if a.notifyDelay != a.notifyTimeout && a.counts[fs.NonRemove]+a.counts[fs.Mixed] == 0 && a.counts[fs.Remove] != 0 {
-		// Only deletion events remaining, no need to delay them additionally
+	if a.notifyDelay != a.notifyTimeout && a.counts[fs.NonRemove] == 0 && a.counts[fs.Remove]+a.counts[fs.Mixed] != 0 {
+		// Only delayed events remaining, no need to delay them additionally
 		a.popOldEventsTo(oldEvents, a.root, ".", time.Now(), false)
 	}
 	if len(oldEvents) == 0 {

+ 19 - 2
lib/watchaggregator/aggregator_test.go

@@ -183,6 +183,23 @@ func TestDelay(t *testing.T) {
 	testScenario(t, "Delay", testCase, expectedBatches)
 }
 
+// TestNoDelay checks that no delay occurs if there are no non-remove events
+func TestNoDelay(t *testing.T) {
+	mixed := "foo"
+	del := "bar"
+	testCase := func(c chan<- fs.Event) {
+		c <- fs.Event{Name: mixed, Type: fs.NonRemove}
+		c <- fs.Event{Name: mixed, Type: fs.Remove}
+		c <- fs.Event{Name: del, Type: fs.Remove}
+	}
+
+	expectedBatches := []expectedBatch{
+		{[][]string{{mixed}, {del}}, 500, 2000},
+	}
+
+	testScenario(t, "NoDelay", testCase, expectedBatches)
+}
+
 func getEventPaths(dir *eventDir, dirPath string, a *aggregator) []string {
 	var paths []string
 	for childName, childDir := range dir.dirs {
@@ -283,10 +300,10 @@ func testAggregatorOutput(t *testing.T, fsWatchChan <-chan []string, expectedBat
 			if innerIndex == 0 {
 				switch {
 				case now < durationMs(expectedBatches[batchIndex].afterMs):
-					t.Errorf("Received batch %d after %v (too soon)", batchIndex+1, elapsedTime)
+					t.Errorf("Received batch %d after %v (too soon)", batchIndex+1, now)
 
 				case now > durationMs(expectedBatches[batchIndex].beforeMs):
-					t.Errorf("Received batch %d after %v (too late)", batchIndex+1, elapsedTime)
+					t.Errorf("Received batch %d after %v (too late)", batchIndex+1, now)
 				}
 			} else if innerTime := now - elapsedTime; innerTime > timeoutWithinBatch {
 				t.Errorf("Receive part %d of batch %d after %v (too late)", innerIndex+1, batchIndex+1, innerTime)