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

Function Test_Client_InsertManyTx

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

Source from the content-addressed store, hash-verified

4373}
4374
4375func Test_Client_InsertManyTx(t *testing.T) {
4376 t.Parallel()
4377
4378 ctx := context.Background()
4379
4380 type testBundle struct {
4381 schema string
4382 tx pgx.Tx
4383 }
4384
4385 setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) {
4386 t.Helper()
4387
4388 var (
4389 dbPool = riversharedtest.DBPool(ctx, t)
4390 driver = riverpgxv5.New(dbPool)
4391 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
4392 config = newTestConfig(t, schema)
4393 client = newTestClient(t, dbPool, config)
4394 )
4395
4396 tx, err := dbPool.Begin(ctx)
4397 require.NoError(t, err)
4398 t.Cleanup(func() { tx.Rollback(ctx) })
4399
4400 return client, &testBundle{
4401 schema: schema,
4402 tx: tx,
4403 }
4404 }
4405
4406 t.Run("SucceedsWithMultipleJobs", func(t *testing.T) {
4407 t.Parallel()
4408
4409 client, bundle := setup(t)
4410
4411 now := time.Now().UTC()
4412
4413 results, err := client.InsertManyTx(ctx, bundle.tx, []InsertManyParams{
4414 {Args: noOpArgs{Name: "Foo"}, InsertOpts: &InsertOpts{Metadata: []byte(`{"a": "b"}`), Queue: "foo", Priority: 2}},
4415 {Args: noOpArgs{}, InsertOpts: &InsertOpts{ScheduledAt: now.Add(time.Minute)}},
4416 })
4417 require.NoError(t, err)
4418 require.Len(t, results, 2)
4419
4420 require.False(t, results[0].UniqueSkippedAsDuplicate)
4421 require.Equal(t, 0, results[0].Job.Attempt)
4422 require.Nil(t, results[0].Job.AttemptedAt)
4423 require.WithinDuration(t, now, results[0].Job.CreatedAt, 2*time.Second)
4424 require.Empty(t, results[0].Job.AttemptedBy)
4425 require.Positive(t, results[0].Job.ID)
4426 require.JSONEq(t, `{"name": "Foo"}`, string(results[0].Job.EncodedArgs))
4427 require.Empty(t, results[0].Job.Errors)
4428 require.Nil(t, results[0].Job.FinalizedAt)
4429 require.Equal(t, "noOp", results[0].Job.Kind)
4430 require.Equal(t, 25, results[0].Job.MaxAttempts)
4431 require.JSONEq(t, `{"a": "b"}`, string(results[0].Job.Metadata))
4432 require.Equal(t, 2, results[0].Job.Priority)

Callers

nothing calls this directly

Calls 15

DBPoolFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
LoggerFunction · 0.92
newTestClientFunction · 0.85
NewClientFunction · 0.85
CleanupMethod · 0.80
InsertManyTxMethod · 0.80
newTestConfigFunction · 0.70
startClientFunction · 0.70
HelperMethod · 0.65
BeginMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…