fix(test): fix race condition in sentinel failover metric test (#3824)

Root cause: a race condition between two independent goroutines
that detect failover completion:

1. The test's polling loop queries sentinel.Master() directly,
   which returns as soon as the sentinel server reports the new
   master.

2. The ConnectionClosed metric callback is triggered asynchronously
   via the pubsub "+switch-master" message. The pubsub listener
   runs in a separate goroutine closes stale connections and emits
   the CloseReasonFailover metric.

When the test's polling loop breaks before the pubsub listener has
processed the "+switch-master" message, the metric callback does
fire eventually, but after the assertion has already failed.

Fix: replace the direct Expect assertion with Eventually.
This commit is contained in:
cxljs
2026-05-22 20:24:56 +03:00
committed by GitHub
parent 14e322935b
commit cf470ca022
+4 -2
View File
@@ -818,8 +818,10 @@ var _ = Describe("Sentinel Failover with Conns", Serial, Ordered, func() {
time.Sleep(500 * time.Millisecond)
}
Expect(failoverCloseCount.Load()).To(Equal(int32(1)),
"Expected exactly 1 CloseReasonFailover metric, got %d", failoverCloseCount.Load())
Eventually(func() int32 {
return failoverCloseCount.Load()
}, "5s", "100ms").Should(Equal(int32(1)),
"Expected exactly 1 CloseReasonFailover metric")
multi, err := client.Do(ctx, "MULTI").Result()
Expect(err).NotTo(HaveOccurred())