From e27323a951b4304b74f92ea90dba87e0ac97a03c Mon Sep 17 00:00:00 2001 From: clyang82 Date: Fri, 3 Jan 2025 17:20:39 +0800 Subject: [PATCH] Fix integration test Signed-off-by: clyang82 --- test/integration/db_listener_test.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/test/integration/db_listener_test.go b/test/integration/db_listener_test.go index e168c83d..aa1f07d3 100644 --- a/test/integration/db_listener_test.go +++ b/test/integration/db_listener_test.go @@ -2,9 +2,12 @@ package integration import ( "context" + "fmt" "testing" "time" + . "github.com/onsi/gomega" + "github.com/openshift-online/maestro/test" ) @@ -34,18 +37,20 @@ func TestWaitForNotification(t *testing.T) { // Simulate an errListenerClosed and wait for the listener to be recreated listener.Close() - time.Sleep(2 * time.Second) - var newListenerId string - g2.Raw("SELECT pid FROM pg_stat_activity WHERE query LIKE 'LISTEN%'").Scan(&newListenerId) - if newListenerId == "" { - t.Errorf("the new Listener was not created") - } + Eventually(func() error { + var newListenerId string + g2.Raw("SELECT pid FROM pg_stat_activity WHERE query LIKE 'LISTEN%'").Scan(&newListenerId) + if newListenerId == "" { + return fmt.Errorf("the new Listener was not created") + } + // Validate the listener was recreated + if originalListenerId == newListenerId { + return fmt.Errorf("Listener was not recreated") + } + return nil + }, 10*time.Second, 1*time.Second).Should(Succeed()) - // Validate the listener was recreated - if originalListenerId == newListenerId { - t.Errorf("Listener was not recreated") - } // send a notification to the new listener g2.Exec("NOTIFY events, 'test'")