Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions internal/jobs/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,23 @@ func TestQueueReconcileConst(t *testing.T) {
t.Errorf("queueReconcile = %q; want %q. River queue names are referenced as plain strings from periodic-job InsertOpts; renaming this without updating the matching QueueConfig entry in workers.go reintroduces the starvation bug.", queueReconcile, "reconcile")
}
}

// TestReconcileInsertOpts_BindsToReconcileQueue verifies the helper that
// every reconciler periodic-job closure calls returns an InsertOpts whose
// Queue matches the dedicated queue name. This is the behavior guard —
// TestQueueReconcileConst above checks the const alone, but a typo could
// still route closures to a different queue if the InsertOpts struct
// literal was edited in isolation. With the helper, periodic-job builders
// share a single call site that this test exercises directly.
func TestReconcileInsertOpts_BindsToReconcileQueue(t *testing.T) {
opts := reconcileInsertOpts()
if opts == nil {
t.Fatal("reconcileInsertOpts() returned nil — closures would default to QueueDefault, reintroducing starvation")
}
if opts.Queue != queueReconcile {
t.Errorf("reconcileInsertOpts().Queue = %q; want %q. The helper is meant to keep reconcilers off the default queue — if it drifts, the deploy_status_reconcile starvation bug returns.", opts.Queue, queueReconcile)
}
if opts.Queue != "reconcile" {
t.Errorf("reconcileInsertOpts().Queue resolved to %q; the dedicated queue config in workers.go is keyed by the literal \"reconcile\", so the helper must produce that string verbatim.", opts.Queue)
}
}
11 changes: 9 additions & 2 deletions internal/jobs/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ import (
// worker slot.
const queueReconcile = "reconcile"

// reconcileInsertOpts is the InsertOpts every reconciler periodic-job builder
// must return. Extracted so a test can exercise the exact production value
// (asserting the closures embed the right Queue) without scraping source code.
func reconcileInsertOpts() *river.InsertOpts {
return &river.InsertOpts{Queue: queueReconcile}
}

// Workers wraps a running River client.
type Workers struct {
client *river.Client[pgx.Tx]
Expand Down Expand Up @@ -187,7 +194,7 @@ func StartWorkers(ctx context.Context, db *sql.DB, rdb *redis.Client, cfg *confi
river.NewPeriodicJob(
river.PeriodicInterval(customDomainReconcileInterval),
func() (river.JobArgs, *river.InsertOpts) {
return CustomDomainReconcileArgs{}, &river.InsertOpts{Queue: queueReconcile}
return CustomDomainReconcileArgs{}, reconcileInsertOpts()
},
&river.PeriodicJobOpts{RunOnStart: true},
),
Expand All @@ -199,7 +206,7 @@ func StartWorkers(ctx context.Context, db *sql.DB, rdb *redis.Client, cfg *confi
river.NewPeriodicJob(
river.PeriodicInterval(deployStatusReconcileInterval),
func() (river.JobArgs, *river.InsertOpts) {
return DeployStatusReconcileArgs{}, &river.InsertOpts{Queue: queueReconcile}
return DeployStatusReconcileArgs{}, reconcileInsertOpts()
},
&river.PeriodicJobOpts{RunOnStart: true},
),
Expand Down