diff --git a/seaweed-block/core/authority/observation_host.go b/seaweed-block/core/authority/observation_host.go index d1d851bbe7..853ed643db 100644 --- a/seaweed-block/core/authority/observation_host.go +++ b/seaweed-block/core/authority/observation_host.go @@ -258,7 +258,7 @@ func (h *ObservationHost) run(ctx context.Context) { var deadlineC <-chan time.Time var timer *time.Timer if at := h.store.NextDeadline(); !at.IsZero() { - d := at.Sub(h.store.now()) + d := at.Sub(h.store.clock()) if d < 10*time.Millisecond { d = 10 * time.Millisecond } diff --git a/seaweed-block/core/authority/observation_store.go b/seaweed-block/core/authority/observation_store.go index 7be900c3ee..00f6d4ab5d 100644 --- a/seaweed-block/core/authority/observation_store.go +++ b/seaweed-block/core/authority/observation_store.go @@ -285,6 +285,14 @@ func (s *ObservationStore) SetNowForTest(now func() time.Time) { s.now = now } +// clock reads the time from the clock source SetNowForTest may swap. +func (s *ObservationStore) clock() time.Time { + s.mu.Lock() + now := s.now + s.mu.Unlock() + return now() +} + // NewObservationStore constructs a store with the given freshness // configuration. `now` is injected for deterministic testing; pass // time.Now in production.