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

Function TestRequireManyInsertedTx

rivertest/rivertest_test.go:866–1272  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

864}
865
866func TestRequireManyInsertedTx(t *testing.T) {
867 t.Parallel()
868
869 ctx := context.Background()
870
871 type testBundle struct {
872 mockT *testutil.MockT
873 tx pgx.Tx
874 }
875
876 setup := func(t *testing.T) (*river.Client[pgx.Tx], *testBundle) {
877 t.Helper()
878
879 riverClient, err := river.NewClient(riverpgxv5.New(nil), &river.Config{})
880 require.NoError(t, err)
881
882 return riverClient, &testBundle{
883 mockT: testutil.NewMockT(t),
884 tx: riverdbtest.TestTxPgx(ctx, t),
885 }
886 }
887
888 t.Run("VerifiesInsert", func(t *testing.T) {
889 t.Parallel()
890
891 riverClient, bundle := setup(t)
892
893 _, err := riverClient.InsertTx(ctx, bundle.tx, Job1Args{String: "foo"}, nil)
894 require.NoError(t, err)
895
896 jobs := requireManyInsertedTx[*riverpgxv5.Driver](ctx, bundle.mockT, bundle.tx, []ExpectedJob{
897 {Args: &Job1Args{}},
898 })
899 require.False(t, bundle.mockT.Failed)
900 require.Equal(t, "job1", jobs[0].Kind)
901 })
902
903 t.Run("TransactionVisibility", func(t *testing.T) {
904 t.Parallel()
905
906 riverClient, bundle := setup(t)
907
908 // Start a second transaction with different visibility.
909 otherTx := riverdbtest.TestTxPgx(ctx, t)
910
911 _, err := riverClient.InsertTx(ctx, bundle.tx, Job1Args{String: "foo"}, nil)
912 require.NoError(t, err)
913
914 // Visible in the original transaction.
915 jobs := requireManyInsertedTx[*riverpgxv5.Driver](ctx, bundle.mockT, bundle.tx, []ExpectedJob{
916 {Args: &Job1Args{}},
917 })
918 require.False(t, bundle.mockT.Failed)
919 require.Equal(t, "job1", jobs[0].Kind)
920
921 // Not visible in the second transaction.
922 _ = requireManyInsertedTx[*riverpgxv5.Driver](ctx, bundle.mockT, otherTx, []ExpectedJob{
923 {Args: &Job1Args{}},

Callers

nothing calls this directly

Calls 12

LogOutputMethod · 0.95
NewClientFunction · 0.92
NewFunction · 0.92
NewMockTFunction · 0.92
TestTxPgxFunction · 0.92
requireManyInsertedTxFunction · 0.85
failureStringFunction · 0.85
InsertTxMethod · 0.80
InsertManyTxMethod · 0.80
HelperMethod · 0.65
RunMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…