From 49505af6caca50b21617e969b6a04aa5cc0f27a1 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 19:15:59 +0100 Subject: [PATCH] A3d entry-kept-want-not-rewritten: the revision row also runs a pass and shows the want at the older fingerprint is not written again Builds: design 47 H2 H-A-757 --- .../mesh-delivery-assigner/halvesnone_test.go | 74 ++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halvesnone_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halvesnone_test.go index f5d8bc726..1f0397efc 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halvesnone_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/halvesnone_test.go @@ -4,7 +4,11 @@ import ( "context" "encoding/json" "errors" + "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient" + mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" + "git.novox.be/novox/mesh-sdk/go/catalogue" + "github.com/nats-io/nats.go/jetstream" "mesh-delivery-assigner/internal/buckets" "slices" "strings" @@ -136,11 +140,79 @@ func TestACatalogRevisionTakenInReleasesTheEntriesKept(t *testing.T) { t.Fatal("the entry is never answered") } } - raw, _ := mwc.EncodeWant(mwc.Want{Fp: old, Version: "1.0.0"}) + raw, _ := mwc.EncodeWant(mwc.Want{Fp: old, Version: "1.0.0", Pipeline: trunkBranch + ".5", Rank: 1, Run: "205", Self: true}) key, _ := mwc.WantKey("g14", "web") h.w.putEntry(buckets.Wants(), key, raw, 1, time.Now()) + // A pass over the want at the older fingerprint: the module's trunk entry names a newer one, so its needs come from the entry + // read by fingerprint. The want stands as the pass writes it, so a revision taken in and a pass after it write nothing. + writes := 0 + wantsKV := &writeCountingKV{memKV: memKV{values: map[string][]byte{}}, writes: &writes, key: key} + p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, time.Now()) + p.w, p.entries = h.w, h.branches.Entries + p.w.setTrunk(trunkBranch) + p.publishWants = func(string, any, string) error { return nil } + p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf) + p.ends.trunk = p.w.trunkName + p.reads = &engineReadsKept{} // g14 states want:version and the capability the entry needs + words, _ := json.Marshal(engineWords{Words: []string{nodeengine.ManifestReadWordWantVersion, "x"}, At: time.Now()}) + if err := p.reads.take("g14", words, false); err != nil { + t.Fatal(err) + } + digest := strings.Repeat("4", 64) + mod, _ := mcc.EncodeModule(seat.ModulesByModuleValue{Fp2: mcc.SourcePrefix2 + strings.Repeat("b", 64), Manifest: digest, Repository: "novox/web", Commit: strings.Repeat("1", 40), Path: mcc.RootPath}) + putModuleRaw(p.w, trunkBranch, "web", mod) + p.w.manifests[digest] = parsed{module: "web", manifest: catalogue.Manifest{Module: "web"}} + placeOn(t, p.w, "g14", "web") + p.w.mu.Lock() + p.w.runningHeard = true + p.w.mu.Unlock() + runningRaw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: "web", Fingerprint: old}) + if err := p.w.hearRunning("running.g14.web", runningRaw); err != nil { + t.Fatal(err) + } + // The pipeline that passed names the older fingerprint: it is the want's target, its entry the one read by fingerprint. + e := ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("web", old, "1.0.0", 1, mpr.StepResultOutcomePassed)) + e.Source, e.Pipeline = 4, trunkBranch+".5" + if _, err := p.ends.take(e); err != nil { + t.Fatal(err) + } + p.wants(ctx) + p.wants(ctx) + settled := writes h.branches.Held("main", seat.CatalogRevision{Branch: "main", Revision: 2}) if rows := h.branches.Entries.Rows(); len(rows) != 1 || rows[0].Fingerprint != old { t.Errorf("a catalog revision taken in keeps %+v, want the entry a want names and releases the one nothing names", rows) } + p.wants(ctx) + if writes != settled { + t.Errorf("a pass after a revision taken in wrote %d wants: the want at the older fingerprint is rewritten", writes-settled) + } +} + +// writeCountingKV counts every write of one key of the wants bucket, a create or an update as a put. +type writeCountingKV struct { + memKV + writes *int + key string +} + +func (c *writeCountingKV) count(key string) { + if key == c.key { + *c.writes++ + } +} + +func (c *writeCountingKV) Put(ctx context.Context, key string, value []byte) (uint64, error) { + c.count(key) + return c.memKV.Put(ctx, key, value) +} + +func (c *writeCountingKV) Create(ctx context.Context, key string, value []byte, o ...jetstream.KVCreateOpt) (uint64, error) { + c.count(key) + return c.memKV.Create(ctx, key, value, o...) +} + +func (c *writeCountingKV) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) { + c.count(key) + return c.memKV.Update(ctx, key, value, revision) }