From 0a3cfab73eee92aebd6f44c7c42c25f92833d836 Mon Sep 17 00:00:00 2001 From: Adam Pantel Date: Fri, 22 Nov 2019 11:02:01 -0500 Subject: [PATCH] Eliminate race condition in TestListenNotifyWhileBusyIsSafe --- conn_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/conn_test.go b/conn_test.go index f2103775..b8b5f460 100644 --- a/conn_test.go +++ b/conn_test.go @@ -527,6 +527,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) { t.Parallel() listenerDone := make(chan bool) + notifierDone := make(chan bool) go func() { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) @@ -547,7 +548,9 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) { for rows.Next() { var n int32 - rows.Scan(&n) + if err := rows.Scan(&n); err != nil { + t.Fatalf("Row scan failed: %v", err) + } sum += n rowCount++ } @@ -571,6 +574,9 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) { go func() { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) + defer func() { + notifierDone <- true + }() for i := 0; i < 100000; i++ { mustExec(t, conn, "notify busysafe, 'hello'") @@ -579,6 +585,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) { }() <-listenerDone + <-notifierDone } func TestListenNotifySelfNotification(t *testing.T) {