diff --git a/lib/watchaggregator/aggregator.go b/lib/watchaggregator/aggregator.go index 057cd1ef6..4b4ee041c 100644 --- a/lib/watchaggregator/aggregator.go +++ b/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 { diff --git a/lib/watchaggregator/aggregator_test.go b/lib/watchaggregator/aggregator_test.go index c13020219..25483781a 100644 --- a/lib/watchaggregator/aggregator_test.go +++ b/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)