From 80eb6e1859e6e4483f0780503f56ae7ed5984e04 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Mon, 27 Feb 2023 20:30:33 -0600 Subject: [PATCH] Remove sleeps in test Sleeping for a microsecond on Windows actually takes 10ms. This caused the test to never finish. Instead use channel to ensure the two goroutines start working at the same time and remove the sleeps. --- conn_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/conn_test.go b/conn_test.go index f32193ae..f1ff2da2 100644 --- a/conn_test.go +++ b/conn_test.go @@ -545,6 +545,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) { listenerDone := make(chan bool) notifierDone := make(chan bool) + listening := make(chan bool) go func() { conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) defer closeConn(t, conn) @@ -553,6 +554,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) { }() mustExec(t, conn, "listen busysafe") + listening <- true for i := 0; i < 5000; i++ { var sum int32 @@ -588,8 +590,6 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) { t.Errorf("Wrong number of rows: %v", rowCount) return } - - time.Sleep(1 * time.Microsecond) } }() @@ -600,9 +600,10 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) { notifierDone <- true }() + <-listening + for i := 0; i < 100000; i++ { mustExec(t, conn, "notify busysafe, 'hello'") - time.Sleep(1 * time.Microsecond) } }()