With no plan left to take a done key in, a write of the builder's keys registers the new fingerprint, composes the module's nodes and the bus's user list, and writes its grant, so the assigner's rules can name it (ADR 0539 clauses 5 and 7). The new controller composes every node at its start, and the controller it replaced at its own fingerprint, the operator's way back (clause 10); the merge window's, silent sends' and building plans' buckets are no longer asserted and are deleted once, each said as the event bucket-deleted (clause 13). The assigner may read the compositions' digests, and a node-engine hears its backup holder's backed-up.
75 lines
2.8 KiB
Go
75 lines
2.8 KiB
Go
package broker
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// 1945/AC1: a node's composition bucket keeps five revisions of a key and is named for its node; the bucket of digests
|
|
// likewise; a node name a subject would widen is refused.
|
|
func TestTheCompositionBuckets(t *testing.T) {
|
|
cfg, err := ComposedConfig("ace")
|
|
if err != nil || cfg.Bucket != "composed-ace" || cfg.History != 5 {
|
|
t.Fatalf("ComposedConfig(ace) = %+v, %v", cfg, err)
|
|
}
|
|
if d := ComposedDigestsConfig(); d.Bucket != delivery.ControllerComposedBucket || d.History != 5 {
|
|
t.Errorf("ComposedDigestsConfig = %+v", d)
|
|
}
|
|
if _, err := ComposedConfig("a.b"); err == nil {
|
|
t.Errorf("a dotted node got a bucket")
|
|
}
|
|
}
|
|
|
|
// 1945/AC1: a node-engine reads its own compositions and its own wants and nothing of another node's, nor the digests;
|
|
// the controller writes a node's bucket by its own subjects.
|
|
func TestANodeReadsOnlyItsOwnCompositions(t *testing.T) {
|
|
reads, err := ComposedReads("ace")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
all := strings.Join(reads, " ")
|
|
for _, want := range []string{"KV_composed-ace", "$KV.mesh-delivery-assigner_wants.want.ace.>"} {
|
|
if !strings.Contains(all, want) {
|
|
t.Errorf("a node-engine of ace cannot reach %s: %v", want, reads)
|
|
}
|
|
}
|
|
for _, never := range []string{"composed-g14", delivery.ControllerComposedBucket, "$KV.composed-ace", "want.*", "want.>"} {
|
|
if strings.Contains(all, never) {
|
|
t.Errorf("a node-engine of ace is granted %s: %v", never, reads)
|
|
}
|
|
}
|
|
if w, err := ComposedWrites("ace"); err != nil || w != "$KV.composed-ace.>" {
|
|
t.Errorf("ComposedWrites(ace) = %q, %v", w, err)
|
|
}
|
|
if _, err := ComposedReads("a*"); err == nil {
|
|
t.Errorf("a node name with a wildcard was granted")
|
|
}
|
|
}
|
|
|
|
// 1945 (for issue 1944): a node-engine asks its own machine's backup holder to back a data module up before it moves
|
|
// and when it last was, and no other machine's.
|
|
func TestANodeAgentAsksItsOwnBackupHolder(t *testing.T) {
|
|
asks, err := NodeAgentAsks("ace")
|
|
if err != nil || strings.Join(asks, " ") != "mesh.seat.node-backup.tool.now.ace mesh.seat.node-backup.tool.backed-up.ace" {
|
|
t.Errorf("NodeAgentAsks(ace) = %v, %v", asks, err)
|
|
}
|
|
p, err := PermissionsFor(Principal{Kind: KindNode, Node: "ace", PasswordHash: "x"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
all := strings.Join(p.Publish, " ")
|
|
for _, want := range append(asks, "$JS.API.DIRECT.GET.KV_composed-ace.>") {
|
|
if !strings.Contains(all, want) {
|
|
t.Errorf("a node-engine of ace may not publish %s", want)
|
|
}
|
|
}
|
|
if !strings.Contains(strings.Join(p.Subscribe, " "), "mesh.mod.*.event.backed-up") {
|
|
t.Errorf("a node-engine of ace does not hear a backup taken: %v", p.Subscribe)
|
|
}
|
|
if strings.Contains(all, "node-backup.tool.now.*") || strings.Contains(all, "KV_composed-g14") {
|
|
t.Errorf("a node-engine of ace reaches another machine: %v", p.Publish)
|
|
}
|
|
}
|