MCPcopy
hub / github.com/riverqueue/river / Test_Client_InsertMany

Function Test_Client_InsertMany

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

Source from the content-addressed store, hash-verified

4072}
4073
4074func Test_Client_InsertMany(t *testing.T) {
4075 t.Parallel()
4076
4077 ctx := context.Background()
4078
4079 type testBundle struct {
4080 dbPool *pgxpool.Pool
4081 schema string
4082 }
4083
4084 setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) {
4085 t.Helper()
4086
4087 var (
4088 dbPool = riversharedtest.DBPool(ctx, t)
4089 driver = riverpgxv5.New(dbPool)
4090 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
4091 config = newTestConfig(t, schema)
4092 client = newTestClient(t, dbPool, config)
4093 )
4094
4095 return client, &testBundle{
4096 dbPool: dbPool,
4097 schema: schema,
4098 }
4099 }
4100
4101 t.Run("SucceedsWithMultipleJobs", func(t *testing.T) {
4102 t.Parallel()
4103
4104 client, _ := setup(t)
4105
4106 now := time.Now().UTC()
4107
4108 results, err := client.InsertMany(ctx, []InsertManyParams{
4109 {Args: noOpArgs{Name: "Foo"}, InsertOpts: &InsertOpts{Metadata: []byte(`{"a": "b"}`), Queue: "foo", Priority: 2}},
4110 {Args: noOpArgs{}, InsertOpts: &InsertOpts{ScheduledAt: now.Add(time.Minute)}},
4111 })
4112 require.NoError(t, err)
4113 require.Len(t, results, 2)
4114
4115 require.False(t, results[0].UniqueSkippedAsDuplicate)
4116 require.Equal(t, 0, results[0].Job.Attempt)
4117 require.Nil(t, results[0].Job.AttemptedAt)
4118 require.WithinDuration(t, now, results[0].Job.CreatedAt, 2*time.Second)
4119 require.Empty(t, results[0].Job.AttemptedBy)
4120 require.Positive(t, results[0].Job.ID)
4121 require.JSONEq(t, `{"name": "Foo"}`, string(results[0].Job.EncodedArgs))
4122 require.Empty(t, results[0].Job.Errors)
4123 require.Nil(t, results[0].Job.FinalizedAt)
4124 require.Equal(t, "noOp", results[0].Job.Kind)
4125 require.Equal(t, 25, results[0].Job.MaxAttempts)
4126 require.JSONEq(t, `{"a": "b"}`, string(results[0].Job.Metadata))
4127 require.Equal(t, 2, results[0].Job.Priority)
4128 require.Equal(t, "foo", results[0].Job.Queue)
4129 require.WithinDuration(t, now, results[0].Job.ScheduledAt, 2*time.Second)
4130 require.Equal(t, rivertype.JobStateAvailable, results[0].Job.State)
4131 require.Empty(t, results[0].Job.Tags)

Callers

nothing calls this directly

Calls 15

DBPoolFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
WaitOrTimeoutFunction · 0.92
WaitOrTimeoutNFunction · 0.92
LoggerFunction · 0.92
newTestClientFunction · 0.85
AddWorkerFunction · 0.85
NewClientFunction · 0.85
CleanupMethod · 0.80
AfterMethod · 0.80
ShouldTriggerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…