Files
zt/router/state/subscription_test.go
zeekay dc626018a2 Renew the data model subscription before it lapses
The router checked its data model subscription every 30 seconds and
renewed it only once it had lapsed, and the controller pushes nothing
to a lapsed subscriber, so every five minutes the router went up to 30
seconds without changes and then took them in one burst.

Renew once a minute remains, so a check always lands in time.

Claude-Session: https://claude.ai/code/session_01HuMDfgFssPUptYUzgZ6Cp8
2026-09-23 20:54:24 -07:00

26 lines
862 B
Go

package state
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
// A subscription is renewed at a check before it lapses, whatever the phase of the checks
// against the moment it was taken, so the controller never stops pushing changes.
func TestSubscriptionRenewedBeforeItLapses(t *testing.T) {
req := require.New(t)
taken := time.Date(2026, 9, 24, 3, 20, 26, 0, time.UTC)
timeout := taken.Add(DefaultSubscriptionTimeout)
for phase := time.Duration(0); phase < subscriptionCheck; phase += time.Second {
check := taken.Add(phase)
for !subscriptionDue(check, timeout) {
check = check.Add(subscriptionCheck)
}
req.True(check.Before(timeout), "phase %v: renewed at %v, subscription lapsed at %v", phase, check, timeout)
req.False(subscriptionDue(taken.Add(phase), timeout), "phase %v: renewed as soon as taken", phase)
}
}