release / go (push) Successful in 2m17s
release / web (push) Successful in 1m29s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m28s
release / android (push) Successful in 4m25s
release / Build signed APK (push) Successful in 5m8s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 15s
release / Verify release artifacts (tag releases only) (push) Skipped
The resolver checked for a running scan once, at the start of a pass. At boot that check could run before the startup scan recorded its run, and a scan that began mid-pass was never seen, so the pass removed copies the scan had listed (23 "no such file" errors on dev, 2026-11-28). A gate now keeps the two apart for their whole length: a full scan and each watcher batch hold it, a scan that meets a pass waits for it (up to 30 minutes, then gives up with a named error), and a pass that meets a scan is put off and tried again a minute later. 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"
|
|
|
|
"git.fabledsword.com/bvandeusen/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 no file it lists is removed under
|
|
// it.
|
|
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")
|
|
}
|
|
}
|