release / go (push) Successful in 2m28s
release / web (push) Successful in 1m42s
release / govulncheck (push) Successful in 23s
release / integration (push) Successful in 5m9s
release / android (push) Successful in 5m28s
release / Build signed APK (push) Successful in 5m54s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 34s
release / Verify release artifacts (tag releases only) (push) Skipped
Other programs file music into the library now, and a startup pass
deleted a whole album a download manager had just filed, keeping older
loose copies of the same songs. The resolver assumed Minstrel was the
only program writing the library; it is not.
An automatic pass now changes only Minstrel's database:
- copies of one song, on one album or across releases, are linked as one
song, so likes, plays and mixes count it once, and any group an admin
may want to thin stays pending for review (and is announced);
- distinct versions are still dismissed, and rips still held back;
- a one-album wrong slot gets a note naming the song MusicBrainz or
AcoustID says the recording is, for the admin who settles it.
Removing a copy is an admin's merge or wrong-slot settle, as before. When
an admin merges, a copy in a folder named for its album ("Album (Year)",
or its "CD nn" folder) now outranks a loose copy of the same audio.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package library
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"log/slog"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/dbtest"
|
|
)
|
|
|
|
// A gate is taken by one holder at a time; a waiter gets it once the holder
|
|
// lets go, and gives up when its context ends or its limit passes.
|
|
func TestGate_OneHolderAndAWaiterThatCanGiveUp(t *testing.T) {
|
|
g := make(gate, 1)
|
|
if !g.tryAcquire() {
|
|
t.Fatal("an empty gate could not be taken")
|
|
}
|
|
if g.tryAcquire() {
|
|
t.Fatal("a held gate was taken a second time")
|
|
}
|
|
if err := g.acquire(context.Background(), 20*time.Millisecond); !errors.Is(err, errFilesBusy) {
|
|
t.Errorf("waiting past the limit: %v, want errFilesBusy", err)
|
|
}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
if err := g.acquire(ctx, time.Minute); !errors.Is(err, context.Canceled) {
|
|
t.Errorf("waiting with an ended context: %v, want context.Canceled", err)
|
|
}
|
|
|
|
got := make(chan error, 1)
|
|
go func() { got <- g.acquire(context.Background(), time.Minute) }()
|
|
select {
|
|
case err := <-got:
|
|
t.Fatalf("a waiter got a held gate: %v", err)
|
|
case <-time.After(50 * time.Millisecond):
|
|
}
|
|
g.release()
|
|
select {
|
|
case err := <-got:
|
|
if err != nil {
|
|
t.Errorf("a waiter after release: %v", err)
|
|
}
|
|
case <-time.After(5 * time.Second):
|
|
t.Fatal("a waiter did not get the gate once it was released")
|
|
}
|
|
}
|
|
|
|
// A scan that starts while a duplicate-resolver pass holds the files reads
|
|
// none of them until the pass lets go, so the pass never decides from a
|
|
// library half-read.
|
|
func TestScanner_WaitsForAPassHoldingTheFiles_Integration(t *testing.T) {
|
|
ctx := context.Background()
|
|
pool := dbtest.Open(t)
|
|
if _, err := pool.Exec(ctx, "TRUNCATE tracks, albums, artists RESTART IDENTITY CASCADE"); err != nil {
|
|
t.Fatalf("truncate: %v", err)
|
|
}
|
|
root := t.TempDir()
|
|
writeTestMP3(t, filepath.Join(root, "Tin Orchard/Dusk/01.mp3"), map[string]string{
|
|
"TIT2": "Dusk", "TPE1": "Tin Orchard", "TALB": "Dusk", "TRCK": "1",
|
|
})
|
|
scanner := New(pool, slog.New(slog.NewTextHandler(io.Discard, nil)), []string{root}, nil)
|
|
|
|
if !filesGate.tryAcquire() {
|
|
t.Fatal("the files gate was already held")
|
|
}
|
|
type result struct {
|
|
stats Stats
|
|
err error
|
|
}
|
|
done := make(chan result, 1)
|
|
go func() {
|
|
stats, err := scanner.Scan(ctx, nil)
|
|
done <- result{stats, err}
|
|
}()
|
|
select {
|
|
case r := <-done:
|
|
filesGate.release()
|
|
t.Fatalf("the scan ran while a pass held the files: %+v, %v", r.stats, r.err)
|
|
case <-time.After(200 * time.Millisecond):
|
|
}
|
|
filesGate.release()
|
|
select {
|
|
case r := <-done:
|
|
if r.err != nil || r.stats.Added != 1 {
|
|
t.Errorf("scan after the pass: %+v, %v; want one song added", r.stats, r.err)
|
|
}
|
|
case <-time.After(30 * time.Second):
|
|
t.Fatal("the scan did not run once the pass let go of the files")
|
|
}
|
|
}
|