test(scanner): fix flaky Windows search_normalized rescan test (#5758)

The 'repopulates a stale search_normalized on a full rescan' spec runs
two full scans back-to-back. Whether the second scan refreshes the
unchanged artist depends on folderEntry.isOutdated(), which compares
folder.updated_at (written during the first scan) against the second
scan's library.last_scan_started_at using a strict time.Before(). Both
are time.Now() values captured milliseconds apart.

On Linux's fine-grained clock they are always distinct, so the test
passes. On Windows the coarse wall-clock granularity frequently makes
the two timestamps land in the same tick and compare equal, so
Before() returns false, the folder is treated as up-to-date and
skipped, the artist is never re-persisted, and search_normalized stays
empty -- failing the assertion intermittently across unrelated PRs.

Backdate the folder's updated_at an hour before the second scan so the
comparison is unambiguous on every platform. This is a test-only
timing artifact (real rescans never run milliseconds apart on an
unchanged library), so no production code changes are needed.
This commit is contained in:
Deluan Quintão 2026-07-10 18:43:31 -04:00 committed by GitHub
parent 7fa13761d7
commit 116a440718
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@ import (
"errors"
"path/filepath"
"testing/fstest"
"time"
"github.com/Masterminds/squirrel"
"github.com/google/uuid"
@ -212,6 +213,15 @@ var _ = Describe("Scanner", Ordered, func() {
_, err := db.Db().ExecContext(ctx, "UPDATE artist SET search_normalized = '' WHERE name = 'GØGGS'")
Expect(err).ToNot(HaveOccurred())
// Backdate the folder so the next full scan reliably sees it as outdated.
// isOutdated() compares folder.updated_at (written by this scan) against the
// next scan's last_scan_started_at with a strict Before(); back-to-back scans
// can capture both within one clock tick on Windows (coarse wall-clock), making
// the refresh flaky. Backdating forces the comparison to be unambiguous.
_, err = db.Db().ExecContext(ctx,
"UPDATE folder SET updated_at = ?", time.Now().Add(-time.Hour))
Expect(err).ToNot(HaveOccurred())
Expect(runScanner(ctx, true)).To(Succeed())
Expect(searchNormalized()).To(Equal("GOGGS"))
})