A delivery and the five-minute reconcile were two paths that applied, ordered only by a lock, and each order it allowed was met live (issues 257, 261, 267). Now both only enqueue: one worker takes the newest declaration held when it starts, applies it once and makes one report, and reports leave in the order they are made. A declaration may carry the controller's lease epoch beside its sequence; one older than what this node applied is refused before anything is touched, counted, logged and reported. A report carries the declaration's epoch and sequence and the host's own report sequence, kept on disk so it goes on increasing across restarts and self-updates. Without an epoch, today's behaviour stands.
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package declaration
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A declaration says where it stands — the controller's lease epoch and its sequence — inside what is
|
|
// signed (novox/hq to-be 45 §6). Absent is no claim; below zero is no order the mesh assigns.
|
|
|
|
func withOrder(order string) string {
|
|
return `{"declaration":1,` + order + `"resources":[{"id":"etc","type":"directory","path":"/etc/mesh","mode":"0755"}]}`
|
|
}
|
|
|
|
func TestADeclarationCarriesItsEpochAndSequence(t *testing.T) {
|
|
d, err := Parse([]byte(withOrder(`"epoch":57,"sequence":3,`)))
|
|
if err != nil {
|
|
t.Fatalf("a declaration carrying its order was refused: %v", err)
|
|
}
|
|
if d.Epoch != 57 || d.Sequence != 3 {
|
|
t.Fatalf("read epoch %d, sequence %d", d.Epoch, d.Sequence)
|
|
}
|
|
// An older controller's: no order, and no claim.
|
|
d, err = Parse([]byte(withOrder(``)))
|
|
if err != nil || d.Epoch != 0 || d.Sequence != 0 {
|
|
t.Fatalf("a declaration with no order read as %+v, %v", d, err)
|
|
}
|
|
}
|
|
|
|
func TestAnOrderBelowZeroIsRefused(t *testing.T) {
|
|
for _, order := range []string{`"epoch":-1,`, `"sequence":-4,`} {
|
|
refusal := refusalFor(t, withOrder(order))
|
|
if !strings.Contains(refusal.Error(), "below zero") {
|
|
t.Errorf("%s: refused for something else: %v", order, refusal)
|
|
}
|
|
}
|
|
}
|