The work queue publishes is declared in the manifest's old streams section (retention work-queue, duplicates 24 h, max-deliveries 10, 64 MiB, 7 days), the module's own stream consumed on the module's account, so the bus binding asked of the broker seat goes; the consumers per holder and class are still made at run time. The seat mesh-builds gains the read verb publish-queue, served by the builder from its own stream (counts per holder and class, oldest and newest, a list capped at 50, capped past 4,000 items read), and builder_publish_queue asks it in place of the runtime's stream and work-queue reads. Two whole tests of a gone artifact are folded into one, so the builder's integration count stays at 18 with the publishes whole test. Builds: design 47 H2 §793, §819, §820; H-A-440 (1), H-A-446 (2), H-A-454 and its addendum
458 lines
23 KiB
Go
458 lines
23 KiB
Go
package versions
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"maps"
|
|
"slices"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
)
|
|
|
|
// republishBed is a Republisher over memory states: reservations of module m (a bundle by the oci seat and a Go package by
|
|
// the Go seat), one holder module `oci` that claims the oci seat, a work queue that records its puts (deduplicating by message
|
|
// id when window is set, refusing when full) and sends each put at once as its pull would, and a Send and a Unreleased that
|
|
// record.
|
|
type republishBed struct {
|
|
*Republisher
|
|
reserved *reserveMem
|
|
now time.Time
|
|
mu sync.Mutex // sent and said, which sends at once write
|
|
sent []Publish
|
|
said []string
|
|
ended []string
|
|
refuse string // the words Send fails with, empty for none
|
|
// holders are the registry seats' holders the seat-holders view names (design 47 G A-416).
|
|
holders map[string][]string
|
|
// puts are the items the work queue took; window deduplicates by message id; full refuses every put; held keeps the puts
|
|
// unsent.
|
|
puts []QueuedPublish
|
|
ids map[string]bool
|
|
window, full bool
|
|
held bool
|
|
}
|
|
|
|
func newRepublishBed(t *testing.T) *republishBed {
|
|
t.Helper()
|
|
b := &republishBed{reserved: &reserveMem{mem: newMem()}, now: time.Date(2026, 11, 11, 12, 0, 0, 0, time.UTC), ids: map[string]bool{}}
|
|
res := &Reserver{Store: b.reserved, Now: func() time.Time { return b.now }, ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
|
|
b.Republisher = &Republisher{Reserved: res, Now: func() time.Time { return b.now },
|
|
Entry: func(_ context.Context, fp string) (meshcatalog.CatalogEntry, error) {
|
|
if fp == "src2:holder" {
|
|
return meshcatalog.CatalogEntry{Serves: []string{SeatArtifacts + ".publish", SeatArtifacts + ".versions"}}, nil
|
|
}
|
|
m := strings.TrimPrefix(fp, "src2:")
|
|
return meshcatalog.CatalogEntry{Artifacts: []meshcatalog.Artifact{
|
|
{Ref: m + ":prog", Kind: "bundle", Language: "go"},
|
|
{Ref: m + ":lib", Kind: "package", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/" + m + "/go"}}}}, nil
|
|
},
|
|
Send: func(_ context.Context, p Publish) error {
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
b.sent = append(b.sent, p)
|
|
if b.refuse != "" {
|
|
return errors.New(b.refuse)
|
|
}
|
|
return nil
|
|
},
|
|
Unreleased: func(_ context.Context, v ReservedVersion, why string) {
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
b.said = append(b.said, v.Module+" "+v.Version+": "+why)
|
|
},
|
|
Ended: func(_ context.Context, module, version string) {
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
b.ended = append(b.ended, module+" "+version)
|
|
},
|
|
Logf: t.Logf}
|
|
b.Put = func(ctx context.Context, q QueuedPublish) (bool, error) {
|
|
if b.full {
|
|
return false, fmt.Errorf("%w: maximum bytes exceeded", ErrQueueFull)
|
|
}
|
|
id := PublishMsgID(q.Holder, q.Class, q.Module, q.Version)
|
|
if b.window && b.ids[id] {
|
|
return true, nil
|
|
}
|
|
b.ids[id] = true
|
|
b.puts = append(b.puts, q)
|
|
if !b.held {
|
|
b.SendQueued(ctx, q)
|
|
}
|
|
return false, nil
|
|
}
|
|
b.Holders = func(seat string) []string { return b.holders[seat] }
|
|
return b
|
|
}
|
|
|
|
// reserve reserves and builds a version of module m (its patch given by the reservation order), its build ended long ago.
|
|
func (b *republishBed) reserve(t *testing.T, module string) ReservedVersion {
|
|
t.Helper()
|
|
b.now = b.now.Add(time.Minute)
|
|
ctx := context.Background()
|
|
v, err := b.Reserved.Reserve(ctx, module, "0.1", []string{module + ":prog", module + ":lib"}, Source{Fingerprint: "src2:" + module})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for ref, d := range map[string]string{module + ":prog": "sha256:aa", module + ":lib": "sha256:bb"} {
|
|
if _, err := b.Reserved.Built(ctx, module, v.Version, ref, d, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
b.now = b.now.Add(UnreleasedBound + time.Minute)
|
|
return v
|
|
}
|
|
|
|
// TestRepublish: design 47 G §588 (A-73, A-76): a reserved version left unpublished is published again, on a registry
|
|
// holder's running and on its node's returned, once per message by its stream sequence, as a publish by digest with no parts,
|
|
// at most the setting's number per event, newest first; an artifact no store holds is said once and not tried again.
|
|
func TestRepublish(t *testing.T) {
|
|
ctx := context.Background()
|
|
t.Run("a done build is published as a digest with no parts, to its seat's holder", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
v := b.reserve(t, "m")
|
|
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
|
if v.Fingerprint != "src2:m" {
|
|
t.Fatalf("the reservation keeps the entry's fingerprint: %q", v.Fingerprint)
|
|
}
|
|
if q, err := b.Republish(ctx, "", ""); err != nil || len(b.sent) != 1 || fmt.Sprint(q) != "[m "+v.Version+"]" {
|
|
t.Fatalf("queued %v sent %d (%v), want 1", q, len(b.sent), err)
|
|
}
|
|
p := b.sent[0]
|
|
if p.Seat != SeatArtifacts || p.Name != "m/prog" || p.Kind != "bundle" || p.Version != v.Version || p.Digest != "sha256:aa" || p.Fingerprint != "src2:m" ||
|
|
p.Transfer != "republish-m-"+strings.ReplaceAll(v.Version, ".", "-")+"-prog" || strings.ContainsAny(p.Transfer, "/. *>") {
|
|
t.Errorf("sent %+v, want the bundle by digest to the oci seat, the Go package left to its own seat's holder", p)
|
|
}
|
|
if len(b.puts) != 1 || b.puts[0].Holder != "oci" || b.puts[0].Class != PublishClassLive {
|
|
t.Errorf("the work queue took %+v, want one live item at oci", b.puts)
|
|
}
|
|
})
|
|
t.Run("an entry that cannot be read stops neither the other versions nor the drain", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
b.reserve(t, "m1")
|
|
b.reserve(t, "m2") // newest: queued before m1's entry is met
|
|
entry := b.Entry
|
|
b.Entry = func(ctx context.Context, fp string) (meshcatalog.CatalogEntry, error) {
|
|
if fp == "src2:m1" {
|
|
return meshcatalog.CatalogEntry{}, errors.New("no entry of fingerprint src2:m1 is kept")
|
|
}
|
|
return entry(ctx, fp)
|
|
}
|
|
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
|
if _, err := b.Republish(ctx, "", ""); err == nil || !strings.Contains(err.Error(), "src2:m1") {
|
|
t.Errorf("the unreadable entry is not said: %v", err)
|
|
}
|
|
if len(b.sent) != 1 || !strings.HasPrefix(b.sent[0].Name, "m2/") {
|
|
t.Errorf("sent %+v, want m2 drained though m1's entry cannot be read", b.sent)
|
|
}
|
|
})
|
|
t.Run("an artifact no store holds is said once and not tried again", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
b.reserve(t, "m")
|
|
b.refuse = "oci-artifact-registry's publish of m/prog: not stored: no blob sha256:aa"
|
|
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
|
_, _ = b.Republish(ctx, "", "")
|
|
_, _ = b.Republish(ctx, "", "")
|
|
if len(b.sent) != 1 || len(b.said) != 1 || !strings.Contains(b.said[0], "not stored: ") {
|
|
t.Errorf("sent %d, said %v: want one try and one saying of not stored", len(b.sent), b.said)
|
|
}
|
|
})
|
|
t.Run("a refusal in other words is said each time", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
b.reserve(t, "m")
|
|
b.refuse = "the holder is full"
|
|
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
|
_, _ = b.Republish(ctx, "", "")
|
|
_, _ = b.Republish(ctx, "", "")
|
|
if len(b.sent) != 2 || len(b.said) != 2 {
|
|
t.Errorf("sent %d, said %v: want both events tried and said", len(b.sent), b.said)
|
|
}
|
|
})
|
|
t.Run("a queue past its cap says queue full", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
b.reserve(t, "m")
|
|
b.full = true
|
|
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
|
_, _ = b.Republish(ctx, "", "")
|
|
if len(b.sent) != 0 || len(b.said) != 1 || !strings.HasSuffix(b.said[0], QueueFull) {
|
|
t.Errorf("sent %d, said %v, want nothing sent and queue full said", len(b.sent), b.said)
|
|
}
|
|
})
|
|
t.Run("an item put twice within the duplicates window is put once, and stands queued", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
v := b.reserve(t, "m")
|
|
b.window, b.held = true, true
|
|
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
|
q1, _ := b.Republish(ctx, "m", v.Version)
|
|
q2, _ := b.Republish(ctx, "m", v.Version)
|
|
if len(b.puts) != 1 || len(q1) != 1 || len(q2) != 1 {
|
|
t.Errorf("puts %d, queued %v then %v: want one item, queued both times", len(b.puts), q1, q2)
|
|
}
|
|
})
|
|
t.Run("the move puts each item of the old state once, its class as of this run, a superseded one not", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
v := b.reserve(t, "m")
|
|
w := b.reserve(t, "n")
|
|
b.Started = b.now
|
|
b.window, b.held = true, true
|
|
raw, _ := json.Marshal(QueuedPublish{V: 1, Holder: "oci", Module: "m", Version: v.Version, Artifacts: map[string]string{"m:prog": "sha256:aa"}, Queued: b.now, Class: "build-ended-this-run"})
|
|
gone, _ := json.Marshal(QueuedPublish{V: 1, Holder: "oci", Module: "n", Version: w.Version, Artifacts: map[string]string{"n:prog": "sha256:aa"}, Queued: b.now})
|
|
if _, _, err := b.Reserved.Withdraw(ctx, "n", w.Version); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for range 2 {
|
|
if _, err := b.MoveQueued(ctx, []json.RawMessage{raw, gone}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if len(b.puts) != 1 || b.puts[0].Class != PublishClassStart || fmt.Sprint(b.ended) != "[n "+w.Version+" n "+w.Version+"]" {
|
|
t.Errorf("puts %+v, ended %v: want m once as again (its build ended before this run), n's item ended", b.puts, b.ended)
|
|
}
|
|
})
|
|
t.Run("after a fresh start the tool queues at the seat's holder, no running heard", func(t *testing.T) {
|
|
// Design 47 G A-416, A-416a: the holder is the one the seat-holders view names from the start, not one learnt from a
|
|
// running heard since; a seat with no holder queues nothing.
|
|
b := newRepublishBed(t)
|
|
b.reserve(t, "m1")
|
|
b.reserve(t, "m2")
|
|
if q, err := b.Republish(ctx, "", ""); err != nil || len(q) != 0 {
|
|
t.Errorf("no holder named: queued %v (%v), want none", q, err)
|
|
}
|
|
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
|
q, err := b.Republish(ctx, "", "")
|
|
if err != nil || fmt.Sprint(q) != "[m2 0.1.0 m1 0.1.0]" || len(b.sent) != 2 || b.sent[0].Seat != SeatArtifacts {
|
|
t.Errorf("the tool with neither queued %v (%v), sent %+v: want both versions at oci, with no limit", q, err, b.sent)
|
|
}
|
|
if _, err := b.Republish(ctx, "m1", "0.1.9"); err == nil {
|
|
t.Error("a version no reservation holds is not refused")
|
|
}
|
|
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
|
_, _ = b.Republish(ctx, "", "")
|
|
items := Reader{Keys: func() ([]string, error) { return []string{"publish.m.0.1.0", "reserve-done.m.x"}, nil },
|
|
Get: func(k string) (json.RawMessage, bool, error) {
|
|
return json.RawMessage(`{"mode":"publish","module":"m","version":"0.1.0","tries":3,"next-try":"2026-11-17T01:00:00Z","why":"w"}`), true, nil
|
|
}}
|
|
none := Reader{Keys: func() ([]string, error) { return nil, nil }}
|
|
answer, err := answerOf(none, none, items, "", "")
|
|
if err != nil || len(answer.Items) != 1 || answer.Items[0].Tries != 3 || answer.Items[0].Version != "0.1.0" {
|
|
t.Errorf("builder_publish_queue items = %+v (%v), want the one publish item with its tries", answer.Items, err)
|
|
}
|
|
})
|
|
}
|
|
|
|
// TestTheRegistriesRecordSaysWhetherAVersionIsHeld: design 47 H H-A-272, H-A-274, H-A-275 — a missing artifact its registry seat
|
|
// holds at the version (the Go form too) with the built digest is held; at the version with another digest it is held elsewhere;
|
|
// a version the seat lacks is said by name. The numbers a registry holds of the module's artifacts are what reserving skips.
|
|
func TestTheRegistriesRecordSaysWhetherAVersionIsHeld(t *testing.T) {
|
|
ctx := context.Background()
|
|
entry := meshcatalog.CatalogEntry{Artifacts: []meshcatalog.Artifact{{Ref: "m:lib", Kind: "package", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.example/m"}}}}
|
|
r := &Republisher{Entry: func(context.Context, string) (meshcatalog.CatalogEntry, error) { return entry, nil }}
|
|
v := ReservedVersion{Module: "m", Version: "0.1.37", Fingerprint: "fp", Artifacts: map[string]string{"m:lib": "sha256:a"}}
|
|
for _, c := range []struct {
|
|
name string
|
|
holds []HeldVersion
|
|
all, elsewhere, lacks bool
|
|
}{
|
|
{name: "held in the Go form with the built digest", holds: []HeldVersion{{Version: "v0.1.36", Digest: "sha256:z"}, {Version: "v0.1.37", Digest: "sha256:a"}}, all: true},
|
|
{name: "another digest at the version", holds: []HeldVersion{{Version: "0.1.37", Digest: "sha256:b"}}, elsewhere: true},
|
|
{name: "the version lacked", holds: []HeldVersion{{Version: "0.1.36", Digest: "sha256:a"}}, lacks: true},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
var seat, name string
|
|
versionsOf := func(_ context.Context, s, n string) ([]HeldVersion, error) { seat, name = s, n; return c.holds, nil }
|
|
j, err := r.Held(ctx, v, versionsOf)
|
|
if err != nil || j.All != c.all || (len(j.Elsewhere) == 1) != c.elsewhere || (j.Lacks != "") != c.lacks || seat != SeatGoPackages || name != "git.example/m" {
|
|
t.Fatalf("judged %+v (%v) asking %s for %s, want all %v, elsewhere %v, lacks %v asking %s for git.example/m", j, err, seat, name, c.all, c.elsewhere, c.lacks, SeatGoPackages)
|
|
}
|
|
if c.lacks && !strings.Contains(j.Lacks, "0.1.37") {
|
|
t.Errorf("what the registry lacks is said as %q", j.Lacks)
|
|
}
|
|
nums, err := r.HeldNumbers(ctx, "m", "fp", []string{"m:lib"}, versionsOf)
|
|
if err != nil || len(nums) != len(c.holds) {
|
|
t.Errorf("the held numbers are %v (%v), want one per version the seat holds", nums, err)
|
|
}
|
|
})
|
|
}
|
|
v.Published = map[string]bool{"m:lib": true}
|
|
if j, err := r.Held(ctx, v, nil); err != nil || !j.All {
|
|
t.Errorf("a version with no missing artifact is judged %+v (%v), want all held without a read", j, err)
|
|
}
|
|
}
|
|
|
|
// queueAt writes a queued version of module m at holder oci directly, as a start finds it.
|
|
func (b *republishBed) queueAt(v ReservedVersion, class string, at time.Time) QueuedPublish {
|
|
return QueuedPublish{V: 1, Holder: "oci", Module: v.Module, Version: v.Version, Artifacts: map[string]string{v.Module + ":prog": "sha256:aa"}, Queued: at, Class: class}
|
|
}
|
|
|
|
// TestAQueuedItemIsSentWhileItsBuildStands: design 47 H H-A-290 (2), H-A-291 (1), H2 §793 — an item is put at the holder in the
|
|
// class of its build (live when it ended in this run); a build whose reservation was withdrawn, taken over or superseded by a newer
|
|
// patch or release of its series never publishes, its publish item ended, at the put and at the send; an item whose artifacts are
|
|
// all published or refused as not stored ends unsent.
|
|
func TestAQueuedItemIsSentWhileItsBuildStands(t *testing.T) {
|
|
ctx := context.Background()
|
|
t.Run("a build that ended before this run is put as again, one after it as live", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
old := b.reserve(t, "o")
|
|
b.Started = b.now
|
|
live := b.reserve(t, "l")
|
|
b.held = true
|
|
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
|
_, _ = b.Republish(ctx, "o", old.Version)
|
|
_, _ = b.Republish(ctx, "l", live.Version)
|
|
if len(b.puts) != 2 || b.puts[0].Class != PublishClassStart || b.puts[1].Class != PublishClassLive ||
|
|
PublishEvent("oci", PublishClassLive, "l", live.Version) != "publish.oci.live.l.0=2E1=2E0" {
|
|
t.Errorf("puts %+v, want o again and l live, on publish.<holder>.<class>.<module>.<version>", b.puts)
|
|
}
|
|
})
|
|
for _, at := range []string{"put", "send"} {
|
|
t.Run("a withdrawn build never publishes, at the "+at, func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
v := b.reserve(t, "m")
|
|
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
|
if _, ok, err := b.Reserved.Withdraw(ctx, "m", v.Version); err != nil || !ok {
|
|
t.Fatalf("withdrawn %v (%v)", ok, err)
|
|
}
|
|
if at == "put" {
|
|
if q, _ := b.Republish(ctx, "m", v.Version); len(q) != 0 {
|
|
t.Errorf("queued %v", q)
|
|
}
|
|
} else if f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now)); f.Ended == "" {
|
|
t.Errorf("the send of a withdrawn build answered %+v, want it ended", f)
|
|
}
|
|
if len(b.sent) != 0 || len(b.puts) != 0 || fmt.Sprint(b.ended) != "[m "+v.Version+"]" {
|
|
t.Errorf("sent %v, puts %v, items ended %v: want nothing sent or put and m %s's item ended", b.sent, b.puts, b.ended, v.Version)
|
|
}
|
|
})
|
|
}
|
|
t.Run("a build a newer patch or release of its series supersedes is ended at the send, never by a newer series", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
v := b.reserve(t, "m")
|
|
if _, err := b.Reserved.Reserve(ctx, "m", "0.2", []string{"m:prog"}, Source{Fingerprint: "src2:m"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if f := b.SendQueued(ctx, b.queueAt(v, PublishClassStart, b.now)); !f.Sent || len(b.sent) != 1 || len(b.ended) != 0 {
|
|
t.Errorf("with a standing 0.2: %+v, sent %v, ended %v, want m %s sent, its series not superseded (H-A-293)", f, b.sent, b.ended, v.Version)
|
|
}
|
|
rel := &reserveMem{mem: newMem()}
|
|
raw, _ := json.Marshal(ReleasedRecord{Kept: []ReleasedBuild{{Fingerprint: "f", Version: "0.2.3"}, {Fingerprint: "g", Version: "0.1.9"}}})
|
|
_, _ = rel.Create(ctx, ReleasedKey("m"), raw)
|
|
b.Reserved.Releases = rel
|
|
b.sent = nil
|
|
if f := b.SendQueued(ctx, b.queueAt(v, PublishClassStart, b.now)); f.Ended == "" || len(b.sent) != 0 || fmt.Sprint(b.ended) != "[m "+v.Version+"]" {
|
|
t.Errorf("at the send: %+v, sent %v, ended %v, want m %s retired by the release 0.1.9", f, b.sent, b.ended, v.Version)
|
|
}
|
|
only := &reserveMem{mem: newMem()}
|
|
raw, _ = json.Marshal(ReleasedRecord{Kept: []ReleasedBuild{{Fingerprint: "f", Version: "0.2.0"}}})
|
|
_, _ = only.Create(ctx, ReleasedKey("n"), raw)
|
|
got, err := (&Reserver{Releases: only}).Retired(ctx, []ReservedVersion{{Module: "n", Version: "0.1.4", BuiltAt: b.now}, {Module: "n", Version: "0.1.6"},
|
|
{Module: "n", Version: "0.3.0", BuiltAt: b.now}, {Module: "p", Version: "0.1.2", BuiltAt: b.now}})
|
|
if err != nil || len(got) != 1 || !strings.Contains(got["n 0.1.4"], "reservation 0.1.6") {
|
|
t.Errorf("retired %v (%v), want only n 0.1.4, by the newer patch 0.1.6; n 0.3.0 and p 0.1.2 kept, a release of 0.2 retiring neither", got, err)
|
|
}
|
|
})
|
|
t.Run("a version taken over is not sent, and its item ended", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
v := b.reserve(t, "m")
|
|
if _, err := b.Reserved.Reserve(ctx, "m", "0.1", []string{"m:prog"}, Source{Fingerprint: "src2:other"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if f := b.SendQueued(ctx, b.queueAt(v, PublishClassStart, b.now)); f.Ended == "" || len(b.sent) != 0 || fmt.Sprint(b.ended) != "[m "+v.Version+"]" {
|
|
t.Errorf("%+v, sent %v, ended %v: want nothing sent and the item ended", f, b.sent, b.ended)
|
|
}
|
|
})
|
|
t.Run("an item whose artifacts are published or refused as not stored ends unsent", func(t *testing.T) {
|
|
b := newRepublishBed(t)
|
|
v := b.reserve(t, "m")
|
|
b.refuse = "not stored: no blob"
|
|
if f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now)); f.Ended == "" || len(b.sent) != 1 {
|
|
t.Errorf("a not stored refusal answered %+v, sent %d: want it ended after one send", f, len(b.sent))
|
|
}
|
|
if f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now)); f.Ended == "" || len(b.sent) != 1 {
|
|
t.Errorf("again: %+v, sent %d: want it ended unsent", f, len(b.sent))
|
|
}
|
|
b.refuse = "the holder is full"
|
|
w := b.reserve(t, "n")
|
|
if f := b.SendQueued(ctx, b.queueAt(w, PublishClassLive, b.now)); f.Failed == "" || f.Sent {
|
|
t.Errorf("a refusal in other words answered %+v, want it failed, handed back", f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// answerOf is builder_publish_queue whole: the builder's verb publish-queue over its work queue (queue), then the tool over the
|
|
// verb's answer and the two states (design 47 H2 §793, H-A-454).
|
|
func answerOf(queue, acted, reasks Reader, module, version string) (Queued, error) {
|
|
q, err := PublishQueueOf(queue, module, version)
|
|
if err != nil {
|
|
return Queued{}, err
|
|
}
|
|
raw, err := json.Marshal(q) // the verb's answer travels the bus
|
|
if err != nil {
|
|
return Queued{}, err
|
|
}
|
|
var heard meshbuilds.PublishQueueAnswer
|
|
if err := json.Unmarshal(raw, &heard); err != nil {
|
|
return Queued{}, err
|
|
}
|
|
return AnswerQueue(heard, acted, reasks)
|
|
}
|
|
|
|
// TestThePublishQueueToolAnswersAtAnySize: design 47 H H-A-290 (5) — builder_publish_queue over two thousand queued versions answers
|
|
// within a second and small: counts per holder and class with the oldest and newest queue time, a list capped at fifty in the
|
|
// order they are sent, and one module's item with its class; each state read in bulk where the reader can.
|
|
func TestThePublishQueueToolAnswersAtAnySize(t *testing.T) {
|
|
at := time.Date(2026, 11, 20, 17, 0, 0, 0, time.UTC)
|
|
vals := map[string]json.RawMessage{}
|
|
for i := range 2000 {
|
|
holder, class := "oci", PublishClassStart
|
|
if i%2 == 1 {
|
|
holder = "go"
|
|
}
|
|
if i >= 1990 {
|
|
class = PublishClassLive
|
|
}
|
|
q := QueuedPublish{V: 1, Holder: holder, Module: fmt.Sprintf("m%d", i), Version: "0.1.0", Artifacts: map[string]string{"a": "sha256:aa"}, Queued: at.Add(time.Duration(i) * time.Second), Class: class}
|
|
vals[QueueKey(holder, q.Module, q.Version)], _ = json.Marshal(q)
|
|
}
|
|
gets := 0
|
|
queue := Reader{All: func() (StatePage, error) { return StatePage{Values: vals}, nil },
|
|
Keys: func() ([]string, error) { return slices.Collect(maps.Keys(vals)), nil },
|
|
Get: func(k string) (json.RawMessage, bool, error) { gets++; v, ok := vals[k]; return v, ok, nil }}
|
|
none := Reader{Keys: func() ([]string, error) { return nil, nil }}
|
|
start := time.Now()
|
|
a, err := answerOf(queue, none, none, "", "")
|
|
took := time.Since(start)
|
|
raw, _ := json.Marshal(a)
|
|
if err != nil || took > time.Second || a.Total != 2000 || len(a.Queue) != PublishQueueListCap || a.Listed != PublishQueueListCap || len(raw) > 64<<10 || gets != 0 {
|
|
t.Fatalf("answered %d of %d in %s, %d bytes, %d single reads (%v): want all counted, fifty listed, within a second, small, in bulk", len(a.Queue), a.Total, took, len(raw), gets, err)
|
|
}
|
|
if fmt.Sprintln(a.Counts[1].Holder, a.Counts[1].Class, a.Counts[1].Count, a.Counts[1].Oldest.Equal(at.Add(1991*time.Second)), a.Counts[1].Newest.Equal(at.Add(1999*time.Second))) != "go "+PublishClassLive+" 5 true true\n" || len(a.Counts) != 4 {
|
|
t.Errorf("counts %+v, want per holder and class with their oldest and newest", a.Counts)
|
|
}
|
|
if a.Queue[0].Class != PublishClassLive || a.Queue[0].Holder != "go" {
|
|
t.Errorf("the list opens with %+v, want the go holder's live class, sent first", a.Queue[0])
|
|
}
|
|
one, err := answerOf(queue, none, none, "m1995", "")
|
|
if err != nil || len(one.Queue) != 1 || one.Queue[0].Class != PublishClassLive || one.Total != 2000 {
|
|
t.Errorf("one module's answer %+v (%v), want its item with its class", one.Queue, err)
|
|
}
|
|
if a.Capped || len(a.Read) != 0 {
|
|
t.Errorf("a state one page holds is answered capped: %+v", a.Read)
|
|
}
|
|
queue.All = func() (StatePage, error) { return StatePage{Values: vals, More: true, Keys: 5000, Bytes: 3 << 20}, nil }
|
|
if c, err := answerOf(queue, none, none, "", ""); err != nil || !c.Capped || len(c.Read) != 1 || c.Read[0].State != PublishesLocal ||
|
|
c.Read[0].KeysRead != 2000 || c.Read[0].StateKeys != 5000 || c.Read[0].StateBytes != 3<<20 || c.Total != 2000 {
|
|
t.Errorf("a state past its one page answered capped %v, read %+v (%v): want capped, 2000 keys read of 5000, its size said (H-A-293)", c.Capped, c.Read, err)
|
|
}
|
|
queue.All = func() (StatePage, error) { return StatePage{}, errors.ErrUnsupported }
|
|
if b, err := answerOf(queue, none, none, "", ""); err != nil || b.Total != 2000 || gets != 2000 {
|
|
t.Errorf("a reader with no bulk read answered %d (%v) with %d single reads, want every key read one by one", b.Total, err, gets)
|
|
}
|
|
}
|