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:
@@ -463,10 +463,9 @@ func (pgConn *PgConn) hardClose() error {
|
|||||||
return pgConn.conn.Close()
|
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
|
// IsClosed reports if the connection has been closed.
|
||||||
// underlying connection.
|
func (pgConn *PgConn) IsClosed() bool {
|
||||||
func (pgConn *PgConn) IsAlive() bool {
|
return pgConn.status < connStatusIdle
|
||||||
return pgConn.status >= connStatusIdle
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// lock locks the connection. It panics if the connection is already locked or is closed.
|
// lock locks the connection. It panics if the connection is already locked or is closed.
|
||||||
|
|||||||
+5
-5
@@ -433,7 +433,7 @@ func TestConnExecContextCanceled(t *testing.T) {
|
|||||||
}
|
}
|
||||||
err = multiResult.Close()
|
err = multiResult.Close()
|
||||||
assert.Equal(t, context.DeadlineExceeded, err)
|
assert.Equal(t, context.DeadlineExceeded, err)
|
||||||
assert.False(t, pgConn.IsAlive())
|
assert.True(t, pgConn.IsClosed())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnExecContextPrecanceled(t *testing.T) {
|
func TestConnExecContextPrecanceled(t *testing.T) {
|
||||||
@@ -566,7 +566,7 @@ func TestConnExecParamsCanceled(t *testing.T) {
|
|||||||
assert.Equal(t, pgconn.CommandTag(nil), commandTag)
|
assert.Equal(t, pgconn.CommandTag(nil), commandTag)
|
||||||
assert.Equal(t, context.DeadlineExceeded, err)
|
assert.Equal(t, context.DeadlineExceeded, err)
|
||||||
|
|
||||||
assert.False(t, pgConn.IsAlive())
|
assert.True(t, pgConn.IsClosed())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnExecParamsPrecanceled(t *testing.T) {
|
func TestConnExecParamsPrecanceled(t *testing.T) {
|
||||||
@@ -692,7 +692,7 @@ func TestConnExecPreparedCanceled(t *testing.T) {
|
|||||||
commandTag, err := result.Close()
|
commandTag, err := result.Close()
|
||||||
assert.Equal(t, pgconn.CommandTag(nil), commandTag)
|
assert.Equal(t, pgconn.CommandTag(nil), commandTag)
|
||||||
assert.Equal(t, context.DeadlineExceeded, err)
|
assert.Equal(t, context.DeadlineExceeded, err)
|
||||||
assert.False(t, pgConn.IsAlive())
|
assert.True(t, pgConn.IsClosed())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnExecPreparedPrecanceled(t *testing.T) {
|
func TestConnExecPreparedPrecanceled(t *testing.T) {
|
||||||
@@ -1142,7 +1142,7 @@ func TestConnCopyToCanceled(t *testing.T) {
|
|||||||
assert.True(t, errors.Is(err, context.DeadlineExceeded))
|
assert.True(t, errors.Is(err, context.DeadlineExceeded))
|
||||||
assert.Equal(t, pgconn.CommandTag(nil), res)
|
assert.Equal(t, pgconn.CommandTag(nil), res)
|
||||||
|
|
||||||
assert.False(t, pgConn.IsAlive())
|
assert.True(t, pgConn.IsClosed())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnCopyToPrecanceled(t *testing.T) {
|
func TestConnCopyToPrecanceled(t *testing.T) {
|
||||||
@@ -1233,7 +1233,7 @@ func TestConnCopyFromCanceled(t *testing.T) {
|
|||||||
assert.Equal(t, int64(0), ct.RowsAffected())
|
assert.Equal(t, int64(0), ct.RowsAffected())
|
||||||
assert.True(t, errors.Is(err, context.DeadlineExceeded))
|
assert.True(t, errors.Is(err, context.DeadlineExceeded))
|
||||||
|
|
||||||
assert.False(t, pgConn.IsAlive())
|
assert.True(t, pgConn.IsClosed())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnCopyFromPrecanceled(t *testing.T) {
|
func TestConnCopyFromPrecanceled(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user