Design 47 H2's corrections: movers carried beside a failed one, validate, acted lifetimes, publish asked again (issue 1984) #365

Merged
mesh-tools merged 156 commits from feat/47-H2-corrections into main 2026-11-25 20:11:50 +00:00
Showing only changes of commit dd0cdf2f8e - Show all commits
@@ -713,7 +713,14 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
t.Fatal(err)
}
reg.await(t, "x.example/other/a", res.Version)
// The item is ended at once, never held for its publish nor left on either durable (H-A-593 (5), H-A-729): the build is of a run
// before the last start here, so its item is of the class again, which the settle reads as the live class.
reg.settle(t, b.js, bind.Stream, holder, nil)
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+".*.other.>")); err != nil || len(info.State.Subjects) != 0 {
t.Errorf("after other bytes the work queue holds %v (%v) of the item, want it terminated", info.State.Subjects, err)
}
if got := reg.callsOf("x.example/other/a"); got != 1 {
t.Errorf("other bytes of another build: called %d times, want once", got)
}
@@ -895,31 +902,57 @@ func (r *fakeRegistry) await(t *testing.T, name, version string) {
}
}
// settle waits until the holder's queue holds nothing sent and unacknowledged: every item taken is ended.
// settle waits until the holder's queue holds nothing sent and unacknowledged on either durable, the live class's and the again
// class's: every item taken is ended.
func (r *fakeRegistry) settle(t *testing.T, js jetstream.JetStream, stream string, holder string, each func()) {
t.Helper()
c, err := js.Consumer(context.Background(), stream, publishesConsumer(holder, versions.PublishClassLive))
if err != nil {
t.Fatal(err)
var cs []jetstream.Consumer
for _, class := range []string{versions.PublishClassLive, versions.PublishClassStart} {
c, err := js.Consumer(context.Background(), stream, publishesConsumer(holder, class))
if err != nil {
t.Fatal(err)
}
cs = append(cs, c)
}
for deadline := time.Now().Add(testbus.SetupBound(t)); ; {
if each != nil {
each()
}
info, err := c.Info(context.Background())
if err != nil {
t.Fatal(err)
var ack, pending int
for _, c := range cs {
info, err := c.Info(context.Background())
if err != nil {
t.Fatal(err)
}
ack, pending = ack+info.NumAckPending, pending+int(info.NumPending)
}
if info.NumAckPending == 0 && info.NumPending == 0 {
if ack == 0 && pending == 0 {
return
}
if time.Now().After(deadline) {
t.Fatalf("the queue of %s holds %d unacknowledged and %d pending", holder, info.NumAckPending, info.NumPending)
t.Fatalf("the queue of %s holds %d unacknowledged and %d pending", holder, ack, pending)
}
time.Sleep(10 * time.Millisecond)
}
}
// delivered is how many items the holder's durable of a class has given since it was made.
func delivered(t *testing.T, js jetstream.JetStream, stream, holder, class string) uint64 {
t.Helper()
c, err := js.Consumer(context.Background(), stream, publishesConsumer(holder, class))
if err != nil {
t.Fatal(err)
}
info, err := c.Info(context.Background())
if err != nil {
t.Fatal(err)
}
return info.Delivered.Consumer
}
// goAway makes the holder answer as the bus does when no one listens: its publish is met by no responders.
func (r *fakeRegistry) goAway() { r.mu.Lock(); r.away = true; r.mu.Unlock() }
// published says the holder's published of name at version, as it says it after a publish: the reservation marks it from the digest held.
func (r *fakeRegistry) published(t *testing.T, rv *reservations, name, version string) {
t.Helper()