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])
| 64 | // The worker is configured to disable unique enforcement by default, as this |
| 65 | // would otherwise prevent conflicting jobs from being tested in parallel. |
| 66 | func 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 | |
| 84 | func (w *Worker[T, TTx]) insertJob(ctx context.Context, tb testing.TB, tx TTx, args T, opts *river.InsertOpts) (*rivertype.JobRow, error) { |
| 85 | tb.Helper() |
searching dependent graphs…