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

Function TestJobCompleteTx

job_complete_tx_test.go:24–166  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func 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)

Callers

nothing calls this directly

Calls 14

TestTxPgxFunction · 0.92
NewFunction · 0.92
LoggerFunction · 0.92
JobFunction · 0.92
PtrFunction · 0.92
NewClientFunction · 0.85
JobCompleteTxFunction · 0.85
JobDeleteTxMethod · 0.80
HelperMethod · 0.65
UnwrapExecutorMethod · 0.65
RunMethod · 0.65
NowMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…