From 4fb1420a008200c6193e60b057aad78f5e14c9c3 Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Sun, 25 Oct 2026 09:15:09 +0100 Subject: [PATCH] test(stats): pin the relay client's clock to the fake gateway's The fake gateway's clock is fixed at 24 Oct 2026, but the client stamped each report with the real day, so from 25 Oct the gateway judged every test report stale and answered 400. statsrelaytest now gives the client the gateway's clock. Production is unchanged: box and gateway both read the real time. Co-Authored-By: Claude Opus 5.5 --- go/internal/statsrelay/statsrelay.go | 7 +++++++ go/internal/statsrelay/statsrelaytest/statsrelaytest.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/go/internal/statsrelay/statsrelay.go b/go/internal/statsrelay/statsrelay.go index 44c81f515..2610de8f6 100644 --- a/go/internal/statsrelay/statsrelay.go +++ b/go/internal/statsrelay/statsrelay.go @@ -102,6 +102,13 @@ func New(relay string, key ohttp.KeyConfig, client *http.Client) *Client { return &Client{relay: relay, key: key, http: client, now: time.Now} } +// WithClock makes c stamp reports with the day now reads. Tests pin it to +// the fake gateway's clock, so a fixed test date stays fresh. +func (c *Client) WithClock(now func() time.Time) *Client { + c.now = now + return c +} + // Relay is the relay's URL, for Settings. func (c *Client) Relay() string { return c.relay } diff --git a/go/internal/statsrelay/statsrelaytest/statsrelaytest.go b/go/internal/statsrelay/statsrelaytest/statsrelaytest.go index 1a30e5bfa..bee5e374a 100644 --- a/go/internal/statsrelay/statsrelaytest/statsrelaytest.go +++ b/go/internal/statsrelay/statsrelaytest/statsrelaytest.go @@ -86,7 +86,7 @@ func New(t testing.TB, now time.Time) (*statsrelay.Client, *Gateway, *Relay) { _, _ = io.Copy(w, resp.Body) })) t.Cleanup(rl.Close) - return statsrelay.New(rl.URL, g.Key, nil), g, rl + return statsrelay.New(rl.URL, g.Key, nil).WithClock(func() time.Time { return now }), g, rl } func (g *Gateway) add(msg []byte) int {