T4: the runtime answers mesh/queue.waiting, a holder's own queue read without consuming
mesh/queue.waiting {seat} answers {asks: [{id, module, age_seconds}], capped}: for each worker the
holder's membership lists on the seat's stream, every message after the worker's delivered
sequence, read by a direct get by subject, never consumed; at most 768 KB; refused for a seat the
module holds no queue of (ADR 0596: a holder reads its own store).
Builds: design 47 H2 §777, H-A-410
This commit is contained in:
@@ -3,6 +3,7 @@ package runtime
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -219,4 +220,43 @@ func TestABundlePullsAndSettlesThroughItsModulesBus(t *testing.T) {
|
||||
if none, err := building.Seat("pull", json.RawMessage(`{"worker":"SEAT_NODE_BUILD_GO_DELIVERY_worker"}`), nil); err != nil || string(none) != "null" {
|
||||
t.Fatalf("an empty worker answered %s, %v", none, err)
|
||||
}
|
||||
// Design 47 H2 H-A-410: the holder reads what waits on its own queue of the seat without consuming it (mesh/queue.waiting),
|
||||
// each ask with its id, the module that put it and its age; another module is refused, as is a seat it holds no queue of.
|
||||
waiting := func(want string) {
|
||||
t.Helper()
|
||||
raw, err := building.Seat("waiting", json.RawMessage(`{"seat":"node-build-go"}`), nil)
|
||||
var w bus.QueueWaiting
|
||||
if err != nil || json.Unmarshal(raw, &w) != nil || w.Capped {
|
||||
t.Fatalf("waiting = %s, %v", raw, err)
|
||||
}
|
||||
var got []string
|
||||
for _, a := range w.Asks {
|
||||
got = append(got, fmt.Sprintf("%s:%s:%v", a.Module, a.ID, a.AgeSeconds < 60))
|
||||
}
|
||||
if strings.Join(got, ",") != want {
|
||||
t.Errorf("waiting is %s, want %s", raw, want)
|
||||
}
|
||||
}
|
||||
waiting("")
|
||||
for _, id := range []string{"ask2", "ask3"} {
|
||||
m := nats.NewMsg("mesh.seat.node-build-go.accept.delivery")
|
||||
m.Header.Set("x-source", "mesh-delivery-pipeline")
|
||||
m.Header.Set("x-event-id", "mesh-delivery-pipeline."+id)
|
||||
m.Data = []byte(`{"id":"` + id + `"}`)
|
||||
if _, err := js.PublishMsg(m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
waiting("mesh-delivery-pipeline:ask2:true,mesh-delivery-pipeline:ask3:true")
|
||||
waiting("mesh-delivery-pipeline:ask2:true,mesh-delivery-pipeline:ask3:true") // read again: nothing was consumed
|
||||
if _, err := elsewhere.Seat("waiting", json.RawMessage(`{"seat":"node-build-go"}`), nil); err == nil {
|
||||
t.Error("another module read the Go build seat's queue")
|
||||
}
|
||||
if _, err := building.Seat("waiting", json.RawMessage(`{"seat":"operator-channel"}`), nil); err == nil {
|
||||
t.Error("the holder read the queue of a seat it holds no worker on")
|
||||
}
|
||||
if _, err := building.Seat("pull", json.RawMessage(`{"worker":"SEAT_NODE_BUILD_GO_DELIVERY_worker","wait_ms":1000}`), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
waiting("mesh-delivery-pipeline:ask3:true") // the pulled ask is taken, no longer waiting
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user