From 0ec512b504657ea3e4b58def04ac1a763e776178 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Mon, 29 May 2023 10:43:15 -0500 Subject: [PATCH] Fix: possible fail in goroutine after test has completed --- pgconn/pgconn_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pgconn/pgconn_test.go b/pgconn/pgconn_test.go index 330b5d43..6c933a33 100644 --- a/pgconn/pgconn_test.go +++ b/pgconn/pgconn_test.go @@ -2233,13 +2233,14 @@ func TestConnCancelRequest(t *testing.T) { multiResult := pgConn.Exec(ctx, "select 'Hello, world', pg_sleep(2)") + errChan := make(chan error) go func() { // The query is actually sent when multiResult.NextResult() is called. So wait to ensure it is sent. // Once Flush is available this could use that instead. time.Sleep(500 * time.Millisecond) err := pgConn.CancelRequest(ctx) - require.NoError(t, err) + errChan <- err }() for multiResult.NextResult() { @@ -2249,6 +2250,9 @@ func TestConnCancelRequest(t *testing.T) { require.IsType(t, &pgconn.PgError{}, err) require.Equal(t, "57014", err.(*pgconn.PgError).Code) + err = <-errChan + require.NoError(t, err) + ensureConnValid(t, pgConn) }