(t *testing.T)
| 22 | ) |
| 23 | |
| 24 | func TestJobCompleteTx(t *testing.T) { |
| 25 | t.Parallel() |
| 26 | |
| 27 | ctx := context.Background() |
| 28 | |
| 29 | type JobArgs struct { |
| 30 | testutil.JobArgsReflectKind[JobArgs] |
| 31 | } |
| 32 | |
| 33 | type testBundle struct { |
| 34 | client *Client[pgx.Tx] |
| 35 | exec riverdriver.Executor |
| 36 | tx pgx.Tx |
| 37 | } |
| 38 | |
| 39 | setup := func(ctx context.Context, t *testing.T) (context.Context, *testBundle) { |
| 40 | t.Helper() |
| 41 | |
| 42 | tx := riverdbtest.TestTxPgx(ctx, t) |
| 43 | client, err := NewClient(riverpgxv5.New(nil), &Config{ |
| 44 | Logger: riversharedtest.Logger(t), |
| 45 | }) |
| 46 | require.NoError(t, err) |
| 47 | ctx = context.WithValue(ctx, rivercommon.ContextKeyClient{}, client) |
| 48 | |
| 49 | return ctx, &testBundle{ |
| 50 | client: client, |
| 51 | exec: riverpgxv5.New(nil).UnwrapExecutor(tx), |
| 52 | tx: tx, |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | t.Run("CompletesJob", func(t *testing.T) { |
| 57 | t.Parallel() |
| 58 | |
| 59 | ctx, bundle := setup(ctx, t) |
| 60 | |
| 61 | job := testfactory.Job(ctx, t, bundle.exec, &testfactory.JobOpts{ |
| 62 | State: ptrutil.Ptr(rivertype.JobStateRunning), |
| 63 | }) |
| 64 | |
| 65 | completedJob, err := JobCompleteTx[*riverpgxv5.Driver](ctx, bundle.tx, &Job[JobArgs]{JobRow: job}) |
| 66 | require.NoError(t, err) |
| 67 | require.Equal(t, rivertype.JobStateCompleted, completedJob.State) |
| 68 | require.WithinDuration(t, time.Now(), *completedJob.FinalizedAt, 2*time.Second) |
| 69 | |
| 70 | updatedJob, err := bundle.exec.JobGetByID(ctx, &riverdriver.JobGetByIDParams{ |
| 71 | ID: job.ID, |
| 72 | Schema: "", |
| 73 | }) |
| 74 | require.NoError(t, err) |
| 75 | require.Equal(t, rivertype.JobStateCompleted, updatedJob.State) |
| 76 | }) |
| 77 | |
| 78 | t.Run("CompletesJobWithMetadataUpdates", func(t *testing.T) { |
| 79 | t.Parallel() |
| 80 | |
| 81 | ctx, bundle := setup(ctx, t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…