2
0

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.
This commit is contained in:
Jack Christensen
2023-02-27 20:30:33 -06:00
parent 7ec6ee7b0a
commit 80eb6e1859
+4 -3
View File
@@ -545,6 +545,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
listenerDone := make(chan bool) listenerDone := make(chan bool)
notifierDone := make(chan bool) notifierDone := make(chan bool)
listening := make(chan bool)
go func() { go func() {
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE")) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
@@ -553,6 +554,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
}() }()
mustExec(t, conn, "listen busysafe") mustExec(t, conn, "listen busysafe")
listening <- true
for i := 0; i < 5000; i++ { for i := 0; i < 5000; i++ {
var sum int32 var sum int32
@@ -588,8 +590,6 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
t.Errorf("Wrong number of rows: %v", rowCount) t.Errorf("Wrong number of rows: %v", rowCount)
return return
} }
time.Sleep(1 * time.Microsecond)
} }
}() }()
@@ -600,9 +600,10 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
notifierDone <- true notifierDone <- true
}() }()
<-listening
for i := 0; i < 100000; i++ { for i := 0; i < 100000; i++ {
mustExec(t, conn, "notify busysafe, 'hello'") mustExec(t, conn, "notify busysafe, 'hello'")
time.Sleep(1 * time.Microsecond)
} }
}() }()