mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
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:
parent
7fa13761d7
commit
116a440718
@ -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"))
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user