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

Function Test_Client_JobDelete

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

Source from the content-addressed store, hash-verified

2757}
2758
2759func Test_Client_JobDelete(t *testing.T) {
2760 t.Parallel()
2761
2762 ctx := context.Background()
2763
2764 type testBundle struct {
2765 dbPool *pgxpool.Pool
2766 }
2767
2768 setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) {
2769 t.Helper()
2770
2771 var (
2772 dbPool = riversharedtest.DBPool(ctx, t)
2773 driver = riverpgxv5.New(dbPool)
2774 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
2775 config = newTestConfig(t, schema)
2776 client = newTestClient(t, dbPool, config)
2777 )
2778
2779 return client, &testBundle{dbPool: dbPool}
2780 }
2781
2782 t.Run("DeletesANonRunningJob", func(t *testing.T) {
2783 t.Parallel()
2784
2785 client, _ := setup(t)
2786
2787 insertRes, err := client.Insert(ctx, noOpArgs{}, &InsertOpts{ScheduledAt: time.Now().Add(time.Hour)})
2788 require.NoError(t, err)
2789 require.Equal(t, rivertype.JobStateScheduled, insertRes.Job.State)
2790
2791 jobAfter, err := client.JobDelete(ctx, insertRes.Job.ID)
2792 require.NoError(t, err)
2793 require.NotNil(t, jobAfter)
2794 require.Equal(t, rivertype.JobStateScheduled, jobAfter.State)
2795
2796 _, err = client.JobGet(ctx, insertRes.Job.ID)
2797 require.ErrorIs(t, err, ErrNotFound)
2798 })
2799
2800 t.Run("DoesNotDeleteARunningJob", func(t *testing.T) {
2801 t.Parallel()
2802
2803 client, _ := setup(t)
2804
2805 type JobArgs struct {
2806 testutil.JobArgsReflectKind[JobArgs]
2807 }
2808
2809 var (
2810 doneCh = make(chan struct{})
2811 startedCh = make(chan int64)
2812 )
2813 AddWorker(client.config.Workers, WorkFunc(func(ctx context.Context, job *Job[JobArgs]) error {
2814 close(startedCh)
2815 <-doneCh
2816 return nil

Callers

nothing calls this directly

Calls 15

DBPoolFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
WaitOrTimeoutFunction · 0.92
newTestClientFunction · 0.85
AddWorkerFunction · 0.85
WorkFuncFunction · 0.85
InsertMethod · 0.80
JobGetMethod · 0.80
CleanupMethod · 0.80
JobDeleteTxMethod · 0.80
newTestConfigFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…