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

Function TestWorker_WorkJob

rivertest/worker_test.go:483–621  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

481}
482
483func TestWorker_WorkJob(t *testing.T) {
484 t.Parallel()
485
486 ctx := context.Background()
487
488 type testBundle struct {
489 client *river.Client[pgx.Tx]
490 config *river.Config
491 driver *riverpgxv5.Driver
492 tx pgx.Tx
493 workFunc func(ctx context.Context, job *river.Job[testArgs]) error
494 }
495
496 setup := func(t *testing.T) (*Worker[testArgs, pgx.Tx], *testBundle) {
497 t.Helper()
498
499 var (
500 config = &river.Config{ID: "rivertest-workjob"}
501 driver = riverpgxv5.New(nil)
502 )
503
504 client, err := river.NewClient(driver, config)
505 require.NoError(t, err)
506
507 bundle := &testBundle{
508 client: client,
509 config: config,
510 driver: driver,
511 tx: riverdbtest.TestTxPgx(ctx, t),
512 workFunc: func(ctx context.Context, job *river.Job[testArgs]) error { return nil },
513 }
514
515 worker := river.WorkFunc(func(ctx context.Context, job *river.Job[testArgs]) error {
516 return bundle.workFunc(ctx, job)
517 })
518
519 return NewWorker(t, driver, config, worker), bundle
520 }
521
522 t.Run("Success", func(t *testing.T) {
523 t.Parallel()
524
525 testWorker, bundle := setup(t)
526
527 bundle.workFunc = func(ctx context.Context, job *river.Job[testArgs]) error {
528 require.WithinDuration(t, time.Now(), *job.AttemptedAt, 5*time.Second)
529 require.Equal(t, []string{"rivertest-workjob"}, job.AttemptedBy)
530 require.Equal(t, rivertype.JobStateRunning, job.State)
531 return nil
532 }
533
534 insertRes, err := bundle.client.InsertTx(ctx, bundle.tx, testArgs{}, nil)
535 require.NoError(t, err)
536
537 res, err := testWorker.WorkJob(ctx, t, bundle.tx, insertRes.Job)
538 require.NoError(t, err)
539 require.Equal(t, river.EventKindJobCompleted, res.EventKind)
540 })

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
NewClientFunction · 0.92
TestTxPgxFunction · 0.92
WorkFuncFunction · 0.92
JobCompleteTxFunction · 0.92
JobFunction · 0.92
PtrFunction · 0.92
DBPoolFunction · 0.92
TestSchemaFunction · 0.92
NewWorkerFunction · 0.85
InsertTxMethod · 0.80
WorkJobMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…