nats: AC-G15b keeps a history's messages at a shorter age and turns the snapshot store's refusal when full on in place

Builds: design 47 H2 H-A-686
This commit is contained in:
2026-11-25 19:11:14 +01:00
parent e2e82311c9
commit f8e40950e1
@@ -672,6 +672,20 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
if !ok {
t.Fatal("the bus holds no rc_records_snapshot")
}
// The snapshot store as a keeper before H2 made it: dropping its oldest when full, which the asked form refuses.
old := snap.Config
old.Discard = jetstream.DiscardOld
if _, err := js.UpdateStream(ctx, old); err != nil {
t.Fatal(err)
}
// A message in the history, which the shorter age asked keeps (it is younger than the age).
hist, ok := held("rc_records")
if !ok || hist.Config.MaxAge != 90*24*time.Hour {
t.Fatalf("the history is %+v: want its age 90 days", hist)
}
if _, err := js.Publish(ctx, strings.TrimSuffix(hist.Config.Subjects[0], ">")+"i1", []byte("x")); err != nil {
t.Fatal(err)
}
for i := range 3 {
if _, err := js.Publish(ctx, strings.TrimSuffix(snap.Config.Subjects[0], ">")+fmt.Sprintf("k%d", i), []byte("x")); err != nil {
t.Fatal(err)
@@ -687,7 +701,7 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
}
}
ending := plain
ending.Configuration = map[string]json.RawMessage{"ended-days": json.RawMessage("30"), "max-age-days": json.RawMessage("90")}
ending.Configuration = map[string]json.RawMessage{"ended-days": json.RawMessage("30"), "max-age-days": json.RawMessage("30")}
accepted("rc", 21, ending)
eventually(t, "drifted rc records", saidHas("drifted rc records"))
r := keeper.Request{ID: "rc1", Verb: keeper.VerbRecreate, Module: "rc", Local: "records", Caller: "person.jo", Why: "take the lifetimes", At: time.Now(), AskExpires: time.Now().Add(keeper.AskLasts)}
@@ -713,6 +727,12 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
eventually(t, "recreated rc records", saidHas("recreated rc records"))
snap, _ = held("rc_records_snapshot")
state, _ := held("KV_rc_records_state")
if hist, _ = held("rc_records"); hist.Config.MaxAge != 30*24*time.Hour || hist.State.Msgs != 1 {
t.Errorf("the history holds %d messages (want 1) at the age %s (want 30 days): changed in place to the shorter age", hist.State.Msgs, hist.Config.MaxAge)
}
if snap.Config.Discard != jetstream.DiscardNew {
t.Errorf("the snapshot store still drops its oldest when full (discard %v): the refusal when full turned on in place", snap.Config.Discard)
}
if snap.State.Msgs != 3 || state.State.Msgs != 2 || !snap.Config.AllowMsgTTL || !state.Config.AllowMsgTTL {
t.Errorf("the snapshot store holds %d messages (want 3, AllowMsgTTL %v), the state bucket %d keys (want 2, AllowMsgTTL %v): changed in place",
snap.State.Msgs, snap.Config.AllowMsgTTL, state.State.Msgs, state.Config.AllowMsgTTL)