Files
mesh-catalog/modules/zfs/cmd/zfs-tools/follow_wake_test.go
T
jschoubben 53351dd30d
mesh/delivery merged: source.main moved to novox/mesh-catalog@6ba73d4e2a4f
mesh/delivery-group group feat/47-G-join12 merged: every member is merged
mesh/check failed (2): mesh-delivery-checker: no published of the tagged version of go-meshconditions of me…; and 1 more | 53351dd30df2 on b1125c02cfe6
Merge main into feat/47-G-join11: the zfs module and pacman's config first (issue 1979); zfs's findings in G's form
mesh-conditions keeps G's form: the keeper reads no observer's state (no reads, no Observers list), so main's zfs entry there goes. The zfs follower says its findings through G's findings writer over its keeper: the keeper gains the publish of the writer's three events on the finding stream finding-events and the hear of mesh-conditions.findings-asked on its own durable, nothing else; each pool or device not ONLINE is scope module, id zfs.<pool>.<device> (the device's own name), kind not-online, on the node. The manifest asks its state findings by template in requires (G §529, §577), and gains the finding-events stream and the consumes, and the keeper's bus the three events and the consumes.

Builds: design 47 G §383, §384, §387, §529, §577, A-339, A-340, A-341, A-342; design 42 zfs-owns-zfs §27, A-32, A-37, A-39, A-41

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-13 09:32:48 +01:00

136 lines
4.7 KiB
Go

package main
import (
"context"
"encoding/json"
"net"
"path/filepath"
"strings"
"testing"
"time"
)
// §18, §27, A-16: the apply is started once at the follower's start and on scrub_finish, resilver_finish and a
// declared device's udev add, through the service manager; a device not ONLINE is a finding, written once,
// deleted when ONLINE again or gone.
func TestTheFollowerStartsTheApplyOnTheEventsThatEndAWaitAndKeepsTheFindings(t *testing.T) {
for class, want := range map[string]bool{"sysevent.fs.zfs.scrub_finish": true, "sysevent.fs.zfs.resilver_finish": true,
"sysevent.fs.zfs.scrub_start": false, "ereport.fs.zfs.io": false} {
if EndsAWait(class) != want {
t.Errorf("%s: %v", class, !want)
}
}
f := newFake(t)
f.uid = 0
f.files[ConfigFile] = `{"pool":"tank","cache-devices":["c1"]}`
f.files[MemInfoFile] = "MemTotal: 16384000 kB\n"
f.links["/dev/disk/by-id/c1"] = "/dev/nvme1n1"
m := f.machine()
var key string
var body any
m.Node = "ace"
m.Call = func(k string, b any) (json.RawMessage, error) { key, body = k, b; return nil, nil }
udev := map[string]bool{
"UDEV [12.3] add /devices/pci0000:00/nvme/nvme1/nvme1n1 (block)": true,
"UDEV [12.3] add /devices/pci0000:00/nvme/nvme1/nvme1n1/nvme1n1p1 (block)": true,
"UDEV [12.3] add /devices/pci0000:00/nvme/nvme2/nvme2n1 (block)": false,
"UDEV [12.3] remove /devices/pci0000:00/nvme/nvme1/nvme1n1 (block)": false,
"KERNEL[12.3] add /devices/pci0000:00/nvme/nvme1/nvme1n1 (block)": false,
}
for line, want := range udev {
if m.DeclaredAdded(line) != want {
t.Errorf("%q: %v", line, !want)
}
}
if err := m.FollowUdev(strings.NewReader("UDEV [1] add /devices/x/nvme2n1 (block)\nUDEV [2] add /devices/x/nvme1n1 (block)\n")); err != nil {
t.Fatal(err)
}
args, _ := body.(map[string]any)
if key != "seat:node-service-manager.start@ace" || args["unit"] != ApplyUnit || args["scope"] != "system" {
t.Errorf("called %s with %v", key, body)
}
// The findings (§27; design 47 G A-339, A-341): G's writer over the keeper. It states what it observes at its start
// and on an ask, says a device not ONLINE once, under its own key, and clears it when ONLINE again.
dir, err := shortTempDir("kf")
if err != nil {
t.Fatal(err)
}
sock := filepath.Join(dir, "k.sock")
l, err := Listen(sock)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
st := memStates{}
said := make(chan string, 64)
asks := make(chan func([]byte), 1)
go (&Keeper{States: st, PeerOf: func(net.Conn) (int, error) { return 0, nil },
Finding: func(event string, body json.RawMessage, id string) error {
said <- event + " " + string(body)
return nil
},
HearAsks: func(_ context.Context, handle func([]byte)) (func(), error) { asks <- handle; return func() {}, nil }}).Serve(ctx, l)
t.Setenv(KeeperSocketEnv, sock)
m.JoinBus()
next := func(want string) string {
t.Helper()
select {
case e := <-said:
if !strings.HasPrefix(e, want+" ") {
t.Fatalf("said %s, want %s", e, want)
}
return e
case <-time.After(5 * time.Second):
t.Fatalf("nothing said, want %s", want)
}
return ""
}
f.on(line("zpool", StatusPathsArgv()), fixture(t, "zpool-status-degraded.txt"))
if err := m.StartFindings(ctx, t.Logf); err != nil {
t.Fatal(err)
}
ask := <-asks
ids := []string{"zfs.tank.pool", "zfs.tank.raidz2-0", "zfs.tank.ata-WDC_WD120EFBX-68B0EN0_D7JA0002"}
stated := next("findings-stated")
for _, id := range ids {
if !strings.Contains(stated, `"id":"`+id+`"`) {
t.Errorf("the start's statement holds no %s: %s", id, stated)
}
}
if !strings.Contains(stated, `"kind":"not-online"`) || !strings.Contains(stated, `"machine":"ace"`) {
t.Errorf("the statement's findings are not of the kind not-online on ace: %s", stated)
}
for _, id := range ids {
if _, ok := st["findings/module."+id+".not-online"]; !ok {
t.Errorf("no key of %s in %v", id, st)
}
}
// Unchanged, nothing more is said; ONLINE again, each is cleared; an ask is answered with what holds now.
if err := m.SyncFindings(ctx); err != nil {
t.Fatal(err)
}
f.on(line("zpool", StatusPathsArgv()), fixture(t, "zpool-status.txt"))
if err := m.SyncFindings(ctx); err != nil {
t.Fatal(err)
}
for range 4 {
next("finding-cleared")
}
if len(st) != 0 {
t.Errorf("left %v", st)
}
ask([]byte(`{"ask":"a1"}`))
if e := next("findings-stated"); !strings.Contains(e, `"asked":"a1"`) || !strings.Contains(e, `"findings":[]`) {
t.Errorf("the answer to the ask: %s", e)
}
f.on(line("zpool", StatusPathsArgv()), fixture(t, "zpool-status-degraded.txt"))
if err := m.SyncFindings(ctx); err != nil {
t.Fatal(err)
}
for range 4 {
next("finding-written")
}
}