MCPcopy Index your code
hub / github.com/riverqueue/river / NewWorker

Function NewWorker

rivertest/worker.go:66–82  ·  view source on GitHub ↗

NewWorker creates a new test Worker for testing the provided [river.Worker]. The worker uses the provided driver and River config to populate default values on test jobs and to configure the execution environment. A pool-less driver is recommended for most usage, as individual job inserts and execu

(tb testing.TB, driver riverdriver.Driver[TTx], config *river.Config, worker river.Worker[T])

Source from the content-addressed store, hash-verified

64// The worker is configured to disable unique enforcement by default, as this
65// would otherwise prevent conflicting jobs from being tested in parallel.
66func NewWorker[T river.JobArgs, TTx any](tb testing.TB, driver riverdriver.Driver[TTx], config *river.Config, worker river.Worker[T]) *Worker[T, TTx] {
67 tb.Helper()
68
69 config = config.WithDefaults()
70 config.Test.DisableUniqueEnforcement = true
71
72 client, err := river.NewClient(driver, config)
73 if err != nil {
74 tb.Fatalf("failed to create client: %s", err)
75 }
76
77 return &Worker[T, TTx]{
78 client: client,
79 config: config,
80 worker: worker,
81 }
82}
83
84func (w *Worker[T, TTx]) insertJob(ctx context.Context, tb testing.TB, tx TTx, args T, opts *river.InsertOpts) (*rivertype.JobRow, error) {
85 tb.Helper()

Callers 5

TestMiddlewareFunction · 0.92
TestWorker_NewWorkerFunction · 0.85
TestWorker_WorkFunction · 0.85
TestWorker_WorkJobFunction · 0.85

Calls 3

NewClientFunction · 0.92
HelperMethod · 0.65
WithDefaultsMethod · 0.45

Tested by 5

TestMiddlewareFunction · 0.74
TestWorker_NewWorkerFunction · 0.68
TestWorker_WorkFunction · 0.68
TestWorker_WorkJobFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…