fix(scrobble): plays that can't be sent no longer block ListenBrainz for everyone (#8103)
The worker skipped a queued play whose account had since switched ListenBrainz off, or whose token couldn't be read, and left it pending. The batch is the oldest fifty pending rows, so skipped rows came back first on every tick, and fifty of them stopped scrobbling for every account. They are now marked failed with the reason. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -222,3 +222,26 @@ func TestWorker_BatchOfTen_OnePost(t *testing.T) {
|
||||
t.Errorf("LB POSTs = %d, want 1 (batch)", posts.Load())
|
||||
}
|
||||
}
|
||||
|
||||
// A queued play whose account has since switched ListenBrainz off is marked
|
||||
// failed, not left pending: left pending it heads the queue on every tick.
|
||||
func TestWorker_ListenBrainzSwitchedOff_MarksFailedInsteadOfBlockingTheQueue(t *testing.T) {
|
||||
s := seed(t, seedOpts{lbToken: "tk", lbEnabled: false, durationMs: 250_000, ratio: 0.83})
|
||||
helperEnqueue(t, s)
|
||||
var posts atomic.Int32
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
posts.Add(1)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer srv.Close()
|
||||
lb := &listenbrainz.Client{BaseURL: srv.URL, HTTP: srv.Client()}
|
||||
if err := newTestWorker(s, lb).tickOnce(context.Background()); err != nil {
|
||||
t.Fatalf("tickOnce: %v", err)
|
||||
}
|
||||
if helperPendingCount(t, s) != 0 || helperFailedCount(t, s) != 1 {
|
||||
t.Fatalf("pending %d failed %d, want the row marked failed", helperPendingCount(t, s), helperFailedCount(t, s))
|
||||
}
|
||||
if posts.Load() != 0 {
|
||||
t.Error("a play was sent for an account with ListenBrainz off")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user