An accepted kind names its work queue's settings (max-age, duplicates-window, ack-wait, in-progress, max-msgs, max-ack-pending, max-deliveries); buscompose.SeatQueue derives the seat's work-queue stream and its one shared worker from them, once, for the grants part to take. Builds: design 47 H2 §777; H-A-350 DMC-1, H-A-362, H-A-340 (1)
72 lines
3.9 KiB
Go
72 lines
3.9 KiB
Go
package buscompose
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/membership"
|
|
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
|
)
|
|
|
|
// The names this package keeps for the grants part's composer (mesh-grants internal/buscompose, ADR 0593 §1) agree with
|
|
// what the runtime reads: the memberships bucket, and a log's stream and subject.
|
|
func TestTheBusNamesAgree(t *testing.T) {
|
|
if GrantsMembershipsBucket != membership.GrantsBucket {
|
|
t.Fatalf("the memberships bucket is %q here and %q in membership", GrantsMembershipsBucket, membership.GrantsBucket)
|
|
}
|
|
if MembershipKey("ace", "netcheck") != "ace.netcheck" {
|
|
t.Fatal("a membership's key is not <node>.<module>")
|
|
}
|
|
if LogStreamName("mesh-delivery-builder", "build-log") == "" || LogSubject("mesh-delivery-builder", "build-log") == "" {
|
|
t.Fatal("a log has no stream or subject")
|
|
}
|
|
// 1966/AC20: a ledger's history and snapshot subjects are one contract, which the grants part grants a ledger
|
|
// account its publish on.
|
|
if h, sn := LedgerHistorySubject("m", "records"), LedgerSnapshotSubject("m", "records"); h != "mesh.ledger.m.records.history" ||
|
|
sn != "mesh.ledger.m.records.snapshot" {
|
|
t.Fatalf("a ledger's subjects are %q and %q", h, sn)
|
|
}
|
|
// 1966/AC23: a ledger account for m on a is named ledger.a.m.
|
|
if got := (Principal{Kind: KindLedger, Node: "a", Module: "m"}).Username(); got != "ledger.a.m" {
|
|
t.Fatalf("a ledger account is named %q", got)
|
|
}
|
|
// G §469: a state's bucket is capped at its max-mib; naming none is unbounded.
|
|
if (Bucket{}).MaxBytes() != -1 || (Bucket{MaxMiB: 2}).MaxBytes() != 2<<20 {
|
|
t.Fatal("a bucket's cap is not its max-mib in bytes")
|
|
}
|
|
// Design 46 7-approval-mark §5: a stream's local event pattern as the bus spells it.
|
|
for local, wire := range map[string]string{"mail.**": "mail.>", "mail.*.message": "mail.*.message", "sent": "sent"} {
|
|
if got := WirePattern(local); got != wire {
|
|
t.Errorf("WirePattern(%q) = %q, want %q", local, got, wire)
|
|
}
|
|
}
|
|
// Design 46 7-approval-mark §13: a per-machine state reaches its machine's key and the keys below it, no other machine's.
|
|
if got := PerMachineKeys("ace"); len(got) != 2 || got[0] != "ace" || got[1] != "ace.>" {
|
|
t.Errorf("a per-machine state reaches %v on ace", got)
|
|
}
|
|
// A seat's family is the shared events stream filtered to its subjects: a definition says the stream's age.
|
|
for _, st := range MeshStreams() {
|
|
if st.Name == EventsStream && int64(st.MaxAge) != seatdef.SharedEventsMaxAgeDays*24*60*60 {
|
|
t.Errorf("the shared events stream keeps %d s, a seat's definition says %d days", st.MaxAge, seatdef.SharedEventsMaxAgeDays)
|
|
}
|
|
}
|
|
// Design 47 H2 §777, H-A-362: a seat's work queue and its one worker are derived from its accepted kind's settings;
|
|
// absent settings take the defaults, two kinds naming one setting differently are refused, no accept is no queue.
|
|
st, w, ok, err := SeatQueue("mesh-builds", []seatdef.Message{{Name: "step", MaxAge: "24h", DuplicatesWindow: "2m",
|
|
AckWait: "60s", InProgress: "20s", MaxMsgs: 10000, MaxAckPending: 64, MaxDeliveries: 3}})
|
|
if err != nil || !ok || st.Name != "SEAT_MESH_BUILDS" || st.Retention != RetentionWorkQueue || st.MaxAge != 86400 ||
|
|
st.MaxMsgs != 10000 || st.DuplicatesSeconds != 120 || st.Subjects[0] != "mesh.seat.mesh-builds.accept.>" ||
|
|
w.Name != "SEAT_MESH_BUILDS_worker" || w.Stream != st.Name || w.AckWaitSeconds != 60 || w.MaxDeliver != 3 ||
|
|
w.MaxAckPending != 64 || w.InProgressSeconds != 20 {
|
|
t.Errorf("derived %+v and %+v, %v", st, w, err)
|
|
}
|
|
if st, w, _, _ := SeatQueue("mesh-wants", []seatdef.Message{{Name: "step"}}); st.MaxAge != 7*86400 || w.AckWaitSeconds != 60 || w.MaxDeliver != 5 {
|
|
t.Errorf("the defaults: %+v, %+v", st, w)
|
|
}
|
|
if _, _, _, err := SeatQueue("s", []seatdef.Message{{Name: "a", AckWait: "60s"}, {Name: "b", AckWait: "2m"}}); err == nil {
|
|
t.Error("two ack waits for one worker were derived")
|
|
}
|
|
if _, _, ok, _ := SeatQueue("s", nil); ok {
|
|
t.Error("a seat that accepts nothing has a queue")
|
|
}
|
|
}
|