Skip to content

[go] Test that insert-time InsertOpts take precedence over JobArgs InsertOpts - #1605

Open
Trenyx wants to merge 1 commit into
riverqueue:masterfrom
Trenyx:test/insert-opts-precedence
Open

Trenyx wants to merge 1 commit into
riverqueue:masterfrom
Trenyx:test/insert-opts-precedence

Conversation

@Trenyx

@Trenyx Trenyx commented Nov 24, 2026

Copy link
Copy Markdown

If the precedence in insertParamsFromConfigArgsAndOptions ever flipped so that a job args type's own InsertOpts() won over the InsertOpts passed to Insert, a job inserted with an explicit Queue would silently land in the args type's default queue instead (and the same for MaxAttempts, Priority and Tags), and no test would notice.

Tests only: one subtest (+18 lines) in client_test.go. No change to library code.

Changes

  • client_test.go: add InsertOptsOverrideWorkerInsertOpts to TestInsertParamsFromJobArgsAndOptions. It passes customInsertOptsJobArgs (whose InsertOpts() sets MaxAttempts: 42, Priority: 2, Queue: "other", tags tag1, tag2) together with insert-time options, and checks the insert-time values win. The existing subtests cover each source on its own, but none passes both at once.

The precedence is documented on InsertOpts ("These will override any default InsertOpts settings provided by JobArgsWithInsertOpts") and on JobArgsWithInsertOpts.InsertOpts ("These can also be overridden at insertion time").

Testing

On master 1f19003:

go test -count=1 -run 'TestInsertParamsFromJobArgsAndOptions' -v .

All subtests pass; this test needs no database.

With the queue line changed to cmp.Or(jobInsertOpts.Queue, insertOpts.Queue, rivercommon.QueueDefault), the new subtest is the only one that fails (expected: "explicit", actual: "other"). In an earlier run of the root module's full suite against Postgres (at fc6c1d5), no existing test caught that change. gofmt and golangci-lint are clean on the file.

This test was written with Claude Code during a planted-bug run by SK @ Trenyx.

…sertOpts

InsertOpts passed at insertion time are documented to override the
defaults from a JobArgsWithInsertOpts implementation, but no test passed
both at once, so the precedence of MaxAttempts, Priority, Queue, and
Tags could flip without a failure. Add a subtest that pins it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant