Skip to content

Commit 48d2f01

Browse files
committed
Do not expect success on token timeout
The retry logic should contain no expectations because it's expected to fail sometimes and retry in such cases.
1 parent 008183c commit 48d2f01

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

system_tests/utils.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -745,20 +745,18 @@ func publishAndConsumeMQTTMsg(hostname, nodePort, username, password string, ove
745745
c := mqtt.NewClient(opts)
746746

747747
var token mqtt.Token
748-
for retry := 0; retry < 5; retry++ {
749-
fmt.Printf("Attempt #%d to connect using MQTT\n", retry)
748+
Eventually(func() bool {
750749
token = c.Connect()
751750
// Waits for the network request to reach the destination and receive a response
752-
Expect(token.WaitTimeout(3 * time.Second)).To(BeTrue())
751+
if !token.WaitTimeout(3 * time.Second) {
752+
return false
753+
}
753754

754755
if err := token.Error(); err == nil {
755-
break
756+
return true
756757
}
757-
758-
time.Sleep(2 * time.Second)
759-
}
760-
761-
Expect(token.Error()).ToNot(HaveOccurred())
758+
return false
759+
}, 10, 2).Should(BeTrue(), "Expected to be able to connect to MQTT port")
762760

763761
topic := "tests/mqtt"
764762
msgReceived := false

0 commit comments

Comments
 (0)