2
0

Allow running tests in parallel

This commit is contained in:
Jack Christensen
2014-06-20 15:27:49 -05:00
parent 73b5c73c1c
commit 839ddcf75f
5 changed files with 86 additions and 0 deletions
+14
View File
@@ -18,6 +18,8 @@ func createConnPool(t *testing.T, maxConnections int) *pgx.ConnPool {
} }
func TestNewConnPool(t *testing.T) { func TestNewConnPool(t *testing.T) {
t.Parallel()
var numCallbacks int var numCallbacks int
afterConnect := func(c *pgx.Conn) error { afterConnect := func(c *pgx.Conn) error {
numCallbacks++ numCallbacks++
@@ -51,6 +53,8 @@ func TestNewConnPool(t *testing.T) {
} }
func TestPoolAcquireAndReleaseCycle(t *testing.T) { func TestPoolAcquireAndReleaseCycle(t *testing.T) {
t.Parallel()
maxConnections := 2 maxConnections := 2
incrementCount := int32(100) incrementCount := int32(100)
completeSync := make(chan int) completeSync := make(chan int)
@@ -125,6 +129,8 @@ func TestPoolAcquireAndReleaseCycle(t *testing.T) {
} }
func TestPoolReleaseWithTransactions(t *testing.T) { func TestPoolReleaseWithTransactions(t *testing.T) {
t.Parallel()
pool := createConnPool(t, 1) pool := createConnPool(t, 1)
defer pool.Close() defer pool.Close()
@@ -163,6 +169,8 @@ func TestPoolReleaseWithTransactions(t *testing.T) {
} }
func TestPoolAcquireAndReleaseCycleAutoConnect(t *testing.T) { func TestPoolAcquireAndReleaseCycleAutoConnect(t *testing.T) {
t.Parallel()
maxConnections := 3 maxConnections := 3
pool := createConnPool(t, maxConnections) pool := createConnPool(t, maxConnections)
defer pool.Close() defer pool.Close()
@@ -202,6 +210,8 @@ func TestPoolAcquireAndReleaseCycleAutoConnect(t *testing.T) {
} }
func TestPoolReleaseDiscardsDeadConnections(t *testing.T) { func TestPoolReleaseDiscardsDeadConnections(t *testing.T) {
t.Parallel()
maxConnections := 3 maxConnections := 3
pool := createConnPool(t, maxConnections) pool := createConnPool(t, maxConnections)
defer pool.Close() defer pool.Close()
@@ -262,6 +272,8 @@ func TestPoolReleaseDiscardsDeadConnections(t *testing.T) {
} }
func TestPoolTransaction(t *testing.T) { func TestPoolTransaction(t *testing.T) {
t.Parallel()
pool := createConnPool(t, 1) pool := createConnPool(t, 1)
defer pool.Close() defer pool.Close()
@@ -315,6 +327,8 @@ func TestPoolTransaction(t *testing.T) {
} }
func TestPoolTransactionIso(t *testing.T) { func TestPoolTransactionIso(t *testing.T) {
t.Parallel()
pool := createConnPool(t, 1) pool := createConnPool(t, 1)
defer pool.Close() defer pool.Close()
+52
View File
@@ -11,6 +11,8 @@ import (
) )
func TestConnect(t *testing.T) { func TestConnect(t *testing.T) {
t.Parallel()
conn, err := pgx.Connect(*defaultConnConfig) conn, err := pgx.Connect(*defaultConnConfig)
if err != nil { if err != nil {
t.Fatalf("Unable to establish connection: %v", err) t.Fatalf("Unable to establish connection: %v", err)
@@ -45,6 +47,8 @@ func TestConnect(t *testing.T) {
} }
func TestConnectWithUnixSocketDirectory(t *testing.T) { func TestConnectWithUnixSocketDirectory(t *testing.T) {
t.Parallel()
// /.s.PGSQL.5432 // /.s.PGSQL.5432
if unixSocketConnConfig == nil { if unixSocketConnConfig == nil {
return return
@@ -62,6 +66,8 @@ func TestConnectWithUnixSocketDirectory(t *testing.T) {
} }
func TestConnectWithUnixSocketFile(t *testing.T) { func TestConnectWithUnixSocketFile(t *testing.T) {
t.Parallel()
if unixSocketConnConfig == nil { if unixSocketConnConfig == nil {
return return
} }
@@ -80,6 +86,8 @@ func TestConnectWithUnixSocketFile(t *testing.T) {
} }
func TestConnectWithTcp(t *testing.T) { func TestConnectWithTcp(t *testing.T) {
t.Parallel()
if tcpConnConfig == nil { if tcpConnConfig == nil {
return return
} }
@@ -96,6 +104,8 @@ func TestConnectWithTcp(t *testing.T) {
} }
func TestConnectWithTLS(t *testing.T) { func TestConnectWithTLS(t *testing.T) {
t.Parallel()
if tlsConnConfig == nil { if tlsConnConfig == nil {
return return
} }
@@ -112,6 +122,8 @@ func TestConnectWithTLS(t *testing.T) {
} }
func TestConnectWithInvalidUser(t *testing.T) { func TestConnectWithInvalidUser(t *testing.T) {
t.Parallel()
if invalidUserConnConfig == nil { if invalidUserConnConfig == nil {
return return
} }
@@ -127,6 +139,8 @@ func TestConnectWithInvalidUser(t *testing.T) {
} }
func TestConnectWithPlainTextPassword(t *testing.T) { func TestConnectWithPlainTextPassword(t *testing.T) {
t.Parallel()
if plainPasswordConnConfig == nil { if plainPasswordConnConfig == nil {
return return
} }
@@ -143,6 +157,8 @@ func TestConnectWithPlainTextPassword(t *testing.T) {
} }
func TestConnectWithMD5Password(t *testing.T) { func TestConnectWithMD5Password(t *testing.T) {
t.Parallel()
if md5ConnConfig == nil { if md5ConnConfig == nil {
return return
} }
@@ -159,6 +175,8 @@ func TestConnectWithMD5Password(t *testing.T) {
} }
func TestParseURI(t *testing.T) { func TestParseURI(t *testing.T) {
t.Parallel()
tests := []struct { tests := []struct {
url string url string
connParams pgx.ConnConfig connParams pgx.ConnConfig
@@ -216,6 +234,8 @@ func TestParseURI(t *testing.T) {
} }
func TestExecute(t *testing.T) { func TestExecute(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -244,6 +264,8 @@ func TestExecute(t *testing.T) {
} }
func TestExecuteFailure(t *testing.T) { func TestExecuteFailure(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -257,6 +279,8 @@ func TestExecuteFailure(t *testing.T) {
} }
func TestSelectFunc(t *testing.T) { func TestSelectFunc(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -280,6 +304,8 @@ func TestSelectFunc(t *testing.T) {
} }
func TestSelectFuncFailure(t *testing.T) { func TestSelectFuncFailure(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -318,6 +344,8 @@ func Example_connectionSelectFunc() {
} }
func TestSelectRows(t *testing.T) { func TestSelectRows(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -364,6 +392,8 @@ func Example_connectionSelectRows() {
} }
func TestSelectRow(t *testing.T) { func TestSelectRow(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -392,6 +422,8 @@ func TestSelectRow(t *testing.T) {
} }
func TestConnectionSelectValue(t *testing.T) { func TestConnectionSelectValue(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -433,6 +465,8 @@ func TestConnectionSelectValue(t *testing.T) {
} }
func TestConnectionSelectValueTo(t *testing.T) { func TestConnectionSelectValueTo(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -482,6 +516,8 @@ func TestConnectionSelectValueTo(t *testing.T) {
} }
func TestSelectValues(t *testing.T) { func TestSelectValues(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -515,6 +551,8 @@ func TestSelectValues(t *testing.T) {
} }
func TestPrepare(t *testing.T) { func TestPrepare(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -592,6 +630,8 @@ func TestPrepare(t *testing.T) {
} }
func TestPrepareFailure(t *testing.T) { func TestPrepareFailure(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -605,6 +645,8 @@ func TestPrepareFailure(t *testing.T) {
} }
func TestTransaction(t *testing.T) { func TestTransaction(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -711,6 +753,8 @@ func TestTransaction(t *testing.T) {
} }
func TestTransactionIso(t *testing.T) { func TestTransactionIso(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -729,6 +773,8 @@ func TestTransactionIso(t *testing.T) {
} }
func TestListenNotify(t *testing.T) { func TestListenNotify(t *testing.T) {
t.Parallel()
listener := mustConnect(t, *defaultConnConfig) listener := mustConnect(t, *defaultConnConfig)
defer closeConn(t, listener) defer closeConn(t, listener)
@@ -782,6 +828,8 @@ func TestListenNotify(t *testing.T) {
} }
func TestFatalRxError(t *testing.T) { func TestFatalRxError(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -813,6 +861,8 @@ func TestFatalRxError(t *testing.T) {
} }
func TestFatalTxError(t *testing.T) { func TestFatalTxError(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -836,6 +886,8 @@ func TestFatalTxError(t *testing.T) {
} }
func TestCommandTag(t *testing.T) { func TestCommandTag(t *testing.T) {
t.Parallel()
var tests = []struct { var tests = []struct {
commandTag pgx.CommandTag commandTag pgx.CommandTag
rowsAffected int64 rowsAffected int64
+2
View File
@@ -6,6 +6,8 @@ import (
) )
func TestDataRowReaderReadValue(t *testing.T) { func TestDataRowReaderReadValue(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
+4
View File
@@ -5,6 +5,8 @@ import (
) )
func TestQuoteString(t *testing.T) { func TestQuoteString(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -18,6 +20,8 @@ func TestQuoteString(t *testing.T) {
} }
func TestSanitizeSql(t *testing.T) { func TestSanitizeSql(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
+14
View File
@@ -6,6 +6,8 @@ import (
) )
func TestTranscodeError(t *testing.T) { func TestTranscodeError(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -28,6 +30,8 @@ func TestTranscodeError(t *testing.T) {
} }
func TestNilTranscode(t *testing.T) { func TestNilTranscode(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -53,6 +57,8 @@ func TestNilTranscode(t *testing.T) {
} }
func TestDateTranscode(t *testing.T) { func TestDateTranscode(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -82,6 +88,8 @@ func TestDateTranscode(t *testing.T) {
} }
func TestTimestampTzTranscode(t *testing.T) { func TestTimestampTzTranscode(t *testing.T) {
t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnect(t, *defaultConnConfig)
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -111,6 +119,8 @@ func TestTimestampTzTranscode(t *testing.T) {
} }
func TestInt2SliceTranscode(t *testing.T) { func TestInt2SliceTranscode(t *testing.T) {
t.Parallel()
testEqual := func(a, b []int16) { testEqual := func(a, b []int16) {
if len(a) != len(b) { if len(a) != len(b) {
t.Errorf("Did not transcode []int16 successfully: %v is not %v", a, b) t.Errorf("Did not transcode []int16 successfully: %v is not %v", a, b)
@@ -143,6 +153,8 @@ func TestInt2SliceTranscode(t *testing.T) {
} }
func TestInt4SliceTranscode(t *testing.T) { func TestInt4SliceTranscode(t *testing.T) {
t.Parallel()
testEqual := func(a, b []int32) { testEqual := func(a, b []int32) {
if len(a) != len(b) { if len(a) != len(b) {
t.Errorf("Did not transcode []int32 successfully: %v is not %v", a, b) t.Errorf("Did not transcode []int32 successfully: %v is not %v", a, b)
@@ -175,6 +187,8 @@ func TestInt4SliceTranscode(t *testing.T) {
} }
func TestInt8SliceTranscode(t *testing.T) { func TestInt8SliceTranscode(t *testing.T) {
t.Parallel()
testEqual := func(a, b []int64) { testEqual := func(a, b []int64) {
if len(a) != len(b) { if len(a) != len(b) {
t.Errorf("Did not transcode []int64 successfully: %v is not %v", a, b) t.Errorf("Did not transcode []int64 successfully: %v is not %v", a, b)