mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Eliminate race condition in TestListenNotifyWhileBusyIsSafe
This commit is contained in:
parent
693ba65a4a
commit
0a3cfab73e
@ -527,6 +527,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
listenerDone := make(chan bool)
|
listenerDone := make(chan bool)
|
||||||
|
notifierDone := 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)
|
||||||
@ -547,7 +548,9 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
|
|||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var n int32
|
var n int32
|
||||||
rows.Scan(&n)
|
if err := rows.Scan(&n); err != nil {
|
||||||
|
t.Fatalf("Row scan failed: %v", err)
|
||||||
|
}
|
||||||
sum += n
|
sum += n
|
||||||
rowCount++
|
rowCount++
|
||||||
}
|
}
|
||||||
@ -571,6 +574,9 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
|
|||||||
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)
|
||||||
|
defer func() {
|
||||||
|
notifierDone <- true
|
||||||
|
}()
|
||||||
|
|
||||||
for i := 0; i < 100000; i++ {
|
for i := 0; i < 100000; i++ {
|
||||||
mustExec(t, conn, "notify busysafe, 'hello'")
|
mustExec(t, conn, "notify busysafe, 'hello'")
|
||||||
@ -579,6 +585,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
<-listenerDone
|
<-listenerDone
|
||||||
|
<-notifierDone
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListenNotifySelfNotification(t *testing.T) {
|
func TestListenNotifySelfNotification(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user