(t *testing.T)
| 3481 | } |
| 3482 | |
| 3483 | func Test_Client_InsertTx(t *testing.T) { |
| 3484 | t.Parallel() |
| 3485 | |
| 3486 | ctx := context.Background() |
| 3487 | |
| 3488 | type testBundle struct { |
| 3489 | schema string |
| 3490 | tx pgx.Tx |
| 3491 | } |
| 3492 | |
| 3493 | setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) { |
| 3494 | t.Helper() |
| 3495 | |
| 3496 | var ( |
| 3497 | dbPool = riversharedtest.DBPool(ctx, t) |
| 3498 | driver = riverpgxv5.New(dbPool) |
| 3499 | schema = riverdbtest.TestSchema(ctx, t, driver, nil) |
| 3500 | config = newTestConfig(t, schema) |
| 3501 | client = newTestClient(t, dbPool, config) |
| 3502 | ) |
| 3503 | |
| 3504 | tx, err := dbPool.Begin(ctx) |
| 3505 | require.NoError(t, err) |
| 3506 | t.Cleanup(func() { tx.Rollback(ctx) }) |
| 3507 | |
| 3508 | return client, &testBundle{ |
| 3509 | schema: schema, |
| 3510 | tx: tx, |
| 3511 | } |
| 3512 | } |
| 3513 | |
| 3514 | t.Run("Succeeds", func(t *testing.T) { |
| 3515 | t.Parallel() |
| 3516 | |
| 3517 | client, bundle := setup(t) |
| 3518 | |
| 3519 | insertRes, err := client.InsertTx(ctx, bundle.tx, &noOpArgs{}, nil) |
| 3520 | require.NoError(t, err) |
| 3521 | jobRow := insertRes.Job |
| 3522 | require.Equal(t, 0, jobRow.Attempt) |
| 3523 | require.Equal(t, rivercommon.MaxAttemptsDefault, jobRow.MaxAttempts) |
| 3524 | require.Equal(t, (&noOpArgs{}).Kind(), jobRow.Kind) |
| 3525 | require.Equal(t, PriorityDefault, jobRow.Priority) |
| 3526 | require.Equal(t, QueueDefault, jobRow.Queue) |
| 3527 | require.Equal(t, []string{}, jobRow.Tags) |
| 3528 | |
| 3529 | // Job is not visible outside of the transaction. |
| 3530 | _, err = client.JobGet(ctx, jobRow.ID) |
| 3531 | require.ErrorIs(t, err, ErrNotFound) |
| 3532 | }) |
| 3533 | |
| 3534 | t.Run("WithInsertOpts", func(t *testing.T) { |
| 3535 | t.Parallel() |
| 3536 | |
| 3537 | client, bundle := setup(t) |
| 3538 | |
| 3539 | insertRes, err := client.InsertTx(ctx, bundle.tx, &noOpArgs{}, &InsertOpts{ |
| 3540 | MaxAttempts: 17, |
nothing calls this directly
no test coverage detected
searching dependent graphs…