2
0

Resplit Begin and BeginEx

This is in preparation for a Begin / Tx interface that will similate
nested transactions with savepoints.

In addition, this passes the TxOptions struct by value and thereby
removes an allocation.
This commit is contained in:
Jack Christensen
2019-08-17 15:53:55 -05:00
parent f3c703a102
commit c3e41872a8
9 changed files with 44 additions and 35 deletions
+10 -10
View File
@@ -26,7 +26,7 @@ func TestTransactionSuccessfulCommit(t *testing.T) {
t.Fatalf("Failed to create table: %v", err)
}
tx, err := conn.Begin(context.Background(), nil)
tx, err := conn.Begin(context.Background())
if err != nil {
t.Fatalf("conn.Begin failed: %v", err)
}
@@ -68,7 +68,7 @@ func TestTxCommitWhenTxBroken(t *testing.T) {
t.Fatalf("Failed to create table: %v", err)
}
tx, err := conn.Begin(context.Background(), nil)
tx, err := conn.Begin(context.Background())
if err != nil {
t.Fatalf("conn.Begin failed: %v", err)
}
@@ -113,13 +113,13 @@ func TestTxCommitSerializationFailure(t *testing.T) {
}
defer c1.Exec(context.Background(), `drop table tx_serializable_sums`)
tx1, err := c1.Begin(context.Background(), &pgx.TxOptions{IsoLevel: pgx.Serializable})
tx1, err := c1.BeginEx(context.Background(), pgx.TxOptions{IsoLevel: pgx.Serializable})
if err != nil {
t.Fatalf("Begin failed: %v", err)
}
defer tx1.Rollback(context.Background())
tx2, err := c2.Begin(context.Background(), &pgx.TxOptions{IsoLevel: pgx.Serializable})
tx2, err := c2.BeginEx(context.Background(), pgx.TxOptions{IsoLevel: pgx.Serializable})
if err != nil {
t.Fatalf("Begin failed: %v", err)
}
@@ -163,7 +163,7 @@ func TestTransactionSuccessfulRollback(t *testing.T) {
t.Fatalf("Failed to create table: %v", err)
}
tx, err := conn.Begin(context.Background(), nil)
tx, err := conn.Begin(context.Background())
if err != nil {
t.Fatalf("conn.Begin failed: %v", err)
}
@@ -196,7 +196,7 @@ func TestBeginIsoLevels(t *testing.T) {
isoLevels := []pgx.TxIsoLevel{pgx.Serializable, pgx.RepeatableRead, pgx.ReadCommitted, pgx.ReadUncommitted}
for _, iso := range isoLevels {
tx, err := conn.Begin(context.Background(), &pgx.TxOptions{IsoLevel: iso})
tx, err := conn.BeginEx(context.Background(), pgx.TxOptions{IsoLevel: iso})
if err != nil {
t.Fatalf("conn.Begin failed: %v", err)
}
@@ -220,7 +220,7 @@ func TestBeginReadOnly(t *testing.T) {
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn)
tx, err := conn.Begin(context.Background(), &pgx.TxOptions{AccessMode: pgx.ReadOnly})
tx, err := conn.BeginEx(context.Background(), pgx.TxOptions{AccessMode: pgx.ReadOnly})
if err != nil {
t.Fatalf("conn.Begin failed: %v", err)
}
@@ -238,7 +238,7 @@ func TestTxStatus(t *testing.T) {
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn)
tx, err := conn.Begin(context.Background(), nil)
tx, err := conn.Begin(context.Background())
if err != nil {
t.Fatal(err)
}
@@ -262,7 +262,7 @@ func TestTxStatusErrorInTransactions(t *testing.T) {
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn)
tx, err := conn.Begin(context.Background(), nil)
tx, err := conn.Begin(context.Background())
if err != nil {
t.Fatal(err)
}
@@ -309,7 +309,7 @@ func TestTxErr(t *testing.T) {
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn)
tx, err := conn.Begin(context.Background(), nil)
tx, err := conn.Begin(context.Background())
if err != nil {
t.Fatal(err)
}