(t *testing.T)
| 3884 | } |
| 3885 | |
| 3886 | func 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 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…