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

Function TestRequireNotInsertedTx

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

Source from the content-addressed store, hash-verified

438}
439
440func TestRequireNotInsertedTx(t *testing.T) {
441 t.Parallel()
442
443 ctx := context.Background()
444
445 type testBundle struct {
446 mockT *testutil.MockT
447 tx pgx.Tx
448 }
449
450 setup := func(t *testing.T) (*river.Client[pgx.Tx], *testBundle) {
451 t.Helper()
452
453 riverClient, err := river.NewClient(riverpgxv5.New(nil), &river.Config{})
454 require.NoError(t, err)
455
456 return riverClient, &testBundle{
457 mockT: testutil.NewMockT(t),
458 tx: riverdbtest.TestTxPgx(ctx, t),
459 }
460 }
461
462 t.Run("VerifiesInsert", func(t *testing.T) {
463 t.Parallel()
464
465 riverClient, bundle := setup(t)
466
467 _, err := riverClient.InsertTx(ctx, bundle.tx, Job2Args{Int: 123}, nil)
468 require.NoError(t, err)
469
470 requireNotInsertedTx[*riverpgxv5.Driver](ctx, t, bundle.tx, &Job1Args{}, nil)
471 require.False(t, bundle.mockT.Failed)
472 })
473
474 t.Run("VerifiesMultiple", func(t *testing.T) {
475 t.Parallel()
476
477 _, bundle := setup(t)
478
479 requireNotInsertedTx[*riverpgxv5.Driver](ctx, t, bundle.tx, &Job1Args{}, nil)
480 require.False(t, bundle.mockT.Failed)
481
482 requireNotInsertedTx[*riverpgxv5.Driver](ctx, t, bundle.tx, &Job2Args{}, nil)
483 require.False(t, bundle.mockT.Failed)
484 })
485
486 t.Run("TransactionVisibility", func(t *testing.T) {
487 t.Parallel()
488
489 riverClient, bundle := setup(t)
490
491 // Start a second transaction with different visibility.
492 otherTx := riverdbtest.TestTxPgx(ctx, t)
493
494 _, err := riverClient.InsertTx(ctx, bundle.tx, Job1Args{String: "foo"}, nil)
495 require.NoError(t, err)
496
497 // Not visible in the second transaction.

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…