test(backup, scrobble, playevents, recsettings, apierror, auth, providers): merge repeated cases (#8299)
release / web (push) Successful in 1m41s
release / go (push) Successful in 2m4s
release / govulncheck (push) Successful in 23s
release / integration (push) Successful in 3m5s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 4m35s
release / Build signed APK (push) Canceled after 3m53s
release / web (push) Successful in 1m41s
release / go (push) Successful in 2m4s
release / govulncheck (push) Successful in 23s
release / integration (push) Successful in 3m5s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 4m35s
release / Build signed APK (push) Canceled after 3m53s
- backup: schema coverage's three tests and the three AWS signing examples, one table each. - scrobble: Qualifies' six boundary tests; the ListenBrainz client's refusal mapping, twelve tests of the same rule across three calls, one table over call x status; the two similarity lookups' success and URL tests, one table. - playevents: the skip rule's three plays share one fixture. Dropped TestRecordPlayEnded_SubThreshold_NoEnqueue: the writer only calls scrobble.MaybeEnqueue, whose own test and Qualifies' table hold that case; the qualifying-play test still proves the writer calls it. - recsettings: the three tag-scale tests share one database reset. - apierror: Error() and From, one test each; auth: RequireAdmin's three. - providers: GetJSON's not-found and transient answers, one table. Its two 401 tests expected the same answer with and without TreatAuthAsTransient, which changes only the error's text; the table says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -138,61 +138,41 @@ func TestRecordPlayStarted_AutoCloseCapsAtTrackDuration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordPlayEnded_AppliesSkipRule_BothFail_NotSkip(t *testing.T) {
|
||||
f := newFixture(t, 200_000)
|
||||
t1 := time.Now().UTC()
|
||||
res, _ := f.w.RecordPlayStarted(context.Background(), f.user, f.track, "c", t1)
|
||||
// 15% completion (30_000ms), 30s duration -> 30s satisfies "duration >= 30s"
|
||||
// so the rule's AND fails -> NOT a skip.
|
||||
t2 := t1.Add(30 * time.Second)
|
||||
if err := f.w.RecordPlayEnded(context.Background(), res.PlayEventID, 30_000, t2); err != nil {
|
||||
t.Fatalf("RecordPlayEnded: %v", err)
|
||||
// A play that ends is a skip only when it played under half the track AND
|
||||
// under 30 seconds (the writer's thresholds here, 0.5 and 30000 ms), and
|
||||
// only a skip writes a skip_events row. Either condition alone is a play.
|
||||
func TestRecordPlayEnded_AppliesTheSkipRule(t *testing.T) {
|
||||
f := newFixture(t, 200_000) // a 200 s track
|
||||
ctx := context.Background()
|
||||
t0 := time.Now().UTC().Add(-time.Hour)
|
||||
for i, tc := range []struct {
|
||||
name string
|
||||
playedMs int32
|
||||
want bool
|
||||
}{
|
||||
{"10 s, 5%: both under", 10_000, true},
|
||||
{"30 s, 15%: the duration reaches 30 s", 30_000, false},
|
||||
{"100 s, 50%: the completion reaches half", 100_000, false},
|
||||
} {
|
||||
start := t0.Add(time.Duration(i) * 10 * time.Minute)
|
||||
res, err := f.w.RecordPlayStarted(ctx, f.user, f.track, "c", start)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: start: %v", tc.name, err)
|
||||
}
|
||||
if err := f.w.RecordPlayEnded(ctx, res.PlayEventID, tc.playedMs, start.Add(time.Duration(tc.playedMs)*time.Millisecond)); err != nil {
|
||||
t.Fatalf("%s: end: %v", tc.name, err)
|
||||
}
|
||||
got, _ := f.q.GetPlayEventByID(ctx, res.PlayEventID)
|
||||
if got.WasSkipped != tc.want {
|
||||
t.Errorf("%s: was_skipped = %v, want %v", tc.name, got.WasSkipped, tc.want)
|
||||
}
|
||||
}
|
||||
got, _ := f.q.GetPlayEventByID(context.Background(), res.PlayEventID)
|
||||
if got.WasSkipped {
|
||||
t.Errorf("was_skipped = true, want false (duration_played_ms == 30000 fails the AND)")
|
||||
var skips int
|
||||
if err := f.pool.QueryRow(ctx, `SELECT count(*) FROM skip_events WHERE user_id = $1`, f.user).Scan(&skips); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordPlayEnded_AppliesSkipRule_BothPass_IsSkip(t *testing.T) {
|
||||
f := newFixture(t, 200_000)
|
||||
t1 := time.Now().UTC()
|
||||
res, _ := f.w.RecordPlayStarted(context.Background(), f.user, f.track, "c", t1)
|
||||
// 5% completion (10_000ms), 10s duration -> both conditions hold -> SKIP.
|
||||
t2 := t1.Add(10 * time.Second)
|
||||
if err := f.w.RecordPlayEnded(context.Background(), res.PlayEventID, 10_000, t2); err != nil {
|
||||
t.Fatalf("RecordPlayEnded: %v", err)
|
||||
}
|
||||
got, _ := f.q.GetPlayEventByID(context.Background(), res.PlayEventID)
|
||||
if !got.WasSkipped {
|
||||
t.Errorf("expected was_skipped=true")
|
||||
}
|
||||
rows, err := f.pool.Query(context.Background(),
|
||||
"SELECT id FROM skip_events WHERE user_id=$1 AND track_id=$2", f.user, f.track)
|
||||
if err != nil {
|
||||
t.Fatalf("query skips: %v", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
count := 0
|
||||
for rows.Next() {
|
||||
count++
|
||||
}
|
||||
if count != 1 {
|
||||
t.Errorf("skip_events count = %d, want 1", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordPlayEnded_DurationOver50Percent_NotSkip(t *testing.T) {
|
||||
f := newFixture(t, 200_000) // 200s track
|
||||
t1 := time.Now().UTC()
|
||||
res, _ := f.w.RecordPlayStarted(context.Background(), f.user, f.track, "c", t1)
|
||||
// 50% completion (100_000ms), 5s duration. Completion fails the "< 0.5"
|
||||
// check — so AND fails, NOT a skip.
|
||||
t2 := t1.Add(5 * time.Second)
|
||||
_ = f.w.RecordPlayEnded(context.Background(), res.PlayEventID, 100_000, t2)
|
||||
got, _ := f.q.GetPlayEventByID(context.Background(), res.PlayEventID)
|
||||
if got.WasSkipped {
|
||||
t.Errorf("expected was_skipped=false at completion >= 0.5")
|
||||
if skips != 1 {
|
||||
t.Errorf("skip_events rows = %d, want 1, for the one skip", skips)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,31 +372,6 @@ func TestRecordPlayEnded_QualifyingPlay_EnqueuesScrobble(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordPlayEnded_SubThreshold_NoEnqueue(t *testing.T) {
|
||||
f := newFixture(t, 300_000)
|
||||
ctx := context.Background()
|
||||
|
||||
tk := "tk"
|
||||
_ = f.q.SetListenBrainzToken(ctx, dbq.SetListenBrainzTokenParams{ID: f.user, ListenbrainzToken: &tk})
|
||||
_ = f.q.SetListenBrainzEnabled(ctx, dbq.SetListenBrainzEnabledParams{ID: f.user, ListenbrainzEnabled: true})
|
||||
|
||||
res, err := f.w.RecordPlayStarted(ctx, f.user, f.track, "test", time.Now().Add(-1*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("start: %v", err)
|
||||
}
|
||||
// 60s played, 20% — well below threshold.
|
||||
if err := f.w.RecordPlayEnded(ctx, res.PlayEventID, 60_000, time.Now()); err != nil {
|
||||
t.Fatalf("end: %v", err)
|
||||
}
|
||||
|
||||
var n int
|
||||
_ = f.pool.QueryRow(ctx,
|
||||
`SELECT count(*) FROM scrobble_queue WHERE play_event_id = $1`, res.PlayEventID).Scan(&n)
|
||||
if n != 0 {
|
||||
t.Errorf("expected 0 queue rows for sub-threshold play, got %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecordPlayStartedWithSource_AppendsRotation(t *testing.T) {
|
||||
f := newFixture(t, 200_000)
|
||||
now := time.Now().UTC()
|
||||
|
||||
Reference in New Issue
Block a user