Pin shared image and object state across queue refusals

This commit is contained in:
pingqiu committed 2026-12-02 07:04:41 -08:00
1 parent 7fd40ec621
commit b8bca3382e
1 file changed
+29
@@ -1,12 +1,23 @@
package layout
import (
"bytes"
"context"
"errors"
"reflect"
"testing"
)
// Copy bytes as well as metadata: retaining object pointers would let an
// in-place mutation change both the observed state and the expected value.
func queueObjectSnapshot(s *chainStore) map[string]memObject {
out := make(map[string]memObject, len(s.objs))
for name, o := range s.objs {
out[name] = memObject{data: append([]byte(nil), o.data...), meta: o.meta}
}
return out
}
func TestDeleteIntentQueueFullKeepsBothWorkAndReferences(t *testing.T) {
ctx := context.Background()
s, first, p := deleteIntentFixture(t)
@@ -36,9 +47,23 @@ func TestDeleteIntentQueueFullKeepsBothWorkAndReferences(t *testing.T) {
}
// Draining the first slot must preserve weekly's live image. Retry then
// atomically unlinks that exact incarnation and publishes its own work.
weekly := before.Snapshots["weekly"]
shared := queueObjectSnapshot(s)
if _, err := RunConsumeSnapshotDeleteIntent(ctx, s, r); err != nil {
t.Fatal(err)
}
if got, found := s.h.Snapshots["weekly"]; !found || !reflect.DeepEqual(got, weekly) {
t.Fatalf("first drain changed the retained weekly incarnation: got=%+v want=%+v", got, weekly)
}
// The page names the shared root, its segment and payload. Check all of
// them now, before weekly is unlinked and reclamation becomes permitted.
for _, rel := range p.Entries {
want, found := shared[s.full(rel)]
got, present := s.objs[s.full(rel)]
if !found || !present || !bytes.Equal(got.data, want.data) || got.meta != want.meta {
t.Fatalf("first drain changed weekly's shared image object %s", rel)
}
}
if _, err := RunDeleteSnapshotWithIntent(ctx, s, s.h.Gen, second); err != nil {
t.Fatal(err)
}
@@ -70,12 +95,16 @@ func TestGenericListQueueFullCannotOverwritePendingWork(t *testing.T) {
}
second := ListCursor{Ref: ref, Kind: p.Kind, Producer: p.Producer, Generation: p.Generation}
before, updates := s.h.clone(), s.updates
objects, writes := queueObjectSnapshot(s), append([]string(nil), s.writes...)
if _, err := RunPublishList(ctx, s, me, "s1", s.h.Gen, second); !errors.Is(err, ErrQueueFull) {
t.Fatalf("want typed queue_full, got %v", err)
}
if !reflect.DeepEqual(*s.h, before) || s.updates != updates {
t.Fatal("full queue was overwritten")
}
if !reflect.DeepEqual(queueObjectSnapshot(s), objects) || !reflect.DeepEqual(s.writes, writes) {
t.Fatal("generic full-slot refusal mutated objects or attempted an object write")
}
if _, err := RunPublishList(ctx, s, me, "s1", first.Generation-1, first); err != nil {
t.Fatalf("same-list replay refused: %v", err)
}