@@ -735,8 +735,21 @@ func publishAndConsumeMQTTMsg(hostname, nodePort, username, password string, ove
735735 SetProtocolVersion (4 ) // RabbitMQ MQTT plugin targets MQTT 3.1.1
736736
737737 c := mqtt .NewClient (opts )
738- token := c .Connect ()
739- Expect (token .Wait ()).To (BeTrue ())
738+
739+ var token mqtt.Token
740+ for retry := 0 ; retry < 5 ; retry ++ {
741+ fmt .Printf ("Attempt #%d to connect using MQTT\n " , retry )
742+ token = c .Connect ()
743+ // Waits for the network request to reach the destination and receive a response
744+ Expect (token .WaitTimeout (3 * time .Second )).To (BeTrue ())
745+
746+ if err := token .Error (); err == nil {
747+ break
748+ }
749+
750+ time .Sleep (2 * time .Second )
751+ }
752+
740753 Expect (token .Error ()).ToNot (HaveOccurred ())
741754
742755 topic := "tests/mqtt"
@@ -769,12 +782,23 @@ func publishAndConsumeMQTTMsg(hostname, nodePort, username, password string, ove
769782}
770783
771784func publishAndConsumeSTOMPMsg (hostname , stompNodePort , username , password string ) {
772- conn , err := stomp .Dial ("tcp" ,
773- fmt .Sprintf ("%s:%s" , hostname , stompNodePort ),
774- stomp .ConnOpt .Login (username , password ),
775- stomp .ConnOpt .AcceptVersion (stomp .V12 ), // RabbitMQ STOMP plugin supports STOMP versions 1.0 through 1.2
776- stomp .ConnOpt .Host ("/" ), // default virtual host
777- )
785+ var conn * stomp.Conn
786+ var err error
787+ for retry := 0 ; retry < 5 ; retry ++ {
788+ fmt .Printf ("Attempt #%d to connect using STOMP\n " , retry )
789+ conn , err = stomp .Dial ("tcp" ,
790+ fmt .Sprintf ("%s:%s" , hostname , stompNodePort ),
791+ stomp .ConnOpt .Login (username , password ),
792+ stomp .ConnOpt .AcceptVersion (stomp .V12 ), // RabbitMQ STOMP plugin supports STOMP versions 1.0 through 1.2
793+ stomp .ConnOpt .Host ("/" ), // default virtual host
794+ )
795+
796+ if err == nil {
797+ break
798+ }
799+
800+ time .Sleep (2 * time .Second )
801+ }
778802 Expect (err ).ToNot (HaveOccurred ())
779803
780804 queue := "/queue/system-tests-stomp"
0 commit comments