(t *testing.T)
| 7519 | } |
| 7520 | |
| 7521 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…