fix: bind matcher source to playlist

This commit is contained in:
Josh Creek
2026-09-01 09:35:00 +01:00
parent d0952adaf9
commit e170bcf0ef
4 changed files with 45 additions and 13 deletions
+33 -4
View File
@@ -40,7 +40,9 @@ func workerFor(source CandidateSource, creator ProposalCreator) Worker {
func TestRunOnceDelegatesFinalClaimAndBindsTickets(t *testing.T) {
creator := &creatorSpy{}
worker := workerFor(func(context.Context, time.Time, int) ([]domain.Candidate, error) { return candidates(), nil }, creator)
worker := workerFor(func(context.Context, time.Time, domain.Playlist, int) ([]domain.Candidate, error) {
return candidates(), nil
}, creator)
formed, err := worker.RunOnce(context.Background())
if err != nil || !formed || creator.calls != 1 {
t.Fatalf("formed=%v err=%v calls=%d", formed, err, creator.calls)
@@ -52,13 +54,15 @@ func TestRunOnceDelegatesFinalClaimAndBindsTickets(t *testing.T) {
func TestRunOnceFailsClosedOnSourceOrDurableClaimFailure(t *testing.T) {
creator := &creatorSpy{err: errors.New("serialization conflict")}
worker := workerFor(func(context.Context, time.Time, int) ([]domain.Candidate, error) {
worker := workerFor(func(context.Context, time.Time, domain.Playlist, int) ([]domain.Candidate, error) {
return nil, errors.New("redis unavailable")
}, creator)
if _, err := worker.RunOnce(context.Background()); err == nil {
t.Fatal("source failure was swallowed")
}
worker.Source = func(context.Context, time.Time, int) ([]domain.Candidate, error) { return candidates(), nil }
worker.Source = func(context.Context, time.Time, domain.Playlist, int) ([]domain.Candidate, error) {
return candidates(), nil
}
if _, err := worker.RunOnce(context.Background()); err == nil {
t.Fatal("durable claim failure was swallowed")
}
@@ -69,9 +73,34 @@ func TestRunOnceFailsClosedOnSourceOrDurableClaimFailure(t *testing.T) {
func TestRunOnceDoesNotClaimAnIncompleteBatch(t *testing.T) {
creator := &creatorSpy{}
worker := workerFor(func(context.Context, time.Time, int) ([]domain.Candidate, error) { return candidates()[:3], nil }, creator)
worker := workerFor(func(context.Context, time.Time, domain.Playlist, int) ([]domain.Candidate, error) {
return candidates()[:3], nil
}, creator)
formed, err := worker.RunOnce(context.Background())
if err != nil || formed || creator.calls != 0 {
t.Fatalf("formed=%v err=%v calls=%d", formed, err, creator.calls)
}
}
func TestRunOnceRejectsMixedPlaylistAndDuplicateIdentityBatches(t *testing.T) {
creator := &creatorSpy{}
worker := workerFor(func(_ context.Context, _ time.Time, _ domain.Playlist, _ int) ([]domain.Candidate, error) {
batch := candidates()
batch[1].Playlist = domain.Ranked
return batch, nil
}, creator)
if _, err := worker.RunOnce(context.Background()); err == nil {
t.Fatal("mixed playlist was accepted")
}
worker.Source = func(_ context.Context, _ time.Time, _ domain.Playlist, _ int) ([]domain.Candidate, error) {
batch := candidates()
batch[1].PlayerID = batch[0].PlayerID
return batch, nil
}
if _, err := worker.RunOnce(context.Background()); err == nil {
t.Fatal("duplicate identity was accepted")
}
if creator.calls != 0 {
t.Fatalf("creator calls=%d", creator.calls)
}
}