From 8170eaf4014734e7e362553f4d53358bf2be09dd Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Tue, 27 Aug 2019 18:22:34 -0500 Subject: [PATCH] Update to latest version of pgconn - Also remove a few tests of functionality that is handled by pgconn --- conn.go | 6 +---- conn_test.go | 71 +++++++-------------------------------------------- go.mod | 4 +-- go.sum | 19 ++++---------- query_test.go | 18 ++++--------- 5 files changed, 22 insertions(+), 96 deletions(-) diff --git a/conn.go b/conn.go index 27a80e95..5a58fa92 100644 --- a/conn.go +++ b/conn.go @@ -89,10 +89,6 @@ var ErrNoRows = errors.New("no rows in result set") // ErrDeadConn occurs on an attempt to use a dead connection var ErrDeadConn = errors.New("conn is dead") -// ErrTLSRefused occurs when the connection attempt requires TLS and the -// PostgreSQL server refuses to use TLS -var ErrTLSRefused = pgconn.ErrTLSRefused - // ErrInvalidLogLevel occurs on attempt to set an invalid log level. var ErrInvalidLogLevel = errors.New("invalid log level") @@ -221,7 +217,7 @@ func connect(ctx context.Context, config *ConnConfig) (c *Conn, err error) { // Replication connections can't execute the queries to // populate the c.PgTypes and c.pgsqlAfInet - if _, ok := c.pgConn.Config.RuntimeParams["replication"]; ok { + if _, ok := config.Config.RuntimeParams["replication"]; ok { return c, nil } diff --git a/conn_test.go b/conn_test.go index 878aa0f2..f87c2bb3 100644 --- a/conn_test.go +++ b/conn_test.go @@ -14,7 +14,6 @@ import ( "github.com/jackc/pgx/v4" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - errors "golang.org/x/xerrors" ) func TestCrateDBConnect(t *testing.T) { @@ -200,9 +199,7 @@ func TestExecFailureWithArguments(t *testing.T) { if err == nil { t.Fatal("Expected SQL syntax error") } - if errors.Is(err, pgconn.ErrNoBytesSent) { - t.Error("Expected bytes to be sent to server") - } + assert.False(t, pgconn.SafeToRetry(err)) } func TestExecContextWithoutCancelation(t *testing.T) { @@ -221,9 +218,7 @@ func TestExecContextWithoutCancelation(t *testing.T) { if string(commandTag) != "CREATE TABLE" { t.Fatalf("Unexpected results from Exec: %v", commandTag) } - if errors.Is(err, pgconn.ErrNoBytesSent) { - t.Error("Expected bytes to be sent to server") - } + assert.False(t, pgconn.SafeToRetry(err)) } func TestExecContextFailureWithoutCancelation(t *testing.T) { @@ -239,18 +234,15 @@ func TestExecContextFailureWithoutCancelation(t *testing.T) { if err == nil { t.Fatal("Expected SQL syntax error") } - if errors.Is(err, pgconn.ErrNoBytesSent) { - t.Error("Expected bytes to be sent to server") - } + assert.False(t, pgconn.SafeToRetry(err)) rows, _ := conn.Query(context.Background(), "select 1") rows.Close() if rows.Err() != nil { t.Fatalf("ExecEx failure appears to have broken connection: %v", rows.Err()) } - if errors.Is(err, pgconn.ErrNoBytesSent) { - t.Error("Expected bytes to be sent to server") - } + assert.False(t, pgconn.SafeToRetry(err)) + } func TestExecContextFailureWithoutCancelationWithArguments(t *testing.T) { @@ -266,9 +258,7 @@ func TestExecContextFailureWithoutCancelationWithArguments(t *testing.T) { if err == nil { t.Fatal("Expected SQL syntax error") } - if errors.Is(err, pgconn.ErrNoBytesSent) { - t.Error("Expected bytes to be sent to server") - } + assert.False(t, pgconn.SafeToRetry(err)) } func TestExecFailureCloseBefore(t *testing.T) { @@ -278,12 +268,8 @@ func TestExecFailureCloseBefore(t *testing.T) { closeConn(t, conn) _, err := conn.Exec(context.Background(), "select 1") - if err == nil { - t.Fatal("Expected network error") - } - if !errors.Is(err, pgconn.ErrNoBytesSent) { - t.Error("Expected no bytes to be sent to server") - } + require.Error(t, err) + assert.True(t, pgconn.SafeToRetry(err)) } func TestExecExtendedProtocol(t *testing.T) { @@ -528,7 +514,7 @@ func TestListenNotify(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond) defer cancel() notification, err = listener.WaitForNotification(ctx) - assert.True(t, errors.Is(err, context.DeadlineExceeded)) + assert.True(t, pgconn.Timeout(err)) // listener can listen again after a timeout mustExec(t, notifier, "notify chat") @@ -723,45 +709,6 @@ func TestInsertTimestampArray(t *testing.T) { } } -func TestCatchSimultaneousConnectionQueries(t *testing.T) { - t.Parallel() - - conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) - defer closeConn(t, conn) - - rows1, err := conn.Query(context.Background(), "select generate_series(1,$1)", 10) - if err != nil { - t.Fatalf("conn.Query failed: %v", err) - } - defer rows1.Close() - - rows2, err := conn.Query(context.Background(), "select generate_series(1,$1)", 10) - require.NoError(t, err) - require.NotNil(t, rows2) - require.False(t, rows2.Next()) - if !errors.Is(rows2.Err(), pgconn.ErrConnBusy) { - t.Fatalf("conn.Query should have failed with pgconn.ErrConnBusy, but it was %v", rows2.Err()) - } -} - -func TestCatchSimultaneousConnectionQueryAndExec(t *testing.T) { - t.Parallel() - - conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) - defer closeConn(t, conn) - - rows, err := conn.Query(context.Background(), "select generate_series(1,$1)", 10) - if err != nil { - t.Fatalf("conn.Query failed: %v", err) - } - defer rows.Close() - - _, err = conn.Exec(context.Background(), "create temporary table foo(spice timestamp[])") - if !errors.Is(err, pgconn.ErrConnBusy) { - t.Fatalf("conn.Exec should have failed with pgconn.ErrConnBusy, but it was %v", err) - } -} - type testLog struct { lvl pgx.LogLevel msg string diff --git a/go.mod b/go.mod index 548f535e..7eed1e0a 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.12 require ( github.com/cockroachdb/apd v1.1.0 - github.com/jackc/pgconn v0.0.0-20190825052232-e6cf51b304f1 + github.com/jackc/pgconn v0.0.0-20190827231150-66aaed7c9eb0 github.com/jackc/pgio v1.0.0 github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711 github.com/jackc/pgtype v0.0.0-20190825053211-b1e25e4ea49c @@ -19,7 +19,7 @@ require ( github.com/stretchr/testify v1.4.0 go.uber.org/multierr v1.1.0 // indirect go.uber.org/zap v1.10.0 - golang.org/x/tools v0.0.0-20190825031127-d72b05d2b1b6 // indirect + golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456 // indirect golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec diff --git a/go.sum b/go.sum index 3f109410..1df29f1a 100644 --- a/go.sum +++ b/go.sum @@ -17,18 +17,8 @@ github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3 h1:ZFYpB74Kq8xE9gmfxC github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA= github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb h1:d6GP9szHvXVopAOAnZ7WhRnF3Xdxrylmm/9jnfmW4Ag= github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= -github.com/jackc/pgconn v0.0.0-20190824212754-2209d2e36aea h1:FwCceMjr3vnfVyl2EG3F0TKILOVs0ly8Z8EbXe72WAE= -github.com/jackc/pgconn v0.0.0-20190824212754-2209d2e36aea/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= -github.com/jackc/pgconn v0.0.0-20190824221829-beba629bb5d5 h1:fGy7MTsuLbREyDs7o1m03cGEgwMrKyUP488Z9zlmR/k= -github.com/jackc/pgconn v0.0.0-20190824221829-beba629bb5d5/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= -github.com/jackc/pgconn v0.0.0-20190825004843-78abbdf1d7ee h1:uHUd7Cnu7QjzOqOWj6MYqz8zvNGoDZG1tK6jQASP2j0= -github.com/jackc/pgconn v0.0.0-20190825004843-78abbdf1d7ee/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= -github.com/jackc/pgconn v0.0.0-20190825013903-da9fc85c4404 h1:ufozZrr6aX2OernEsOAA1Ewa8agH/FdeNbWFDvespbM= -github.com/jackc/pgconn v0.0.0-20190825013903-da9fc85c4404/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= -github.com/jackc/pgconn v0.0.0-20190825044326-6feea0c1c57d h1:U65ZwSZafY7s0wopPUpkess6d9cq1+sbgn29fTU8oUc= -github.com/jackc/pgconn v0.0.0-20190825044326-6feea0c1c57d/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= -github.com/jackc/pgconn v0.0.0-20190825052232-e6cf51b304f1 h1:s+1P8J/6SAtclZhitBNe4Qav977uvklzETfdibAVC5k= -github.com/jackc/pgconn v0.0.0-20190825052232-e6cf51b304f1/go.mod h1:hdtls2SWJnLvdibz+9nF6uu8qnDEHJv2pLK/NCOI4yY= +github.com/jackc/pgconn v0.0.0-20190827231150-66aaed7c9eb0 h1:jIDrxO/xGyPFI+khT670Hv4DcfU/Bml3A1layKKXyDo= +github.com/jackc/pgconn v0.0.0-20190827231150-66aaed7c9eb0/go.mod h1:hdtls2SWJnLvdibz+9nF6uu8qnDEHJv2pLK/NCOI4yY= github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= @@ -54,6 +44,7 @@ github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9 h1:KLBBPU++1T3DHtm1B1 github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -133,6 +124,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456 h1:ng0gs1AKnRRuEMZoTLLlbOd+C17zUDepwGQBb/n+JVg= +golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -140,8 +133,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190824210100-c2567a220953/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190825031127-d72b05d2b1b6/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373 h1:PPwnA7z1Pjf7XYaBP9GL1VAMZmcIWyFz7QCMSIIa3Bg= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522 h1:bhOzK9QyoD0ogCnFro1m2mz41+Ib0oOhfJnBp5MR4K4= diff --git a/query_test.go b/query_test.go index 287f4a31..8439a47f 100644 --- a/query_test.go +++ b/query_test.go @@ -20,7 +20,7 @@ import ( uuid "github.com/satori/go.uuid" "github.com/shopspring/decimal" "github.com/stretchr/testify/assert" - errors "golang.org/x/xerrors" + "github.com/stretchr/testify/require" ) func TestConnQueryScan(t *testing.T) { @@ -288,9 +288,7 @@ func TestConnQueryCloseEarlyWithErrorOnWire(t *testing.T) { if err != nil { t.Fatalf("conn.Query failed: %v", err) } - if errors.Is(err, pgconn.ErrNoBytesSent) { - t.Error("Expected bytes to be sent to server") - } + assert.False(t, pgconn.SafeToRetry(err)) rows.Close() ensureConnValid(t, conn) @@ -480,9 +478,7 @@ func TestQueryEncodeError(t *testing.T) { if err != nil { t.Errorf("conn.Query failure: %v", err) } - if errors.Is(err, pgconn.ErrNoBytesSent) { - t.Error("Expected bytes to be sent to server") - } + assert.False(t, pgconn.SafeToRetry(err)) defer rows.Close() rows.Next() @@ -1309,12 +1305,8 @@ func TestQueryCloseBefore(t *testing.T) { closeConn(t, conn) _, err := conn.Query(context.Background(), "select 1") - if err == nil { - t.Fatal("Expected network error") - } - if !errors.Is(err, pgconn.ErrNoBytesSent) { - t.Error("Expected bytes to be sent to server") - } + require.Error(t, err) + assert.True(t, pgconn.SafeToRetry(err)) } func TestRowsFromResultReader(t *testing.T) {