MCPcopy
hub / github.com/jackc/pgx / TestBeginIsoLevels

Function TestBeginIsoLevels

tx_test.go:271–297  ·  tx_test.go::TestBeginIsoLevels
(t *testing.T)

Source from the content-addressed store, hash-verified

269}
270
271func TestBeginIsoLevels(t *testing.T) {
272 t.Parallel()
273
274 conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
275 defer closeConn(t, conn)
276
277 pgxtest.SkipCockroachDB(t, conn, "Server always uses SERIALIZABLE isolation (https://www.cockroachlabs.com/docs/stable/demo-serializable.html)")
278
279 isoLevels := []pgx.TxIsoLevel{pgx.Serializable, pgx.RepeatableRead, pgx.ReadCommitted, pgx.ReadUncommitted}
280 for _, iso := range isoLevels {
281 tx, err := conn.BeginTx(context.Background(), pgx.TxOptions{IsoLevel: iso})
282 if err != nil {
283 t.Fatalf("conn.Begin failed: %v", err)
284 }
285
286 var level pgx.TxIsoLevel
287 conn.QueryRow(context.Background(), "select current_setting('transaction_isolation')").Scan(&level)
288 if level != iso {
289 t.Errorf("Expected to be in isolation level %v but was %v", iso, level)
290 }
291
292 err = tx.Rollback(context.Background())
293 if err != nil {
294 t.Fatalf("tx.Rollback failed: %v", err)
295 }
296 }
297}
298
299func TestBeginFunc(t *testing.T) {
300 t.Parallel()

Callers

nothing calls this directly

Calls 7

SkipCockroachDBFunction · 0.92
mustConnectStringFunction · 0.85
closeConnFunction · 0.70
ScanMethod · 0.65
QueryRowMethod · 0.65
RollbackMethod · 0.65
BeginTxMethod · 0.45

Tested by

no test coverage detected