2
0

Replace IsAlive with IsClosed

IsAlive is ambiguous because the connection may be dead and we do not
know it. It implies the possibility of a ping. IsClosed is clearer -- it
does not promise the connection is alive only that it hasn't been
closed.

fixes #2
This commit is contained in:
Jack Christensen
2019-08-24 23:43:26 -05:00
parent da9fc85c44
commit 6feea0c1c5
2 changed files with 8 additions and 9 deletions
+3 -4
View File
@@ -463,10 +463,9 @@ func (pgConn *PgConn) hardClose() error {
return pgConn.conn.Close()
}
// TODO - rethink how to report status. At the moment this is just a temporary measure so pgx.Conn can detect death of
// underlying connection.
func (pgConn *PgConn) IsAlive() bool {
return pgConn.status >= connStatusIdle
// IsClosed reports if the connection has been closed.
func (pgConn *PgConn) IsClosed() bool {
return pgConn.status < connStatusIdle
}
// lock locks the connection. It panics if the connection is already locked or is closed.
+5 -5
View File
@@ -433,7 +433,7 @@ func TestConnExecContextCanceled(t *testing.T) {
}
err = multiResult.Close()
assert.Equal(t, context.DeadlineExceeded, err)
assert.False(t, pgConn.IsAlive())
assert.True(t, pgConn.IsClosed())
}
func TestConnExecContextPrecanceled(t *testing.T) {
@@ -566,7 +566,7 @@ func TestConnExecParamsCanceled(t *testing.T) {
assert.Equal(t, pgconn.CommandTag(nil), commandTag)
assert.Equal(t, context.DeadlineExceeded, err)
assert.False(t, pgConn.IsAlive())
assert.True(t, pgConn.IsClosed())
}
func TestConnExecParamsPrecanceled(t *testing.T) {
@@ -692,7 +692,7 @@ func TestConnExecPreparedCanceled(t *testing.T) {
commandTag, err := result.Close()
assert.Equal(t, pgconn.CommandTag(nil), commandTag)
assert.Equal(t, context.DeadlineExceeded, err)
assert.False(t, pgConn.IsAlive())
assert.True(t, pgConn.IsClosed())
}
func TestConnExecPreparedPrecanceled(t *testing.T) {
@@ -1142,7 +1142,7 @@ func TestConnCopyToCanceled(t *testing.T) {
assert.True(t, errors.Is(err, context.DeadlineExceeded))
assert.Equal(t, pgconn.CommandTag(nil), res)
assert.False(t, pgConn.IsAlive())
assert.True(t, pgConn.IsClosed())
}
func TestConnCopyToPrecanceled(t *testing.T) {
@@ -1233,7 +1233,7 @@ func TestConnCopyFromCanceled(t *testing.T) {
assert.Equal(t, int64(0), ct.RowsAffected())
assert.True(t, errors.Is(err, context.DeadlineExceeded))
assert.False(t, pgConn.IsAlive())
assert.True(t, pgConn.IsClosed())
}
func TestConnCopyFromPrecanceled(t *testing.T) {