mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
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:
+4
-2
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user