Both branches changed the seat set from the same starting point, so every number collided and every `mesh-*` name existed twice. The trunk's numbers and names win: this branch's records became 0129/0130 and its migrations 0037/0038, and the hardcoded rename map gave way to the trunk's `seat_alias` table — a rename is a row now (ADR 0122), not a recompile. Three of my checks were wrong and the merge is what showed it: A seat with an empty protocol is a marker, not an incomplete declaration. Most node-scoped seats are markers — which module is this machine's packet filter — and refusing one refused most of the set, the showcase module included. A mistyped field name is already refused by the parser, so an empty protocol was written as one deliberately. A claim on a seat this manifest does not declare is not the parser's to judge. A module may hold a seat another module declared; that is the whole reason ADR 0126 has callers name the seat and not its provider. Whether the seat exists is a fact about the catalogue, so the refusal is at registration, where every declaration is in view. And a seat may share a name with the provision it delivers. `git`, the npm registry and the artifact store still do, because renaming a delivering seat cascades to every consumer requiring it, with a window where a holder stops resolving mid-flight. The trunk deferred exactly those three on purpose. Full suite green against a real NATS and store.
102 lines
4.7 KiB
Go
102 lines
4.7 KiB
Go
package catalogue
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// The mesh's bus is one per mesh, read from the catalogue beside this checkout.
|
|
//
|
|
// **This is step 2's claim, and it is checked here rather than in a bed** (novox/hq ADR 0116):
|
|
// adoption puts the NATS server into the `mesh-broker` seat on a mesh that is already running,
|
|
// and the property that matters is that a second one anywhere is refused *when it is assigned*,
|
|
// not discovered later as two servers holding different halves of the mesh's traffic. A second
|
|
// bus is not a degraded mesh; it is two meshes that both believe they are the one.
|
|
func TestASecondMeshBusAnywhereIsRefusedByName(t *testing.T) {
|
|
nats := catalogueManifest(t, "nats")
|
|
|
|
if _, err := Resolve(shelf(nats), []string{"nats"}, workstation(), World{}); err != nil {
|
|
t.Fatalf("the bus alone does not resolve: %v", err)
|
|
}
|
|
|
|
elsewhere := World{Held: []Held{{Claim: "mesh-broker", Scope: ScopeMesh,
|
|
Node: "anchor", Module: "nats"}}}
|
|
other := workstation()
|
|
other.Name = "laptop"
|
|
_, err := Resolve(shelf(nats), []string{"nats"}, other, elsewhere)
|
|
if err == nil {
|
|
t.Fatal("a second bus was accepted on another machine")
|
|
}
|
|
if !strings.Contains(err.Error(), "mesh-broker") || !strings.Contains(err.Error(), "one per mesh") {
|
|
t.Fatalf("refused without naming the seat: %v", err)
|
|
}
|
|
}
|
|
|
|
// The seat is the server's role, not the product's name (novox/hq ADR 0079). A different
|
|
// implementation of the bus claims the same seat, and the mesh refuses it for the same reason —
|
|
// which is the property that lets the bus be replaced at all.
|
|
func TestTheSeatRefusesADifferentBusToo(t *testing.T) {
|
|
nats := catalogueManifest(t, "nats")
|
|
held := World{Held: []Held{{Claim: "mesh-broker", Scope: ScopeMesh,
|
|
Node: "anchor", Module: "some-other-broker"}}}
|
|
other := workstation()
|
|
other.Name = "laptop"
|
|
if _, err := Resolve(shelf(nats), []string{"nats"}, other, held); err == nil {
|
|
t.Fatal("the seat admitted a second holder because the module's name differed")
|
|
}
|
|
}
|
|
|
|
// The old broker no longer claims the seat: it is an ordinary provider of `amqp`
|
|
// (novox/hq ADR 0119), so it can sit on the same mesh as the bus without contending for it.
|
|
func TestTheAmqpBrokerDoesNotContendForTheSeat(t *testing.T) {
|
|
lavinmq := catalogueManifest(t, "lavinmq")
|
|
for _, c := range lavinmq.Claims {
|
|
if c.Name == "mesh-broker" {
|
|
t.Fatal("the amqp broker still claims mesh-broker; it is a provider, not foundation")
|
|
}
|
|
}
|
|
busHeld := World{Held: []Held{{Claim: "mesh-broker", Scope: ScopeMesh,
|
|
Node: "anchor", Module: "nats"}}}
|
|
other := workstation()
|
|
other.Name = "laptop"
|
|
if _, err := Resolve(shelf(lavinmq), []string{"lavinmq"}, other, busHeld); err != nil {
|
|
t.Fatalf("the amqp broker was refused beside the mesh bus: %v", err)
|
|
}
|
|
}
|
|
|
|
// **A seat and the interface it delivers are different names, and renaming one must not rename
|
|
// the other** (novox/hq ADR 0118). This nearly went wrong: the seats were renamed to the `mesh-*`
|
|
// prefix, and a blanket search-and-replace also renamed `npm-package-registry` and `git` where
|
|
// they are *provisions* — which a consumer requires and a provider offers. The tests failed with
|
|
// "the package registry is served on <nil>", which does not say "you renamed an interface".
|
|
func TestRenamingASeatDidNotRenameTheInterfaceItDelivers(t *testing.T) {
|
|
for _, pair := range []struct{ seat, delivers string }{
|
|
{"git", "git"},
|
|
{"npm-package-registry", "npm-package-registry"},
|
|
{"the-artifact-store", "artifact-store"},
|
|
{"mesh-store", "postgres-database"},
|
|
{"mesh-broker", "mesh-bus"},
|
|
} {
|
|
s, known := SeatNamed(pair.seat)
|
|
if !known {
|
|
t.Fatalf("%q is not a seat", pair.seat)
|
|
}
|
|
if s.Delivers != pair.delivers {
|
|
t.Errorf("the %s seat delivers %q, expected %q — renaming the seat moved the "+
|
|
"interface with it, and every consumer requiring it would stop resolving",
|
|
pair.seat, s.Delivers, pair.delivers)
|
|
}
|
|
// **Three of these deliberately share a name with what they deliver**, and that is not an
|
|
// incomplete rename. Renaming a seat that delivers a provision cascades to every consumer
|
|
// requiring it, with a mesh-wide window where a holder stops resolving mid-flight — so the
|
|
// trunk deferred exactly those three (novox/hq ADR 0121) while renaming the node-scoped ones.
|
|
// What this test is for is the other direction: that renaming a seat never moves the
|
|
// interface, which once produced "the package registry is served on <nil>".
|
|
}
|
|
}
|
|
|
|
// A manifest written against an old seat name is told what it became rather than refused as
|
|
// unknown. **That map is the controller's store now, not this package** (novox/hq ADR 0122): a
|
|
// rename is a row, so the courtesy survives a rename nobody recompiled for. Checked where the
|
|
// table is read, not here, where there is no longer a hardcoded list to check against.
|