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

Function Test_Client_UnknownJobKindErrorsTheJob

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

Source from the content-addressed store, hash-verified

7832func (unregisteredJobArgs) Kind() string { return "RandomWorkerNameThatIsNeverRegistered" }
7833
7834func Test_Client_UnknownJobKindErrorsTheJob(t *testing.T) {
7835 t.Parallel()
7836
7837 ctx := context.Background()
7838
7839 ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
7840 t.Cleanup(cancel)
7841
7842 doneCh := make(chan struct{})
7843 close(doneCh) // don't need to block any jobs from completing
7844
7845 config := newTestConfig(t, "")
7846 client := runNewTestClient(ctx, t, config)
7847
7848 subscribeChan, cancel := client.Subscribe(EventKindJobFailed)
7849 t.Cleanup(cancel)
7850
7851 insertParams, err := insertParamsFromConfigArgsAndOptions(&client.baseService.Archetype, config, unregisteredJobArgs{}, nil)
7852 require.NoError(t, err)
7853 insertedResults, err := client.driver.GetExecutor().JobInsertFastMany(ctx, &riverdriver.JobInsertFastManyParams{
7854 Jobs: []*riverdriver.JobInsertFastParams{(*riverdriver.JobInsertFastParams)(insertParams)},
7855 Schema: client.config.Schema,
7856 })
7857 require.NoError(t, err)
7858
7859 insertedResult := insertedResults[0]
7860
7861 event := riversharedtest.WaitOrTimeout(t, subscribeChan)
7862 require.Equal(t, insertedResult.Job.ID, event.Job.ID)
7863 require.Equal(t, "RandomWorkerNameThatIsNeverRegistered", insertedResult.Job.Kind)
7864 require.Len(t, event.Job.Errors, 1)
7865 require.Equal(t, (&UnknownJobKindError{Kind: "RandomWorkerNameThatIsNeverRegistered"}).Error(), event.Job.Errors[0].Error)
7866 require.Equal(t, rivertype.JobStateRetryable, event.Job.State)
7867 // Ensure that ScheduledAt was updated with next run time:
7868 require.True(t, event.Job.ScheduledAt.After(insertedResult.Job.ScheduledAt))
7869 // It's the 1st attempt that failed. Attempt won't be incremented again until
7870 // the job gets fetched a 2nd time.
7871 require.Equal(t, 1, event.Job.Attempt)
7872
7873 require.NoError(t, client.Stop(ctx))
7874}
7875
7876func Test_Client_Start_Error(t *testing.T) {
7877 t.Parallel()

Callers

nothing calls this directly

Calls 11

WaitOrTimeoutFunction · 0.92
runNewTestClientFunction · 0.85
CleanupMethod · 0.80
SubscribeMethod · 0.80
AfterMethod · 0.80
newTestConfigFunction · 0.70
JobInsertFastManyMethod · 0.65
GetExecutorMethod · 0.65
StopMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…