Delete the push and the declaration: the send stub and node holds, link declare and its order, the sent readers, and the sweep judged by compositions (release 6, issue 1945 B8)
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
sdkdecl "git.novox.be/novox/mesh-sdk/go/declaration"
|
||||
sdkdelivery "git.novox.be/novox/mesh-sdk/go/delivery"
|
||||
|
||||
"github.com/novox/mesh-controller/internal/conditions"
|
||||
"github.com/novox/mesh-controller/internal/link"
|
||||
@@ -55,7 +56,7 @@ func wireSizeOf(t *testing.T, s sendable) int {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The signature the controller's key makes is 64 bytes.
|
||||
msg, err := link.Envelope(body, make([]byte, 64))
|
||||
msg, err := json.Marshal(link.Signed{Declaration: body, Signature: make([]byte, 64)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -306,22 +307,43 @@ func TestAnObjectIsRemovedADayAfterNoLatestDeclarationNamesIt(t *testing.T) { //
|
||||
}
|
||||
}
|
||||
|
||||
// What a node's latest declaration names is read from the signed envelope as stored on the bus; an unreadable one is an error and
|
||||
// never "names none", which would mark an object a node needs.
|
||||
func TestTheObjectsALatestDeclarationNamesAreReadFromTheBus(t *testing.T) {
|
||||
s := sendable{fileReferences: true, Resources: []map[string]any{aFileResource("a", contentOf("a", 70<<10))}}
|
||||
body, _ := s.Body()
|
||||
msg, _ := link.Envelope(body, []byte("sig"))
|
||||
named, err := namedByLatest("novox", msg)
|
||||
name, _ := sdkdecl.ObjectName(sdkdecl.DigestOf([]byte(contentOf("a", 70<<10))))
|
||||
// What a node's compositions name is read from the values of its bucket `composed-<node>`: the files each carries by digest
|
||||
// (ADR 0539 §4). An unreadable one is an error and never "names none", which would mark an object a node needs.
|
||||
func TestTheObjectsACompositionNamesAreReadFromItsValue(t *testing.T) {
|
||||
content := contentOf("a", 70<<10)
|
||||
digest := sdkdecl.DigestOf([]byte(content))
|
||||
ref, _ := json.Marshal(map[string]any{"id": "m.f", "type": "file", "module": "m", "path": "/etc/m", "digest": digest,
|
||||
"size": len(content)})
|
||||
small := json.RawMessage(`{"id":"m.g","type":"file","module":"m","path":"/etc/g","content":"x"}`)
|
||||
fp := sdkdelivery.SourcePrefix2 + strings.Repeat("a", 64)
|
||||
value, err := sdkdelivery.EncodeComposed(sdkdelivery.Composed{Node: "novox", Module: "m", FP: fp,
|
||||
Resources: []json.RawMessage{ref, small}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
named, err := namedByCompositions("novox", [][]byte{value})
|
||||
name, _ := sdkdecl.ObjectName(digest)
|
||||
if err != nil || len(named) != 1 || !named[name] {
|
||||
t.Fatalf("%v %v", named, err)
|
||||
}
|
||||
if none, err := namedByLatest("ace", []byte(`{"declaration":"e30=","signature":""}`)); err != nil || len(none) != 0 {
|
||||
t.Fatalf("a declaration naming none: %v %v", none, err)
|
||||
none, _ := sdkdelivery.EncodeComposed(sdkdelivery.Composed{Node: "ace", Module: "m", FP: fp, Resources: []json.RawMessage{small}})
|
||||
if got, err := namedByCompositions("ace", [][]byte{none}); err != nil || len(got) != 0 {
|
||||
t.Fatalf("a composition naming none: %v %v", got, err)
|
||||
}
|
||||
if _, err := namedByLatest("novox", []byte("not json")); err == nil {
|
||||
t.Fatal("an unreadable latest declaration was read as naming none")
|
||||
if got, err := namedByCompositions("ace", nil); err != nil || len(got) != 0 {
|
||||
t.Fatalf("a node with no composition: %v %v", got, err)
|
||||
}
|
||||
if _, err := namedByCompositions("novox", [][]byte{[]byte("not json")}); err == nil {
|
||||
t.Fatal("an unreadable composition was read as naming none")
|
||||
}
|
||||
// A node's objects are those of every composition it keeps: the five newest fingerprints of a module name their own.
|
||||
other := sdkdecl.DigestOf([]byte(contentOf("b", 80<<10)))
|
||||
ref2, _ := json.Marshal(map[string]any{"id": "m.f", "type": "file", "module": "m", "path": "/etc/m", "digest": other, "size": 80 << 10})
|
||||
older, _ := sdkdelivery.EncodeComposed(sdkdelivery.Composed{Node: "novox", Module: "m", FP: sdkdelivery.SourcePrefix2 + strings.Repeat("b", 64),
|
||||
Resources: []json.RawMessage{ref2}})
|
||||
both, err := namedByCompositions("novox", [][]byte{value, older})
|
||||
if err != nil || len(both) != 2 {
|
||||
t.Fatalf("two fingerprints of one module name %v (%v), want both objects", both, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user