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