mirror of
https://github.com/redis/go-redis.git
synced 2025-12-02 06:22:31 +03:00
fix flaky tests
This commit is contained in:
@@ -8905,27 +8905,37 @@ var _ = Describe("Commands", func() {
|
||||
const key = "latency-monitor-threshold"
|
||||
|
||||
old := client.ConfigGet(ctx, key).Val()
|
||||
client.ConfigSet(ctx, key, "1")
|
||||
// Use a higher threshold (100ms) to avoid capturing normal operations
|
||||
// that could cause flakiness due to timing variations
|
||||
client.ConfigSet(ctx, key, "100")
|
||||
defer client.ConfigSet(ctx, key, old[key])
|
||||
|
||||
result, err := client.Latency(ctx).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(result)).Should(Equal(0))
|
||||
|
||||
err = client.Do(ctx, "DEBUG", "SLEEP", 0.01).Err()
|
||||
// Use a longer sleep (150ms) to ensure it exceeds the 100ms threshold
|
||||
err = client.Do(ctx, "DEBUG", "SLEEP", 0.15).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
result, err = client.Latency(ctx).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(result)).Should(Equal(1))
|
||||
Expect(len(result)).Should(BeNumerically(">=", 1))
|
||||
|
||||
// reset latency by event name
|
||||
err = client.LatencyReset(ctx, result[0].Name).Err()
|
||||
eventName := result[0].Name
|
||||
err = client.LatencyReset(ctx, eventName).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Verify the specific event was reset (not that all events are gone)
|
||||
// This avoids flakiness from other operations triggering latency events
|
||||
result, err = client.Latency(ctx).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(result)).Should(Equal(0))
|
||||
for _, event := range result {
|
||||
if event.Name == eventName {
|
||||
Fail("Event " + eventName + " should have been reset")
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -700,8 +700,25 @@ func TestConnectionHook(t *testing.T) {
|
||||
t.Errorf("Connection should be pooled after handoff (shouldPool=%v, shouldRemove=%v)", shouldPool, shouldRemove)
|
||||
}
|
||||
|
||||
// Wait for handoff to complete
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
// Wait for handoff to complete with polling instead of fixed sleep
|
||||
// This avoids flakiness on slow CI runners where 50ms may not be enough
|
||||
maxWait := 500 * time.Millisecond
|
||||
pollInterval := 10 * time.Millisecond
|
||||
deadline := time.Now().Add(maxWait)
|
||||
|
||||
handoffCompleted := false
|
||||
for time.Now().Before(deadline) {
|
||||
if conn.IsUsable() && !processor.IsHandoffPending(conn) {
|
||||
handoffCompleted = true
|
||||
break
|
||||
}
|
||||
time.Sleep(pollInterval)
|
||||
}
|
||||
|
||||
if !handoffCompleted {
|
||||
t.Fatalf("Handoff did not complete within %v (IsUsable=%v, IsHandoffPending=%v)",
|
||||
maxWait, conn.IsUsable(), processor.IsHandoffPending(conn))
|
||||
}
|
||||
|
||||
// After handoff completion, connection should be usable again
|
||||
if !conn.IsUsable() {
|
||||
|
||||
Reference in New Issue
Block a user