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

Function exerciseExecutorTx

riverdriver/riverdrivertest/executor_tx.go:17–237  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T,
	driverWithSchema func(ctx context.Context, t *testing.T, opts *riverdbtest.TestSchemaOpts) (riverdriver.Driver[TTx], string),
	executorWithTx func(ctx context.Context, t *testing.T) (riverdriver.Executor, riverdriver.Driver[TTx]),
)

Source from the content-addressed store, hash-verified

15)
16
17func exerciseExecutorTx[TTx any](ctx context.Context, t *testing.T,
18 driverWithSchema func(ctx context.Context, t *testing.T, opts *riverdbtest.TestSchemaOpts) (riverdriver.Driver[TTx], string),
19 executorWithTx func(ctx context.Context, t *testing.T) (riverdriver.Executor, riverdriver.Driver[TTx]),
20) {
21 t.Helper()
22
23 setup := func(ctx context.Context, t *testing.T) riverdriver.Executor {
24 t.Helper()
25
26 exec, _ := executorWithTx(ctx, t)
27 return exec
28 }
29
30 t.Run("Begin", func(t *testing.T) {
31 t.Parallel()
32
33 t.Run("BasicVisibility", func(t *testing.T) {
34 t.Parallel()
35
36 exec := setup(ctx, t)
37
38 tx, err := exec.Begin(ctx)
39 require.NoError(t, err)
40 t.Cleanup(func() { _ = tx.Rollback(ctx) })
41
42 // Job visible in subtransaction, but not parent.
43 {
44 job := testfactory.Job(ctx, t, tx, &testfactory.JobOpts{})
45 _ = testfactory.Job(ctx, t, tx, &testfactory.JobOpts{})
46
47 _, err := tx.JobGetByID(ctx, &riverdriver.JobGetByIDParams{ID: job.ID})
48 require.NoError(t, err)
49
50 require.NoError(t, tx.Rollback(ctx))
51
52 _, err = exec.JobGetByID(ctx, &riverdriver.JobGetByIDParams{ID: job.ID})
53 require.ErrorIs(t, err, rivertype.ErrNotFound)
54 }
55 })
56
57 t.Run("NestedTransactions", func(t *testing.T) {
58 t.Parallel()
59
60 exec := setup(ctx, t)
61
62 tx1, err := exec.Begin(ctx)
63 require.NoError(t, err)
64 t.Cleanup(func() { _ = tx1.Rollback(ctx) })
65
66 // Job visible in tx1, but not top level executor.
67 {
68 job1 := testfactory.Job(ctx, t, tx1, &testfactory.JobOpts{})
69
70 {
71 tx2, err := tx1.Begin(ctx)
72 require.NoError(t, err)
73 t.Cleanup(func() { _ = tx2.Rollback(ctx) })
74

Callers 1

ExerciseFunction · 0.85

Calls 15

WriteMethod · 0.95
KeyMethod · 0.95
JobFunction · 0.92
NewAdvisoryLockHashFunction · 0.92
HexFunction · 0.92
CleanupMethod · 0.80
HelperMethod · 0.65
RunMethod · 0.65
BeginMethod · 0.65
RollbackMethod · 0.65
JobGetByIDMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…