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

Function Test_Client_JobCompletion

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

Source from the content-addressed store, hash-verified

7519}
7520
7521func Test_Client_JobCompletion(t *testing.T) {
7522 t.Parallel()
7523
7524 ctx := context.Background()
7525
7526 type testBundle struct {
7527 dbPool *pgxpool.Pool
7528 schema string
7529 subscribeChan <-chan *Event
7530 }
7531
7532 setup := func(t *testing.T, config *Config) (*Client[pgx.Tx], *testBundle) {
7533 t.Helper()
7534
7535 var (
7536 dbPool = riversharedtest.DBPool(ctx, t)
7537 driver = riverpgxv5.New(dbPool)
7538 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
7539 )
7540 config.Schema = schema
7541
7542 client := newTestClient(t, dbPool, config)
7543 startClient(ctx, t, client)
7544
7545 subscribeChan, cancel := client.Subscribe(EventKindJobCancelled, EventKindJobCompleted, EventKindJobFailed)
7546 t.Cleanup(cancel)
7547
7548 return client, &testBundle{
7549 dbPool: dbPool,
7550 schema: schema,
7551 subscribeChan: subscribeChan,
7552 }
7553 }
7554
7555 t.Run("JobThatReturnsNilIsCompleted", func(t *testing.T) {
7556 t.Parallel()
7557
7558 config := newTestConfig(t, "")
7559
7560 type JobArgs struct {
7561 testutil.JobArgsReflectKind[JobArgs]
7562 }
7563
7564 AddWorker(config.Workers, WorkFunc(func(ctx context.Context, job *Job[JobArgs]) error {
7565 return nil
7566 }))
7567
7568 client, bundle := setup(t, config)
7569
7570 now := client.baseService.Time.StubNow(time.Now().UTC())
7571
7572 insertRes, err := client.Insert(ctx, JobArgs{}, nil)
7573 require.NoError(t, err)
7574
7575 event := riversharedtest.WaitOrTimeout(t, bundle.subscribeChan)
7576 require.Equal(t, insertRes.Job.ID, event.Job.ID)
7577 require.Equal(t, rivertype.JobStateCompleted, event.Job.State)
7578

Callers

nothing calls this directly

Calls 15

IntervalMethod · 0.95
CallsMethod · 0.95
DBPoolFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
WaitOrTimeoutFunction · 0.92
newTestClientFunction · 0.85
AddWorkerFunction · 0.85
WorkFuncFunction · 0.85
JobCompleteTxFunction · 0.85
SubscribeMethod · 0.80
CleanupMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…