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

Function Test_Client_InsertManyFastTx

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

Source from the content-addressed store, hash-verified

3884}
3885
3886func Test_Client_InsertManyFastTx(t *testing.T) {
3887 t.Parallel()
3888
3889 ctx := context.Background()
3890
3891 type testBundle struct {
3892 schema string
3893 tx pgx.Tx
3894 }
3895
3896 setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) {
3897 t.Helper()
3898
3899 var (
3900 dbPool = riversharedtest.DBPool(ctx, t)
3901 driver = riverpgxv5.New(dbPool)
3902 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
3903 config = newTestConfig(t, schema)
3904 client = newTestClient(t, dbPool, config)
3905 )
3906
3907 tx, err := dbPool.Begin(ctx)
3908 require.NoError(t, err)
3909 t.Cleanup(func() { tx.Rollback(ctx) })
3910
3911 return client, &testBundle{
3912 schema: schema,
3913 tx: tx,
3914 }
3915 }
3916
3917 t.Run("SucceedsWithMultipleJobs", func(t *testing.T) {
3918 t.Parallel()
3919
3920 client, bundle := setup(t)
3921
3922 count, err := client.InsertManyFastTx(ctx, bundle.tx, []InsertManyParams{
3923 {Args: noOpArgs{}, InsertOpts: &InsertOpts{Queue: "foo", Priority: 2}},
3924 {Args: noOpArgs{}},
3925 })
3926 require.NoError(t, err)
3927 require.Equal(t, 2, count)
3928
3929 jobs, err := client.driver.UnwrapExecutor(bundle.tx).JobGetByKindMany(ctx, &riverdriver.JobGetByKindManyParams{
3930 Kind: []string{(noOpArgs{}).Kind()},
3931 Schema: client.config.Schema,
3932 })
3933
3934 require.NoError(t, err)
3935 require.Len(t, jobs, 2, "Expected to find exactly two jobs of kind: "+(noOpArgs{}).Kind())
3936
3937 require.NoError(t, bundle.tx.Commit(ctx))
3938
3939 // Ensure the jobs are visible outside the transaction:
3940 jobs, err = client.driver.GetExecutor().JobGetByKindMany(ctx, &riverdriver.JobGetByKindManyParams{
3941 Kind: []string{(noOpArgs{}).Kind()},
3942 Schema: client.config.Schema,
3943 })

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
InsertManyFastTxMethod · 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…