From b1178a7dcd117c8f496f0bb335a16b78a68bc516 Mon Sep 17 00:00:00 2001 From: "pulse-triage[bot]" <249995291+pulse-triage[bot]@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:38:36 +0000 Subject: [PATCH] Bound the initial circuit-breaker timestamp by construction The race suite observed a correct timestamp before the old lower bound because the fixture sampled the clock after constructing the breaker. Bracket the constructor itself and verify that closed state and its initial transition share that timestamp. Contract-Neutral: Only the closed-state test clock window changes. Breaker policy, thresholds, timestamp production, and open and half-open fixtures are unchanged. Change-source: pulse-maintainer --- internal/monitoring/circuit_breaker_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/monitoring/circuit_breaker_test.go b/internal/monitoring/circuit_breaker_test.go index e186e55867..227dd1e885 100644 --- a/internal/monitoring/circuit_breaker_test.go +++ b/internal/monitoring/circuit_breaker_test.go @@ -487,8 +487,9 @@ func TestCircuitBreaker_Allow(t *testing.T) { func TestCircuitBreaker_StateDetails(t *testing.T) { t.Run("closed state", func(t *testing.T) { + beforeCreate := time.Now() cb := newCircuitBreaker(3, 5*time.Second, 5*time.Minute, 30*time.Second) - beforeCreate := time.Now().Add(-time.Millisecond) + afterCreate := time.Now() state, failures, retryAt, since, lastTransition := cb.stateDetails() @@ -501,11 +502,11 @@ func TestCircuitBreaker_StateDetails(t *testing.T) { if !retryAt.IsZero() { t.Errorf("retryAt = %v, want zero time", retryAt) } - if since.Before(beforeCreate) { - t.Errorf("since = %v, should be after %v", since, beforeCreate) + if since.Before(beforeCreate) || since.After(afterCreate) { + t.Errorf("since = %v, want within construction window [%v, %v]", since, beforeCreate, afterCreate) } - if lastTransition.Before(beforeCreate) { - t.Errorf("lastTransition = %v, should be after %v", lastTransition, beforeCreate) + if !lastTransition.Equal(since) { + t.Errorf("lastTransition = %v, want initial state timestamp %v", lastTransition, since) } })