B7/B8 events-whole: the publish again hears a node-engine running and two returned from the bus in the publishes test; two returns queue a version once while its send runs
Builds: design 47 H2 H-A-606 (AC-B7), H-A-620 (1) (AC-B8a)
This commit is contained in:
+94
-4
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
|
||||
@@ -23,6 +24,7 @@ import (
|
||||
"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"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
"git.novox.be/novox/mesh-sdk/go/testbus"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
@@ -557,6 +559,55 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
|
||||
republish.Ended = items.Ended
|
||||
pq.take = items.take
|
||||
wirePublishItems(rv, items, &lockedReserve{memReserve: &memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}}, versions.DefaultReleasedKept)
|
||||
// The publish again hears the node-engine seat's events from the bus, as the builder's events consumer gives them (H-A-606, ADR 0674 §2):
|
||||
// the registry holder's module runs on the node ace, and its catalog entry serves the registry seat.
|
||||
entries[fpOf+holder] = meshcatalog.CatalogEntry{Module: holder, Fp: fpOf + holder, Serves: []string{versions.SeatGoPackages + ".publish"}}
|
||||
againer := &publishingAgain{a: &versions.Againer{Republisher: republish, Acted: &lockedReserve{memReserve: &memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}},
|
||||
Nodes: func(seat string) []seatlist.HolderNode {
|
||||
if seat == versions.SeatGoPackages {
|
||||
return []seatlist.HolderNode{{Module: holder, Node: "ace"}}
|
||||
}
|
||||
return nil
|
||||
}}}
|
||||
handled := make(chan uint64, 16)
|
||||
engineEvents, err := b.js.CreateOrUpdateConsumer(ctx, eventsStream, jetstream.ConsumerConfig{Durable: "publish-again-test", AckPolicy: jetstream.AckExplicitPolicy,
|
||||
DeliverPolicy: jetstream.DeliverNewPolicy, FilterSubjects: []string{nodeengine.SubjectRunningAll, nodeengine.SubjectManifestReadsChanged("*")}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
hearing, err := engineEvents.Consume(func(m jetstream.Msg) {
|
||||
againer.heard(ctx, m, t.Logf)
|
||||
_ = m.Ack()
|
||||
if md, err := m.Metadata(); err == nil {
|
||||
handled <- md.Sequence.Stream
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer hearing.Stop()
|
||||
// said puts one event of the node-engine seat on the bus and waits until the publish again has handled it; it answers its stream sequence.
|
||||
said := func(subject string, body any) uint64 {
|
||||
t.Helper()
|
||||
data, _ := json.Marshal(body)
|
||||
ack, err := b.js.Publish(ctx, subject, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for bound := time.After(testbus.SetupBound(t)); ; {
|
||||
select {
|
||||
case seq := <-handled:
|
||||
if seq == ack.Sequence {
|
||||
return seq
|
||||
}
|
||||
case <-bound:
|
||||
t.Fatalf("the publish again did not handle %s", subject)
|
||||
}
|
||||
}
|
||||
}
|
||||
returned := func() uint64 {
|
||||
return said(nodeengine.SubjectManifestReadsChanged("ace"), nodeengine.ManifestReadsChanged{Node: "ace", Why: nodeengine.ManifestReadsChangedWhyReturned})
|
||||
}
|
||||
// build is the reserve and the end of a build of module at fp: its digests are built+artifact.
|
||||
build := func(module, fp, built string, arts ...string) versions.ReservedVersion {
|
||||
t.Helper()
|
||||
@@ -603,16 +654,55 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
|
||||
t.Errorf("the refused publish was called %d times, want once: it waits for the next running", got)
|
||||
}
|
||||
reg.refuse("x.example/refused/a", "")
|
||||
republish.Started = time.Now() // the holder's next running, in a run later than the build's: its put is of the start class, another message id
|
||||
if _, err := republish.Republish(ctx, "refused", "0.1.0"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The holder's running, heard from the bus, puts it again once, as an item of the class again (H-A-606, H-A-613 (1), H-A-620 (1)).
|
||||
liveBefore, againBefore := delivered(t, b.js, bind.Stream, holder, versions.PublishClassLive), delivered(t, b.js, bind.Stream, holder, versions.PublishClassStart)
|
||||
said(nodeengine.SubjectRunning("ace", holder), nodeengine.Running{Module: holder, Node: "ace", Fingerprint: fpOf + holder})
|
||||
reg.await(t, "x.example/refused/a", "0.1.0")
|
||||
if got := stored("refused", "0.1.0", "a"); got != "sha256:ra" {
|
||||
t.Errorf("the refused publish put again stored %q, want sha256:ra", got)
|
||||
}
|
||||
reg.published(t, rv, "x.example/refused/a", "0.1.0")
|
||||
reg.settle(t, b.js, bind.Stream, holder, func() { items.heard(ctx, "refused", "0.1.0") })
|
||||
if l, a := delivered(t, b.js, bind.Stream, holder, versions.PublishClassLive), delivered(t, b.js, bind.Stream, holder, versions.PublishClassStart); l != liveBefore || a != againBefore+1 {
|
||||
t.Errorf("the running put %d live and %d again items, want one item of the class again", l-liveBefore, a-againBefore)
|
||||
}
|
||||
|
||||
// H-A-620 (1) (AC-B8a): two returns of one holder queue a version once while its send runs: the holder is away, the first return puts
|
||||
// the version and its send waits at the kept call's pace, the second finds the version held by the work queue and puts nothing.
|
||||
entryOf("twice", fpOf+"t", "a")
|
||||
reg.refuse("x.example/twice/a", "the cap")
|
||||
build("twice", fpOf+"t", "t", "a")
|
||||
reg.await(t, "x.example/twice/a", "0.1.0")
|
||||
reg.settle(t, b.js, bind.Stream, holder, nil)
|
||||
reg.refuse("x.example/twice/a", "")
|
||||
reg.goAway()
|
||||
againBefore = delivered(t, b.js, bind.Stream, holder, versions.PublishClassStart)
|
||||
returned()
|
||||
select {
|
||||
case <-reg.firstAway:
|
||||
case <-time.After(testbus.SetupBound(t)):
|
||||
t.Fatal("the first return did not put the version")
|
||||
}
|
||||
returned()
|
||||
if st, err := b.js.Stream(ctx, bind.Stream); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if info, err := st.Info(ctx, jetstream.WithSubjectFilter(bind.Subject+".publish."+holder+".again."+versions.EscapeToken("twice")+".>")); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n := func() (n uint64) {
|
||||
for _, c := range info.State.Subjects {
|
||||
n += c
|
||||
}
|
||||
return
|
||||
}(); n != 1 {
|
||||
t.Errorf("two returns left %d items of twice on the work queue (%v), want one", n, info.State.Subjects)
|
||||
}
|
||||
reg.answer()
|
||||
reg.await(t, "x.example/twice/a", "0.1.0")
|
||||
reg.published(t, rv, "x.example/twice/a", "0.1.0")
|
||||
reg.settle(t, b.js, bind.Stream, holder, func() { items.heard(ctx, "twice", "0.1.0") })
|
||||
if got := delivered(t, b.js, bind.Stream, holder, versions.PublishClassStart); got != againBefore+1 {
|
||||
t.Errorf("two returns made %d deliveries of again items, want one", got-againBefore)
|
||||
}
|
||||
|
||||
// H-A-593 (5): a build of F publishes two of three artifacts at V and fails on the third (the holder refuses it). Built again, the
|
||||
// two held for F keep their held digests, the third is stored and V is released, with no refusal and no new number.
|
||||
|
||||
Reference in New Issue
Block a user