The keeper reads pacman's database into installed.<node> and writes it only when it differs from the key, says each change as package.changed, and keeps the last value when the list is over the bus's cap, marking the node not current until it fits again; the health names the size. The loop runs over injected states, events, clock, watch and machine, and leaves hooks (start, after a transaction, state watches, wakes) for the upgrade parts of ADR 0508.
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
)
|
|
|
|
// fakeReader reads a fakeStore as a verb does.
|
|
type fakeReader struct{ *fakeStore }
|
|
|
|
func (r fakeReader) History(key string) ([]stdio.StateRevision, error) {
|
|
e, _ := r.Get(key)
|
|
if e == nil {
|
|
return []stdio.StateRevision{}, nil
|
|
}
|
|
return []stdio.StateRevision{{Key: key, Value: e.Value, Revision: e.Revision, Op: "put", At: r.at[key]}}, nil
|
|
}
|
|
|
|
// readerOf is a machine's States over fake states.
|
|
func readerOf(states *fakeStates) func(string) StateReader {
|
|
return func(name string) StateReader { return fakeReader{states.store(name)} }
|
|
}
|
|
|
|
// 1840/AC3: the health is unhealthy naming the size while the node is marked not current, and says nothing of
|
|
// it once the mark is gone.
|
|
func TestTheHealthNamesTheSizeWhileTheNodeIsNotCurrent(t *testing.T) {
|
|
states := &fakeStates{}
|
|
m := machine(nil, 1000)
|
|
m.Node, m.States = "node-a", readerOf(states)
|
|
if _, said := m.InstalledHealth(); said {
|
|
t.Fatal("a current node's health said something")
|
|
}
|
|
states.store(StateInstalled).Put("node-a.not-current", NotCurrent{Bytes: 300000, Since: t0})
|
|
states.store(StateInstalled).Put("node-b.not-current", NotCurrent{Bytes: 1, Since: t0})
|
|
h, said := m.InstalledHealth()
|
|
if !said || h.Healthy || !strings.Contains(h.Why, "300000 bytes") || !strings.Contains(h.Why, "2026-10-24 04:00") {
|
|
t.Fatalf("%+v", h)
|
|
}
|
|
states.store(StateInstalled).Delete("node-a.not-current")
|
|
if _, said := m.InstalledHealth(); said {
|
|
t.Fatal("the mark is gone and the health still says it")
|
|
}
|
|
}
|