From cbc6bac8c070b5e6752b4432b9cea36696fb3312 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 18 Oct 2026 13:51:37 +0200 Subject: [PATCH] Test chains start laid out; two tests follow delivery 2's meaning (issues 1121, 1108, 1109) The fixtures' fresh chain writes the layout marker, as the controller's start leaves a mesh, so the gate stays for the live start. A pending wait that ended unanswered is carried by the next one, so both are known. A hand send forgets what each assignment runs, so the test writes its build and commit after the send. --- internal/inventory/chain_pending_test.go | 5 +++-- internal/inventory/chain_store_test.go | 13 +++++++------ internal/inventory/fortest.go | 8 ++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/internal/inventory/chain_pending_test.go b/internal/inventory/chain_pending_test.go index 88ee416e..e9841507 100644 --- a/internal/inventory/chain_pending_test.go +++ b/internal/inventory/chain_pending_test.go @@ -53,8 +53,9 @@ func TestAPendingAssignmentIsAKeyOfTheAssignmentsBucket(t *testing.T) { if err != nil || next.ID == p.ID { t.Fatalf("a wait after one ended: %+v %v", next, err) } - if known, _ := inv.PendingKnown(ctx, []string{p.ID, next.ID}); known[p.ID] || !known[next.ID] { - t.Fatalf("known %v: the key holds the newer one now", known) + // The earlier wait ended unmade and nobody answered its condition, so the new wait carries it (issue 1108): both are on record. + if known, _ := inv.PendingKnown(ctx, []string{p.ID, next.ID}); !known[p.ID] || !known[next.ID] { + t.Fatalf("known %v: the key holds the newer one and carries the unanswered earlier one", known) } if history, _ := inv.chain.Assignments.History(ctx, "anchor.sensors"); len(history) != 2 { t.Fatalf("the earlier wait is in the key's history: %d values", len(history)) diff --git a/internal/inventory/chain_store_test.go b/internal/inventory/chain_store_test.go index 02b3353e..11d8d68c 100644 --- a/internal/inventory/chain_store_test.go +++ b/internal/inventory/chain_store_test.go @@ -289,12 +289,6 @@ func TestThePlansAreKeptInTheAssignmentsValuesAndNothingElseOfThemMoves(t *testi t.Fatal(err) } } - // A build and a commit put in the value by another write. - cur, _, _ := inv.chain.Assignments.Get(ctx, "anchor.dunst") - cur.Value.Build, cur.Value.Commit = "build-1", "c1" - if _, err := inv.chain.Assignments.Update(ctx, "anchor.dunst", cur.Value, cur.Revision); err != nil { - t.Fatal(err) - } record, _ := inv.NodeByName(ctx, node) digest := "sha256:" + strings.Repeat("d", 64) plan := Provisioning{Templates: TemplatesArchive{Source: "http://store:5000/v2/dunst/files/blobs/" + digest, @@ -304,6 +298,13 @@ func TestThePlansAreKeptInTheAssignmentsValuesAndNothingElseOfThemMoves(t *testi if err := inv.RecordSentWith(ctx, record.ID, "first", nil, 0, 0, Send{Digest: "first", Provisioning: raw}); err != nil { t.Fatal(err) } + // A build and a commit put in the value by another write, after the send: a send that carries no builds (a hand send, as this + // one) forgets what each assignment of its machine runs (issue 1109), so they are written once it is recorded. + cur, _, _ := inv.chain.Assignments.Get(ctx, "anchor.dunst") + cur.Value.Build, cur.Value.Commit = "build-1", "c1" + if _, err := inv.chain.Assignments.Update(ctx, "anchor.dunst", cur.Value, cur.Revision); err != nil { + t.Fatal(err) + } inv.SetProvisioningPlans(inv.SentProvisioningPlans) written, removed, err := inv.KeepAssignmentPlans(ctx) if err != nil || written != 2 || removed != 0 { diff --git a/internal/inventory/fortest.go b/internal/inventory/fortest.go index 790401c4..4cecc83c 100644 --- a/internal/inventory/fortest.go +++ b/internal/inventory/fortest.go @@ -67,6 +67,10 @@ func ForTest(t *testing.T) *Inventory { } // The chain is on the bus in a mesh; in a test it is in memory (ADR 0408). c := chain.InMemory(nil) + // A fresh test chain has nothing to lay out: it is laid out already, as the controller's start leaves a mesh (issue 1121). + if _, err := c.Builds.CreateRaw(t.Context(), chain.LayoutMarkerKey, []byte(`{}`)); err != nil { + t.Fatal(err) + } inv.UseChain(c) testChains.Store(os.Getenv(store.Variable(Name)), c) t.Cleanup(func() { testChains.Delete(os.Getenv(store.Variable(Name))) }) @@ -129,6 +133,10 @@ func ForTestBefore(t *testing.T, number int) (*Inventory, func()) { } // The chain is in memory, for what a test of the store before a migration reads of it. c := chain.InMemory(nil) + // A fresh test chain has nothing to lay out: it is laid out already, as the controller's start leaves a mesh (issue 1121). + if _, err := c.Builds.CreateRaw(t.Context(), chain.LayoutMarkerKey, []byte(`{}`)); err != nil { + t.Fatal(err) + } inv.UseChain(c) testChains.Store(os.Getenv(store.Variable(Name)), c) t.Cleanup(func() { testChains.Delete(os.Getenv(store.Variable(Name))) })