From c658c08fcb455773c3ecb7742d3ce0ef44493d53 Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 19 Aug 2026 23:50:29 -0400 Subject: [PATCH] test(scanner): repair BenchmarkScan so it can actually run The benchmark failed three ways before reaching its first iteration: it reused a shared temp DB and tried to repoint the default library, it never loaded the config defaults so the scanner got a concurrency of 0, and it lacked the notify ignore that the suite already carries. tests.Init now takes a testing.TB so a benchmark can load the test config the same way the suites do. --- scanner/scanner_benchmark_test.go | 11 +++++++++-- tests/init_tests.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/scanner/scanner_benchmark_test.go b/scanner/scanner_benchmark_test.go index ca1064631..97ade09a7 100644 --- a/scanner/scanner_benchmark_test.go +++ b/scanner/scanner_benchmark_test.go @@ -3,7 +3,6 @@ package scanner_test import ( "context" "fmt" - "os" "path/filepath" "runtime" "testing" @@ -21,6 +20,7 @@ import ( "github.com/navidrome/navidrome/persistence" "github.com/navidrome/navidrome/scanner" "github.com/navidrome/navidrome/server/events" + "github.com/navidrome/navidrome/tests" "go.uber.org/goleak" ) @@ -31,10 +31,17 @@ func BenchmarkScan(b *testing.B) { goleak.IgnoreAnyFunction("testing.(*B).doBench"), // Ignore database/sql.(*DB).connectionOpener, as we are not closing the database connection goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"), + // The notify library keeps internal watcher goroutines alive after Stop() + goleak.IgnoreTopFunction("github.com/rjeczalik/notify.(*recursiveTree).dispatch"), ) - tmpDir := os.TempDir() + // Benchmarks run without the suite's TestMain, so the config defaults must be loaded here + tests.Init(b, false) + + tmpDir := b.TempDir() conf.Server.DbPath = filepath.Join(tmpDir, "test-scanner.db?_journal_mode=WAL") + // The default library is seeded from MusicFolder, and its path cannot be changed afterwards + conf.Server.MusicFolder = "fake:///music" db.Init(context.Background()) ds := persistence.New(db.Db()) diff --git a/tests/init_tests.go b/tests/init_tests.go index 582ad95fc..902cf196d 100644 --- a/tests/init_tests.go +++ b/tests/init_tests.go @@ -13,7 +13,7 @@ import ( var once sync.Once -func Init(t *testing.T, skipOnShort bool) { +func Init(t testing.TB, skipOnShort bool) { if skipOnShort && testing.Short() { t.Skip("skipping test in short mode.") }