The bus's objects are raised on every start, and one switch says which bus
Two of 1.7's three remaining pieces. **Raised on every start, not created once at genesis.** A stream somebody deleted, a mesh raised from a restored backup, or a bus whose data directory was replaced all have records and no objects — and a node whose consumer is missing hears nothing while everything else about it looks correct. The order is not a preference: a consumer on a stream that does not exist is refused *naming the stream*, so somebody reading that refusal goes looking for a deletion instead of a reversed pair of lines. Pinned by a test, along with the one thing about seats that reads like an omission and is not — a seat's work queue is asserted whether or not anybody holds it, because work queues until a holder appears, so installing the module a week later flushes the backlog instead of having lost it. Against a real server: every object accepted, asserting twice changes nothing (a start that failed the second time is a controller that cannot restart), a machine joining an already-raised bus is accepted, each node's consumer is bound to its own declaration subject and no other's, and CONTROL does not dead-letter — because the store window's bound belongs to the controller and a server that gave up first would discard the push the stream exists to protect. **Which bus this mesh is on is one fact, read in one place.** Every seam the change went behind ships both implementations; this is what the rollout flips. Being told about both is refused at start rather than warned about: a mesh half on each is one where a declaration goes out on one bus and the report comes back on the other, and every component logs success while it happens — ADR 0074's failure arriving through configuration instead of through code. The refusal names both variables and says which to unset, because whoever reads it has to choose and the wrong choice is a rollout half done.
This commit is contained in:
@@ -144,3 +144,93 @@ func TestEachStreamCarriesTheRetentionItsShapeNeeds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The order the bus's objects are asserted in, because getting it wrong is a refusal that names the
|
||||
// wrong thing: a consumer on a stream that does not exist is refused naming the *stream*, so
|
||||
// somebody reading it goes looking for a deletion instead of a reversed pair of lines.
|
||||
func TestTheBusesObjectsAreAssertedStreamsBeforeConsumers(t *testing.T) {
|
||||
r := &recording{}
|
||||
if err := Raise(r, []string{"anchor", "laptop"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Every stream before every consumer.
|
||||
firstConsumer := -1
|
||||
for i, step := range r.steps {
|
||||
if strings.HasPrefix(step, "consumer ") && firstConsumer < 0 {
|
||||
firstConsumer = i
|
||||
}
|
||||
if strings.HasPrefix(step, "stream ") && firstConsumer >= 0 {
|
||||
t.Fatalf("a stream was asserted after a consumer: %v", r.steps)
|
||||
}
|
||||
}
|
||||
if firstConsumer < 0 {
|
||||
t.Fatalf("no consumer was asserted: %v", r.steps)
|
||||
}
|
||||
|
||||
// And every node got one, named after it — without which that node hears nothing while
|
||||
// everything else about it looks correct.
|
||||
for _, node := range []string{"anchor", "laptop"} {
|
||||
if !containsStep(r.steps, "consumer NODES/"+node) {
|
||||
t.Errorf("%s was given no way to hear its declaration: %v", node, r.steps)
|
||||
}
|
||||
}
|
||||
// And the controller its own, on both streams it reads.
|
||||
for _, want := range []string{"consumer CONTROL/controller", "consumer EVENTS/controller"} {
|
||||
if !containsStep(r.steps, want) {
|
||||
t.Errorf("the controller is missing %s: %v", want, r.steps)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A seat's work queue is asserted whether or not anybody holds it; the holder's worker only when
|
||||
// somebody does. **The stream without the consumer is the point**: work queues until a holder
|
||||
// appears, so installing the module later flushes the backlog instead of having lost it.
|
||||
func TestASeatsQueueExistsBeforeItsHolderDoes(t *testing.T) {
|
||||
seats := []DeclaredSeat{{Name: "telegram-sender", Accepts: []string{"send"}}}
|
||||
|
||||
unheld := &recording{}
|
||||
if err := RaiseSeats(unheld, seats, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !containsStep(unheld.steps, "stream SEAT_TELEGRAM_SENDER") {
|
||||
t.Fatalf("a declared seat got no work queue: %v", unheld.steps)
|
||||
}
|
||||
for _, step := range unheld.steps {
|
||||
if strings.HasPrefix(step, "consumer ") {
|
||||
t.Fatalf("a seat nobody holds got a worker: %v", unheld.steps)
|
||||
}
|
||||
}
|
||||
|
||||
held := &recording{}
|
||||
if err := RaiseSeats(held, seats, map[string]Holder{
|
||||
"telegram-sender": {Node: "anchor", Module: "telegram"},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !containsStep(held.steps, "consumer SEAT_TELEGRAM_SENDER/SEAT_TELEGRAM_SENDER_worker") {
|
||||
t.Fatalf("the seat's holder got no worker: %v", held.steps)
|
||||
}
|
||||
}
|
||||
|
||||
// recording is a connection to the bus that writes down what it was asked for.
|
||||
type recording struct{ steps []string }
|
||||
|
||||
func (r *recording) EnsureStream(s Stream) error {
|
||||
r.steps = append(r.steps, "stream "+s.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *recording) EnsureConsumer(c Consumer) error {
|
||||
r.steps = append(r.steps, "consumer "+c.Stream+"/"+c.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func containsStep(steps []string, want string) bool {
|
||||
for _, s := range steps {
|
||||
if s == want {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user