fix(playevents): a late offline replay no longer closes the play that is live now (#8074)
RecordOfflinePlay auto-closed whatever play was open at the replayed play's original, often hours-old, time. When Android drained its offline queue while the next song was already playing, each replay ended the live row before it began, as a zero-length skip. That stuck when the live play's own close was lost, and for a Subsonic app's now-playing row it became a skip plus a second play. autoClosePriorOpen now leaves open any row that started after the time it was asked to close at, for every caller; #8019's guard for the Subsonic path moves into it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -585,3 +585,26 @@ func TestRecordOfflinePlay_StampsForYouPickKind(t *testing.T) {
|
||||
t.Errorf("pick_kind = %v, want taste", pickKind)
|
||||
}
|
||||
}
|
||||
|
||||
// An offline play replayed while another song is playing live leaves the
|
||||
// live play open: closing it at the replay's older time would end it before
|
||||
// it began, as a zero-length skip.
|
||||
func TestRecordOfflinePlay_LeavesALaterLivePlayOpen(t *testing.T) {
|
||||
f := newFixture(t, 200_000)
|
||||
ctx := context.Background()
|
||||
now := time.Now().UTC()
|
||||
live, err := f.w.RecordPlayStarted(ctx, f.user, f.track, "c", now)
|
||||
if err != nil {
|
||||
t.Fatalf("live start: %v", err)
|
||||
}
|
||||
if err := f.w.RecordOfflinePlay(ctx, f.user, f.track, "c", "", "", now.Add(-2*time.Hour), 120_000); err != nil {
|
||||
t.Fatalf("offline replay: %v", err)
|
||||
}
|
||||
var ended pgtype.Timestamptz
|
||||
if err := f.pool.QueryRow(ctx, "SELECT ended_at FROM play_events WHERE id = $1", live.PlayEventID).Scan(&ended); err != nil {
|
||||
t.Fatalf("read live play: %v", err)
|
||||
}
|
||||
if ended.Valid {
|
||||
t.Fatalf("the live play was closed at %v by an older replay", ended.Time)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user