Skip to content

Commit cf2d5d3

Browse files
committed
fix flaky tests
1 parent b635202 commit cf2d5d3

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

commands_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8905,27 +8905,37 @@ var _ = Describe("Commands", func() {
89058905
const key = "latency-monitor-threshold"
89068906

89078907
old := client.ConfigGet(ctx, key).Val()
8908-
client.ConfigSet(ctx, key, "1")
8908+
// Use a higher threshold (100ms) to avoid capturing normal operations
8909+
// that could cause flakiness due to timing variations
8910+
client.ConfigSet(ctx, key, "100")
89098911
defer client.ConfigSet(ctx, key, old[key])
89108912

89118913
result, err := client.Latency(ctx).Result()
89128914
Expect(err).NotTo(HaveOccurred())
89138915
Expect(len(result)).Should(Equal(0))
89148916

8915-
err = client.Do(ctx, "DEBUG", "SLEEP", 0.01).Err()
8917+
// Use a longer sleep (150ms) to ensure it exceeds the 100ms threshold
8918+
err = client.Do(ctx, "DEBUG", "SLEEP", 0.15).Err()
89168919
Expect(err).NotTo(HaveOccurred())
89178920

89188921
result, err = client.Latency(ctx).Result()
89198922
Expect(err).NotTo(HaveOccurred())
8920-
Expect(len(result)).Should(Equal(1))
8923+
Expect(len(result)).Should(BeNumerically(">=", 1))
89218924

89228925
// reset latency by event name
8923-
err = client.LatencyReset(ctx, result[0].Name).Err()
8926+
eventName := result[0].Name
8927+
err = client.LatencyReset(ctx, eventName).Err()
89248928
Expect(err).NotTo(HaveOccurred())
89258929

8930+
// Verify the specific event was reset (not that all events are gone)
8931+
// This avoids flakiness from other operations triggering latency events
89268932
result, err = client.Latency(ctx).Result()
89278933
Expect(err).NotTo(HaveOccurred())
8928-
Expect(len(result)).Should(Equal(0))
8934+
for _, event := range result {
8935+
if event.Name == eventName {
8936+
Fail("Event " + eventName + " should have been reset")
8937+
}
8938+
}
89298939
})
89308940
})
89318941
})

maintnotifications/pool_hook_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,25 @@ func TestConnectionHook(t *testing.T) {
700700
t.Errorf("Connection should be pooled after handoff (shouldPool=%v, shouldRemove=%v)", shouldPool, shouldRemove)
701701
}
702702

703-
// Wait for handoff to complete
704-
time.Sleep(50 * time.Millisecond)
703+
// Wait for handoff to complete with polling instead of fixed sleep
704+
// This avoids flakiness on slow CI runners where 50ms may not be enough
705+
maxWait := 500 * time.Millisecond
706+
pollInterval := 10 * time.Millisecond
707+
deadline := time.Now().Add(maxWait)
708+
709+
handoffCompleted := false
710+
for time.Now().Before(deadline) {
711+
if conn.IsUsable() && !processor.IsHandoffPending(conn) {
712+
handoffCompleted = true
713+
break
714+
}
715+
time.Sleep(pollInterval)
716+
}
717+
718+
if !handoffCompleted {
719+
t.Fatalf("Handoff did not complete within %v (IsUsable=%v, IsHandoffPending=%v)",
720+
maxWait, conn.IsUsable(), processor.IsHandoffPending(conn))
721+
}
705722

706723
// After handoff completion, connection should be usable again
707724
if !conn.IsUsable() {

0 commit comments

Comments
 (0)