From 1e3961bd0ea4d624dc181734894db99b9e5946f4 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Wed, 24 Apr 2019 16:49:52 -0500 Subject: [PATCH] Fix flickering test --- pgconn_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pgconn_test.go b/pgconn_test.go index b7cb4036..dcbbfc89 100644 --- a/pgconn_test.go +++ b/pgconn_test.go @@ -1289,7 +1289,12 @@ func TestConnCancelRequest(t *testing.T) { require.NoError(t, err) defer closeConn(t, pgConn) - multiResult := pgConn.Exec(context.Background(), "select 'Hello, world', pg_sleep(5)") + multiResult := pgConn.Exec(context.Background(), "select 'Hello, world', pg_sleep(2)") + + // This test flickers without the Sleep. It appears that since Exec only sends the query and returns without awaiting a + // response that the CancelRequest can race it and be received before the query is running and cancellable. So wait a + // few milliseconds. + time.Sleep(50 * time.Millisecond) err = pgConn.CancelRequest(context.Background()) require.NoError(t, err)