github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/tests/integration/table_tx_control_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package integration 5 6 import ( 7 "context" 8 "testing" 9 10 "github.com/ydb-platform/ydb-go-sdk/v3/table" 11 ) 12 13 func TestTableTxControl(t *testing.T) { 14 scope := newScope(t) 15 driver := scope.Driver() 16 17 t.Run("rw-auto-commit", func(t *testing.T) { 18 txControl := table.TxControl( 19 table.BeginTx(table.WithSerializableReadWrite()), 20 table.CommitTx(), 21 ) 22 err := driver.Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error { 23 _, _, err := s.Execute(ctx, txControl, "SELECT 1", nil) 24 return err 25 }) 26 scope.Require.NoError(err) 27 }) 28 t.Run("online-ro-auto-commit", func(t *testing.T) { 29 txControl := table.TxControl( 30 table.BeginTx(table.WithOnlineReadOnly(table.WithInconsistentReads())), 31 table.CommitTx(), 32 ) 33 err := driver.Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error { 34 _, _, err := s.Execute(ctx, txControl, "SELECT 1", nil) 35 return err 36 }) 37 scope.Require.NoError(err) 38 }) 39 t.Run("stale-ro-auto-commit", func(t *testing.T) { 40 txControl := table.TxControl( 41 table.BeginTx(table.WithStaleReadOnly()), 42 table.CommitTx(), 43 ) 44 err := driver.Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error { 45 _, _, err := s.Execute(ctx, txControl, "SELECT 1", nil) 46 return err 47 }) 48 scope.Require.NoError(err) 49 }) 50 t.Run("snapshot-ro-auto-commit", func(t *testing.T) { 51 txControl := table.TxControl( 52 table.BeginTx(table.WithSnapshotReadOnly()), 53 table.CommitTx(), 54 ) 55 err := driver.Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error { 56 _, _, err := s.Execute(ctx, txControl, "SELECT 1", nil) 57 return err 58 }) 59 scope.Require.NoError(err) 60 }) 61 }