Builder: every again fetch and gap read follows a live fetch
On the turn after an again item ran, the dispatch fetched again and read the live gap
without fetching live first, so a live item the stream held but had not yet given to
the waiting live pull showed no gap and a later again item went first (review round 2
on b77b70a6, publishitem.go:791). The live consumer is now fetched without waiting on
every turn no live item is held. The test row adds that case and bounds its rounds by
the level's set-up share.
Builds: design 47 H2 §793, H-A-473 (third addendum)
This commit is contained in:
+28
-14
@@ -22,6 +22,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/meshbuilds"
|
||||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
"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/process"
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/testbus"
|
||||||
"git.novox.be/novox/mesh-sdk/go/views"
|
"git.novox.be/novox/mesh-sdk/go/views"
|
||||||
|
|
||||||
"mesh-delivery-builder/internal/versions"
|
"mesh-delivery-builder/internal/versions"
|
||||||
@@ -136,16 +137,18 @@ func TestThePublishQueueSendsLiveFirstAndNeverADroppedItem(t *testing.T) {
|
|||||||
}
|
}
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
|
||||||
// An idle dispatch (H-A-473, its third addendum): its two pulls wait; a live item put, then an again one, is sent live first,
|
// An idle dispatch (H-A-473, its third addendum): its two pulls wait; a live item put, then an again one, is sent live first;
|
||||||
// every time, 50 rounds, each a holder of its own.
|
// and an again item put after a live one, while the dispatch runs an again item put before both, is sent after the live one.
|
||||||
classCh := make(chan string, 2)
|
// Every time, 50 rounds, each a holder of its own.
|
||||||
|
sentOf := make(chan string, 8)
|
||||||
idle := &publishQueue{js: b.js, ackWait: time.Minute, logf: func(string, ...any) {}, binding: publishesOf("mesh-delivery-builder"),
|
idle := &publishQueue{js: b.js, ackWait: time.Minute, logf: func(string, ...any) {}, binding: publishesOf("mesh-delivery-builder"),
|
||||||
take: func(_ context.Context, m itemMsg) {
|
take: func(_ context.Context, m itemMsg) {
|
||||||
var q versions.QueuedPublish
|
var q versions.QueuedPublish
|
||||||
_ = json.Unmarshal(m.Data(), &q)
|
_ = json.Unmarshal(m.Data(), &q)
|
||||||
_ = m.Ack()
|
_ = m.Ack()
|
||||||
classCh <- q.Class
|
sentOf <- q.Module
|
||||||
}}
|
}}
|
||||||
|
roundBound := testbus.SetupBound(t) // the level's set-up share (MESH_TEST_LEVEL_BOUND), as the other whole tests
|
||||||
for r := range 50 {
|
for r := range 50 {
|
||||||
holder := fmt.Sprintf("idle%d", r)
|
holder := fmt.Sprintf("idle%d", r)
|
||||||
idle.learn(ctx, holder)
|
idle.learn(ctx, holder)
|
||||||
@@ -164,25 +167,36 @@ func TestThePublishQueueSendsLiveFirstAndNeverADroppedItem(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, class := range []string{versions.PublishClassLive, versions.PublishClassStart} {
|
put := func(module, class string) {
|
||||||
q := versions.QueuedPublish{V: 1, Holder: holder, Module: "m", Version: "0.1.0", Class: class, Queued: time.Now()}
|
q := versions.QueuedPublish{V: 1, Holder: holder, Module: module, Version: "0.1.0", Class: class, Queued: time.Now()}
|
||||||
data, _ := json.Marshal(q)
|
data, _ := json.Marshal(q)
|
||||||
if _, err := b.js.Publish(ctx, idle.subject(bind, q), data); err != nil {
|
if _, err := b.js.Publish(ctx, idle.subject(bind, q), data); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var order []string
|
sent := func(n int) []string {
|
||||||
for range 2 {
|
var order []string
|
||||||
select {
|
for range n {
|
||||||
case c := <-classCh:
|
select {
|
||||||
order = append(order, c)
|
case m := <-sentOf:
|
||||||
case <-time.After(30 * time.Second):
|
order = append(order, m)
|
||||||
t.Fatalf("round %d: sent %v of a live and an again item", r, order)
|
case <-time.After(roundBound):
|
||||||
|
t.Fatalf("round %d: sent %v of %d items", r, order, n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return order
|
||||||
}
|
}
|
||||||
if order[0] != versions.PublishClassLive {
|
put("live", versions.PublishClassLive)
|
||||||
|
put("again", versions.PublishClassStart)
|
||||||
|
if order := sent(2); order[0] != "live" {
|
||||||
t.Errorf("round %d: an idle dispatch sent %v, want the live item put first sent first", r, order)
|
t.Errorf("round %d: an idle dispatch sent %v, want the live item put first sent first", r, order)
|
||||||
}
|
}
|
||||||
|
put("before", versions.PublishClassStart)
|
||||||
|
put("live2", versions.PublishClassLive)
|
||||||
|
put("after", versions.PublishClassStart)
|
||||||
|
if order := sent(3); slices.Index(order, "after") < slices.Index(order, "live2") {
|
||||||
|
t.Errorf("round %d: the dispatch sent %v, want the again item put after the live one sent after it", r, order)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The move of the old state, run twice, puts each item once (at another holder, so the pull of oci is not asked).
|
// The move of the old state, run twice, puts each item once (at another holder, so the pull of oci is not asked).
|
||||||
|
|||||||
@@ -659,8 +659,8 @@ func (pq *publishQueue) pull(ctx context.Context, holder string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dispatch runs the items of one holder, at most four at once, every live item before an again one (design 47 H2 §793,
|
// dispatch runs the items of one holder, at most four at once, every live item before an again one (design 47 H2 §793,
|
||||||
// H-A-473 and its third addendum): it pulls the live consumer itself, a fetch of up to its free slots that does not wait, and
|
// H-A-473 and its third addendum): on every turn no live item is held it pulls the live consumer itself, a fetch of up to its
|
||||||
// pulls the again consumer only when that fetch returns nothing. When neither holds an item, a pull of one item waits on each,
|
// free slots that does not wait, and pulls the again consumer, or reads the live gap, only after that fetch returned nothing. When neither holds an item, a pull of one item waits on each,
|
||||||
// the bus's only wake for an item put or delivered again. An again item taken while the live pull waits is run only once the
|
// the bus's only wake for an item put or delivered again. An again item taken while the live pull waits is run only once the
|
||||||
// live consumer's delivered sequence is no further than the live items the dispatch received: a gap is a live item in flight
|
// live consumer's delivered sequence is no further than the live items the dispatch received: a gap is a live item in flight
|
||||||
// to the waiting pull, and the again items are held until it arrives and runs. A pull the bus refuses ends the dispatch, said;
|
// to the waiting pull, and the again items are held until it arrives and runs. A pull the bus refuses ends the dispatch, said;
|
||||||
@@ -788,7 +788,7 @@ func (pq *publishQueue) dispatch(ctx context.Context, holder string, live, again
|
|||||||
held := false // again items held for a live item in flight
|
held := false // again items held for a live item in flight
|
||||||
if heldLive != nil {
|
if heldLive != nil {
|
||||||
got, heldLive = []jetstream.Msg{heldLive}, nil
|
got, heldLive = []jetstream.Msg{heldLive}, nil
|
||||||
} else if !liveWaiting || len(heldAgain) > 0 {
|
} else {
|
||||||
ms, err := now(live, n)
|
ms, err := now(live, n)
|
||||||
if refused(err) {
|
if refused(err) {
|
||||||
failed(err)
|
failed(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user