MCPcopy
hub / github.com/riverqueue/river / Test_Client_JobDeleteTx

Function Test_Client_JobDeleteTx

client_test.go:2876–2936  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2874}
2875
2876func Test_Client_JobDeleteTx(t *testing.T) {
2877 t.Parallel()
2878
2879 ctx := context.Background()
2880
2881 type testBundle struct {
2882 dbPool *pgxpool.Pool
2883 exec riverdriver.Executor
2884 execTx riverdriver.ExecutorTx
2885 schema string
2886 tx pgx.Tx
2887 }
2888
2889 setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) {
2890 t.Helper()
2891
2892 var (
2893 dbPool = riversharedtest.DBPool(ctx, t)
2894 driver = riverpgxv5.New(dbPool)
2895 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
2896 config = newTestConfig(t, schema)
2897 client = newTestClient(t, dbPool, config)
2898 )
2899
2900 tx, err := dbPool.Begin(ctx)
2901 require.NoError(t, err)
2902 t.Cleanup(func() { tx.Rollback(ctx) })
2903
2904 return client, &testBundle{
2905 dbPool: dbPool,
2906 exec: driver.GetExecutor(),
2907 execTx: driver.UnwrapExecutor(tx),
2908 schema: schema,
2909 tx: tx,
2910 }
2911 }
2912
2913 t.Run("Succeeds", func(t *testing.T) {
2914 t.Parallel()
2915
2916 client, bundle := setup(t)
2917
2918 job1 := testfactory.Job(ctx, t, bundle.exec, &testfactory.JobOpts{Schema: bundle.schema})
2919 job2 := testfactory.Job(ctx, t, bundle.exec, &testfactory.JobOpts{Schema: bundle.schema})
2920
2921 deletedJob, err := client.JobDeleteTx(ctx, bundle.tx, job1.ID)
2922 require.NoError(t, err)
2923 require.Equal(t, job1.ID, deletedJob.ID)
2924
2925 _, err = bundle.execTx.JobGetByID(ctx, &riverdriver.JobGetByIDParams{ID: job1.ID, Schema: bundle.schema})
2926 require.ErrorIs(t, rivertype.ErrNotFound, err)
2927 _, err = bundle.execTx.JobGetByID(ctx, &riverdriver.JobGetByIDParams{ID: job2.ID, Schema: bundle.schema})
2928 require.NoError(t, err)
2929
2930 // Both jobs present because other transaction doesn't see the deletion.
2931 _, err = bundle.exec.JobGetByID(ctx, &riverdriver.JobGetByIDParams{ID: job1.ID, Schema: bundle.schema})
2932 require.NoError(t, err)
2933 _, err = bundle.exec.JobGetByID(ctx, &riverdriver.JobGetByIDParams{ID: job2.ID, Schema: bundle.schema})

Callers

nothing calls this directly

Calls 15

DBPoolFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
JobFunction · 0.92
newTestClientFunction · 0.85
CleanupMethod · 0.80
JobDeleteTxMethod · 0.80
newTestConfigFunction · 0.70
HelperMethod · 0.65
BeginMethod · 0.65
RollbackMethod · 0.65
GetExecutorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…