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

Function Test_Client_ErrorHandler

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

Source from the content-addressed store, hash-verified

5445}
5446
5447func 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) {

Callers

nothing calls this directly

Calls 13

WaitOrTimeoutFunction · 0.92
runNewTestClientFunction · 0.85
AddWorkerFunction · 0.85
WorkFuncFunction · 0.85
SubscribeMethod · 0.80
CleanupMethod · 0.80
InsertMethod · 0.80
newTestConfigFunction · 0.70
HelperMethod · 0.65
RunMethod · 0.65
JobInsertFastManyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…