From 352c506228f2451d8f40259155b633796b5383e4 Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Wed, 26 Nov 2025 13:41:39 +0300 Subject: [PATCH 1/3] fix watcher --- plugin/input/file/watcher.go | 2 +- plugin/input/file/watcher_test.go | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugin/input/file/watcher.go b/plugin/input/file/watcher.go index b7f2a3e30..89d220768 100644 --- a/plugin/input/file/watcher.go +++ b/plugin/input/file/watcher.go @@ -150,7 +150,7 @@ func (w *watcher) notify(e notify.Event, path string) { return } - w.logger.Infof("notify %s %s", e, path) + w.logger.Debugf("notify %s %s", e, path) for _, pattern := range w.paths.Exclude { match, err := doublestar.PathMatch(pattern, path) diff --git a/plugin/input/file/watcher_test.go b/plugin/input/file/watcher_test.go index 1dc000d9f..54e6885a7 100644 --- a/plugin/input/file/watcher_test.go +++ b/plugin/input/file/watcher_test.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "strings" + "sync" "testing" "time" @@ -32,7 +33,9 @@ func TestWatcher(t *testing.T) { t.Run(tt.name, func(t *testing.T) { dir := t.TempDir() shouldCreate := atomic.Int64{} + var wg sync.WaitGroup notifyFn := func(_ notify.Event, _ string, _ os.FileInfo) { + defer wg.Done() shouldCreate.Inc() } ctl := metric.NewCtl("test", prometheus.NewRegistry(), time.Minute, 0) @@ -67,8 +70,7 @@ func TestWatcher(t *testing.T) { require.NoError(t, err) err = f2.Close() require.NoError(t, err) - - time.Sleep(10 * time.Millisecond) + wg.Add(1) f1, err = os.OpenFile(f1Name, os.O_WRONLY, 0o600) require.NoError(t, err) @@ -77,13 +79,11 @@ func TestWatcher(t *testing.T) { err = f1.Close() require.NoError(t, err) - time.Sleep(10 * time.Millisecond) - err = os.Remove(f1Name) require.NoError(t, err) + wg.Add(1) - time.Sleep(10 * time.Millisecond) - + wg.Wait() require.Equal(t, int64(2), shouldCreate.Load()) }) } @@ -193,7 +193,10 @@ func TestWatcherPaths(t *testing.T) { time.Sleep(10 * time.Millisecond) before := shouldCreate.Load() - w.notify(notify.Create, filename) + + resolvedFilename, err := resolvePathLinks(filename) + require.NoError(t, err) + w.notify(notify.Create, resolvedFilename) after := shouldCreate.Load() isNotified := after-before != 0 @@ -216,9 +219,9 @@ func TestCommonPathPrefix(t *testing.T) { func TestResolvePathLinks(t *testing.T) { a := assert.New(t) - originalDir := t.TempDir() + originalDir, _ := resolvePathLinks(t.TempDir()) - dirWithLink := t.TempDir() + dirWithLink, _ := resolvePathLinks(t.TempDir()) dirLink := filepath.Join(dirWithLink, "symlink") err := os.Symlink(originalDir, dirLink) if err != nil { From 4392e05e47075068bc291cd349af28a2d6cc962b Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Fri, 28 Nov 2025 10:30:02 +0300 Subject: [PATCH 2/3] fix watcher test --- .github/workflows/ci.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bdbd4a08b..47759462f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,21 @@ jobs: GOFLAGS: ${{ matrix.flags }} LOG_LEVEL: error run: | - go test -coverprofile=profile${{ matrix.flags }}.out -covermode=atomic -v -coverpkg=./... ./... -json | tee test-report${{ matrix.flags }}.json + go test -coverprofile=profile${{ matrix.flags }}.out -covermode=atomic -coverpkg=./... ./... -json 2>&1 | tee test-report${{ matrix.flags }}.json + TEST_EXIT_CODE=${PIPESTATUS[0]} + exit $TEST_EXIT_CODE + + - name: Fix Test Report + if: always() + run: | + if [ -f test-report${{ matrix.flags }}.json ]; then + # Add final event if missing + if ! tail -1 test-report${{ matrix.flags }}.json | grep -q '"Action":"end"'; then + echo '{"Time":"'$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")'","Action":"end","Package":".","Elapsed":0}' >> test-report${{ matrix.flags }}.json + fi + else + echo '{"Time":"'$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")'","Action":"end","Package":".","Elapsed":0}' > test-report${{ matrix.flags }}.json + fi - name: Coverage report run: | @@ -101,7 +115,9 @@ jobs: GOFLAGS: ${{ matrix.flags }} LOG_LEVEL: error run: | - go test ./e2e -coverprofile=profile-e2e${{ matrix.flags }}.out -covermode=atomic -tags=e2e_new -timeout=3m -coverpkg=./... -json | tee test-report-e2e${{ matrix.flags }}.json + go test ./e2e -coverprofile=profile-e2e${{ matrix.flags }}.out -covermode=atomic -tags=e2e_new -timeout=3m -coverpkg=./... -json 2>&1 | tee test-report-e2e${{ matrix.flags }}.json + TEST_EXIT_CODE=${PIPESTATUS[0]} + exit $TEST_EXIT_CODE - name: Coverage report run: | From 13f9213e1f12e3379e20decb8a48f10b0ab2ae6a Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Mon, 22 Jun 2026 14:05:49 +0700 Subject: [PATCH 3/3] Revert "fix watcher test" This reverts commit 4392e05e47075068bc291cd349af28a2d6cc962b. --- .github/workflows/ci.yml | 20 ++------------------ plugin/input/file/watcher_test.go | 2 ++ 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 47759462f..bdbd4a08b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,21 +35,7 @@ jobs: GOFLAGS: ${{ matrix.flags }} LOG_LEVEL: error run: | - go test -coverprofile=profile${{ matrix.flags }}.out -covermode=atomic -coverpkg=./... ./... -json 2>&1 | tee test-report${{ matrix.flags }}.json - TEST_EXIT_CODE=${PIPESTATUS[0]} - exit $TEST_EXIT_CODE - - - name: Fix Test Report - if: always() - run: | - if [ -f test-report${{ matrix.flags }}.json ]; then - # Add final event if missing - if ! tail -1 test-report${{ matrix.flags }}.json | grep -q '"Action":"end"'; then - echo '{"Time":"'$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")'","Action":"end","Package":".","Elapsed":0}' >> test-report${{ matrix.flags }}.json - fi - else - echo '{"Time":"'$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")'","Action":"end","Package":".","Elapsed":0}' > test-report${{ matrix.flags }}.json - fi + go test -coverprofile=profile${{ matrix.flags }}.out -covermode=atomic -v -coverpkg=./... ./... -json | tee test-report${{ matrix.flags }}.json - name: Coverage report run: | @@ -115,9 +101,7 @@ jobs: GOFLAGS: ${{ matrix.flags }} LOG_LEVEL: error run: | - go test ./e2e -coverprofile=profile-e2e${{ matrix.flags }}.out -covermode=atomic -tags=e2e_new -timeout=3m -coverpkg=./... -json 2>&1 | tee test-report-e2e${{ matrix.flags }}.json - TEST_EXIT_CODE=${PIPESTATUS[0]} - exit $TEST_EXIT_CODE + go test ./e2e -coverprofile=profile-e2e${{ matrix.flags }}.out -covermode=atomic -tags=e2e_new -timeout=3m -coverpkg=./... -json | tee test-report-e2e${{ matrix.flags }}.json - name: Coverage report run: | diff --git a/plugin/input/file/watcher_test.go b/plugin/input/file/watcher_test.go index 54e6885a7..6be18a212 100644 --- a/plugin/input/file/watcher_test.go +++ b/plugin/input/file/watcher_test.go @@ -65,12 +65,14 @@ func TestWatcher(t *testing.T) { require.NoError(t, err) err = f1.Close() require.NoError(t, err) + wg.Add(1) f2, err := os.Create(filepath.Join(dir, "watch2.log")) require.NoError(t, err) err = f2.Close() require.NoError(t, err) wg.Add(1) + wg.Wait() f1, err = os.OpenFile(f1Name, os.O_WRONLY, 0o600) require.NoError(t, err)