(t *testing.T)
| 5445 | } |
| 5446 | |
| 5447 | func Test_Client_ErrorHandler(t *testing.T) { |
| 5448 | t.Parallel() |
| 5449 | |
| 5450 | ctx := context.Background() |
| 5451 | |
| 5452 | type testBundle struct { |
| 5453 | schema string |
| 5454 | subscribeChan <-chan *Event |
| 5455 | } |
| 5456 | |
| 5457 | setup := func(t *testing.T, config *Config) (*Client[pgx.Tx], *testBundle) { |
| 5458 | t.Helper() |
| 5459 | |
| 5460 | client := runNewTestClient(ctx, t, config) |
| 5461 | |
| 5462 | subscribeChan, cancel := client.Subscribe(EventKindJobCompleted, EventKindJobFailed) |
| 5463 | t.Cleanup(cancel) |
| 5464 | |
| 5465 | return client, &testBundle{ |
| 5466 | schema: client.config.Schema, |
| 5467 | subscribeChan: subscribeChan, |
| 5468 | } |
| 5469 | } |
| 5470 | |
| 5471 | t.Run("ErrorHandler", func(t *testing.T) { |
| 5472 | t.Parallel() |
| 5473 | |
| 5474 | config := newTestConfig(t, "") |
| 5475 | |
| 5476 | type JobArgs struct { |
| 5477 | testutil.JobArgsReflectKind[JobArgs] |
| 5478 | } |
| 5479 | |
| 5480 | handlerErr := errors.New("job error") |
| 5481 | AddWorker(config.Workers, WorkFunc(func(ctx context.Context, job *Job[JobArgs]) error { |
| 5482 | return handlerErr |
| 5483 | })) |
| 5484 | |
| 5485 | var errorHandlerCalled bool |
| 5486 | config.ErrorHandler = &testErrorHandler{ |
| 5487 | HandleErrorFunc: func(ctx context.Context, job *rivertype.JobRow, err error) *ErrorHandlerResult { |
| 5488 | require.Equal(t, handlerErr, err) |
| 5489 | errorHandlerCalled = true |
| 5490 | return &ErrorHandlerResult{} |
| 5491 | }, |
| 5492 | } |
| 5493 | |
| 5494 | client, bundle := setup(t, config) |
| 5495 | |
| 5496 | _, err := client.Insert(ctx, JobArgs{}, nil) |
| 5497 | require.NoError(t, err) |
| 5498 | |
| 5499 | riversharedtest.WaitOrTimeout(t, bundle.subscribeChan) |
| 5500 | |
| 5501 | require.True(t, errorHandlerCalled) |
| 5502 | }) |
| 5503 | |
| 5504 | t.Run("ErrorHandler_UnknownJobKind", func(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…