The end judgement took every mover with no step as waiting on its registration; one may wait for the publish of a mover it builds on. The registration lookup tells them apart, and the why names each with its own reason. Builds: design 47 H §746, H-A-163, H-A-171, G A-327
380 lines
19 KiB
Go
380 lines
19 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
|
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
|
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
|
wants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
|
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
type memStore map[string]struct {
|
|
p seat.Pipeline
|
|
rev uint64
|
|
}
|
|
|
|
func (m memStore) Get(key string) (seat.Pipeline, uint64, error) {
|
|
e, ok := m[key]
|
|
if !ok {
|
|
return seat.Pipeline{}, 0, errors.New("no such key")
|
|
}
|
|
// A read is a copy, as one from the bus is: a change not written is not seen by the next read.
|
|
e.p.Steps = append([]seat.StepResult(nil), e.p.Steps...)
|
|
e.p.Movers = append([]seat.Mover(nil), e.p.Movers...)
|
|
return e.p, e.rev, nil
|
|
}
|
|
|
|
func (m memStore) Update(key string, p seat.Pipeline, rev uint64) (uint64, error) {
|
|
if m[key].rev != rev {
|
|
return 0, ErrChanged
|
|
}
|
|
m[key] = struct {
|
|
p seat.Pipeline
|
|
rev uint64
|
|
}{p, rev + 1}
|
|
return rev + 1, nil
|
|
}
|
|
|
|
func (m memStore) Keys(filter string) ([]string, error) {
|
|
var out []string
|
|
for k := range m {
|
|
if ok, _ := matchKey(filter, k); ok {
|
|
out = append(out, k)
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func matchKey(filter, key string) (bool, error) {
|
|
f, k := strings.Split(filter, "."), strings.Split(key, ".")
|
|
if len(f) != len(k) {
|
|
return false, nil
|
|
}
|
|
for i := range f {
|
|
if f[i] != "*" && f[i] != k[i] {
|
|
return false, nil
|
|
}
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
type askRecorder struct{ asked []oc.Ask }
|
|
|
|
func (a *askRecorder) Ask(x oc.Ask) error { a.asked = append(a.asked, x); return nil }
|
|
|
|
const pkey = "main.5"
|
|
|
|
// fixture is a pipeline of app with a required lint asked of node-build-go, an optional unit asked of the same seat and an
|
|
// approval step waiting, and a hearer over it.
|
|
func fixture() (*Hearer, memStore, *[]string, *askRecorder, map[string]seat.KeptResult, map[string]string) {
|
|
store := memStore{pkey: {p: seat.Pipeline{V: 1, Pipeline: pkey, Branch: "main", Source: 5,
|
|
Outcome: seat.PipelineOutcomeRunning, Steps: []seat.StepResult{
|
|
{Module: "app", Artifact: "program", Step: seat.StepResultStepLint, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeRunning, Ask: "a1", Seat: nodebuildgo.Seat},
|
|
{Module: "app", Artifact: "program", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusOptional, Outcome: seat.StepResultOutcomeRunning, Ask: "a2", Seat: nodebuildgo.Seat},
|
|
{Module: "app", Artifact: "program", Step: seat.StepResultStepApproval, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeWaiting}}, Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}}}, rev: 1}}
|
|
said := &[]string{}
|
|
asker := &askRecorder{}
|
|
kept := map[string]seat.KeptResult{}
|
|
outs := map[string]string{}
|
|
h := &Hearer{Store: store, Name: "mesh-pipeline-runner", Asker: asker,
|
|
Say: func(subject string, _ any) error {
|
|
*said = append(*said, subject[strings.Index(subject, ".event.")+7:])
|
|
return nil
|
|
},
|
|
Log: func(seat.LogEntry) error { return nil },
|
|
Keep: func(k string, v seat.KeptResult) error { kept[k] = v; return nil },
|
|
Output: func(k string, d []byte) error { outs[k] = string(d); return nil },
|
|
Now: func() time.Time { return time.Date(2026, 11, 11, 12, 0, 0, 0, time.UTC) }}
|
|
return h, store, said, asker, kept, outs
|
|
}
|
|
|
|
func ended(ask, step, outcome string) StepEnded {
|
|
return StepEnded{ID: ask, Ask: ask, Node: "n1", Pipeline: pkey, Module: "app", Commit: "c1", Fingerprint: "src2:aa", Step: step, Outcome: outcome}
|
|
}
|
|
|
|
var goSeat = StepSeat{Seat: nodebuildgo.Seat, Prefix: "mesh.seat.node-build-go.event.step-ended."}
|
|
|
|
// A step's end is taken only as the runner asked it (design 47 G §24; ADR 0666 §21).
|
|
func TestStepEndedIsTakenOnlyAsAsked(t *testing.T) {
|
|
h, store, _, _, _, _ := fixture()
|
|
other := ended("a1", "lint", "passed")
|
|
other.Fingerprint = "src2:bb"
|
|
wrongNode := ended("a1", "lint", "passed")
|
|
wrongNode.Node = "n2"
|
|
unknownPipeline := ended("a1", "lint", "passed")
|
|
unknownPipeline.Pipeline = "main.9"
|
|
for name, c := range map[string]struct {
|
|
subject string
|
|
ev StepEnded
|
|
}{
|
|
"a subject of another seat": {"mesh.seat.node-build-node.event.step-ended.n1", ended("a1", "lint", "passed")},
|
|
"a body naming another node": {goSeat.Prefix + "n1", wrongNode},
|
|
"an unknown pipeline": {goSeat.Prefix + "n1", unknownPipeline},
|
|
"an ask nobody made": {goSeat.Prefix + "n1", ended("zz", "lint", "passed")},
|
|
"another fingerprint": {goSeat.Prefix + "n1", other},
|
|
"another step": {goSeat.Prefix + "n1", ended("a1", "unit", "passed")},
|
|
"an outcome step-ended lacks": {goSeat.Prefix + "n1", ended("a1", "lint", "waiting")},
|
|
} {
|
|
if _, err := h.OnStepEnded(goSeat, c.subject, c.ev); !errors.Is(err, ErrRefused) {
|
|
t.Errorf("%s: err %v, want a refusal", name, err)
|
|
}
|
|
}
|
|
if store[pkey].p.Steps[0].Outcome != seat.StepResultOutcomeRunning {
|
|
t.Error("a refused end changed the pipeline")
|
|
}
|
|
// R2/AC1 (design 47 G §24, §69): the end of another asker's step (the assigner's composer build, which names no
|
|
// pipeline) is not the runner's: it writes and says nothing, read before any pipeline, and is acknowledged.
|
|
theirs := ended("b7", "build", "passed")
|
|
theirs.Asker, theirs.Pipeline = "mesh-delivery-assigner", ""
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", theirs); err != nil {
|
|
t.Errorf("another asker's step end: err %v, want it taken as nothing", err)
|
|
}
|
|
if store[pkey].p.Steps[0].Outcome != seat.StepResultOutcomeRunning || store[pkey].rev != 1 {
|
|
t.Error("another asker's step end changed the pipeline")
|
|
}
|
|
// The seat the step was asked of is the only one that ends it.
|
|
if _, err := h.OnStepEnded(StepSeat{Seat: "node-build-node", Prefix: "mesh.seat.node-build-node.event.step-ended."}, "mesh.seat.node-build-node.event.step-ended.n1", ended("a1", "lint", "passed")); !errors.Is(err, ErrRefused) {
|
|
t.Errorf("another seat's holder ended the step: %v", err)
|
|
}
|
|
}
|
|
|
|
// A taken end is written, kept and said; the pipeline ends once every step ended (§24, §27).
|
|
func TestStepEndedEndsThePipeline(t *testing.T) {
|
|
h, store, said, _, kept, outs := fixture()
|
|
h.Asker = nil
|
|
lint := ended("a1", "lint", "passed")
|
|
lint.Output = "all clean"
|
|
unit := ended("a2", "unit", "failed")
|
|
unit.Kept = []nodebuildgo.KeptResult{{Digest: "sha256:d1", Level: "unit", Package: "app/x"}}
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", lint); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if p := store[pkey].p; p.Outcome != seat.PipelineOutcomeRunning || p.Steps[0].Node != "n1" || p.Steps[0].Output == "" {
|
|
t.Fatalf("after the lint: %+v", p)
|
|
}
|
|
if len(outs) != 1 {
|
|
t.Errorf("outputs kept %v", outs)
|
|
}
|
|
// Approval waits with no asker, so the pipeline does not end on the last test step alone.
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", unit); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if p := store[pkey].p; p.Outcome != seat.PipelineOutcomeRunning {
|
|
t.Fatalf("a pipeline with its approval waiting ended: %+v", p)
|
|
}
|
|
if k := kept[seat.KeptByLevelDigestKey("unit", keys.EscapeName("sha256:d1"))]; k.Package != "app/x" || k.Pipeline != pkey {
|
|
t.Errorf("kept %+v", kept)
|
|
}
|
|
// A step heard again takes nothing.
|
|
n := len(*said)
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", unit); err != nil || len(*said) != n {
|
|
t.Errorf("a second end said %v (%v)", (*said)[n:], err)
|
|
}
|
|
}
|
|
|
|
// The approval step is asked last, only when every other required step passed, and ended by its warrant (§26, §37).
|
|
func TestApprovalIsAskedLastAndEndedByItsWarrant(t *testing.T) {
|
|
h, store, said, asker, _, _ := fixture()
|
|
var record *oc.Warrant
|
|
h.Where = func(string) (string, *oc.Warrant, error) { return "chosen", record, nil }
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ended("a1", "lint", "passed")); err != nil || len(asker.asked) != 0 {
|
|
t.Fatalf("asked %d before the unit step ended (%v)", len(asker.asked), err)
|
|
}
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ended("a2", "unit", "failed")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// An optional step that failed holds nothing: the approval is asked.
|
|
if len(asker.asked) != 1 || asker.asked[0].About != "app.main" {
|
|
t.Fatalf("asked %+v", asker.asked)
|
|
}
|
|
a := asker.asked[0]
|
|
if got := (*said)[len(*said)-1]; !strings.HasPrefix(got, "wait-held.main.5") {
|
|
t.Errorf("the wait was said as %q", got)
|
|
}
|
|
warrant := func(option, outcome string) oc.Warrant {
|
|
return oc.Warrant{Asker: "mesh-pipeline-runner", Ask: a.ID, About: a.About, Outcome: outcome, Option: option, Level: operatorchannelclient.Approve,
|
|
AskDigest: operatorchannelclient.Digest(a), At: operatorchannelclient.FormatTime(time.Date(2026, 11, 11, 13, 0, 0, 0, time.UTC)),
|
|
By: &oc.Person{Who: operatorchannelclient.Operator, Identity: "op", Kind: "telegram", Verified: "linked"}}
|
|
}
|
|
// The event only wakes the runner (A-89): an event that says approve while the router's record holds none takes nothing.
|
|
event := warrant(OptionApprove, oc.WarrantOutcomeChosen)
|
|
if _, err := h.OnDecided(event); !errors.Is(err, ErrNoRecord) || store[pkey].p.Steps[2].Outcome != seat.StepResultOutcomeRunning {
|
|
t.Errorf("an event with no record was taken: %v", err)
|
|
}
|
|
// A record whose warrant is for another ask's digest is not taken; an event of another asker neither.
|
|
bad := warrant(OptionApprove, oc.WarrantOutcomeChosen)
|
|
bad.AskDigest = "sha256:other"
|
|
record = &bad
|
|
if _, err := h.OnDecided(event); err == nil || store[pkey].p.Steps[2].Outcome != seat.StepResultOutcomeRunning {
|
|
t.Errorf("a warrant for another ask was taken: %v", err)
|
|
}
|
|
notMine := event
|
|
notMine.Asker = "someone"
|
|
if _, err := h.OnDecided(notMine); !errors.Is(err, ErrRefused) {
|
|
t.Errorf("another asker's event: %v", err)
|
|
}
|
|
// The record says decline although the event body says approve: the record decides.
|
|
decline := warrant(OptionDecline, oc.WarrantOutcomeChosen)
|
|
record = &decline
|
|
if p, err := h.OnDecided(event); err != nil || p.Steps[2].Outcome != seat.StepResultOutcomeDeclined {
|
|
t.Fatalf("the record said decline: %+v (%v)", p.Steps[2], err)
|
|
}
|
|
// (the declined pipeline above is a fresh fixture's: approve it on a new one)
|
|
h, store, said, asker, _, _ = fixture()
|
|
h.Where = func(string) (string, *oc.Warrant, error) { return "chosen", record, nil }
|
|
for _, s := range []StepEnded{ended("a1", "lint", "passed"), ended("a2", "unit", "failed")} {
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
a = asker.asked[0]
|
|
approve := warrant(OptionApprove, oc.WarrantOutcomeChosen)
|
|
record = &approve
|
|
p, err := h.OnDecided(event)
|
|
if err != nil || p.Steps[2].Outcome != seat.StepResultOutcomePassed || p.Outcome != seat.PipelineOutcomePassed || p.EndCount != 1 {
|
|
t.Fatalf("approved: %+v (%v)", p, err)
|
|
}
|
|
if !strings.HasPrefix((*said)[len(*said)-1], "pipeline-ended.main.5") {
|
|
t.Errorf("said %v", *said)
|
|
}
|
|
// A pipeline that ended takes no second decision.
|
|
record = &decline
|
|
if p, err := h.OnDecided(event); err != nil || p.Steps[2].Outcome != seat.StepResultOutcomePassed {
|
|
t.Errorf("a second warrant changed it: %+v (%v)", p.Steps[2], err)
|
|
}
|
|
}
|
|
|
|
// A decline, an expiry or a replacement ends the approval step declined or superseded, and a failed required step leaves it
|
|
// not asked with the pipeline failed (§26, §37).
|
|
func TestApprovalEnds(t *testing.T) {
|
|
for name, c := range map[string]struct {
|
|
outcome, option, want string
|
|
}{
|
|
"declined": {oc.WarrantOutcomeChosen, OptionDecline, seat.StepResultOutcomeDeclined},
|
|
"expired": {oc.WarrantOutcomeExpired, "", seat.StepResultOutcomeDeclined},
|
|
"refused": {oc.WarrantOutcomeRefused, "", seat.StepResultOutcomeDeclined},
|
|
"superseded": {oc.WarrantOutcomeReplaced, "", seat.StepResultOutcomeSuperseded},
|
|
} {
|
|
h, _, _, asker, _, _ := fixture()
|
|
for _, s := range []StepEnded{ended("a1", "lint", "passed"), ended("a2", "unit", "passed")} {
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
a := asker.asked[0]
|
|
rec := oc.Warrant{Asker: h.Name, Ask: a.ID, About: a.About, Outcome: c.outcome, Option: c.option, Level: operatorchannelclient.Approve,
|
|
AskDigest: operatorchannelclient.Digest(a), At: operatorchannelclient.FormatTime(time.Date(2026, 11, 11, 13, 0, 0, 0, time.UTC)),
|
|
By: &oc.Person{Who: operatorchannelclient.Operator, Identity: "op", Kind: "telegram", Verified: "linked"}}
|
|
h.Where = func(string) (string, *oc.Warrant, error) { return c.outcome, &rec, nil }
|
|
p, err := h.OnDecided(oc.Warrant{Asker: h.Name, Ask: a.ID, About: a.About})
|
|
if err != nil || p.Steps[2].Outcome != c.want || p.Outcome != seat.PipelineOutcomeFailed {
|
|
t.Errorf("%s: step %q, pipeline %q (%v)", name, p.Steps[2].Outcome, p.Outcome, err)
|
|
}
|
|
}
|
|
h, store, _, asker, _, _ := fixture()
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ended("a1", "lint", "failed")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ended("a2", "unit", "passed")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p := store[pkey].p
|
|
if len(asker.asked) != 0 || p.Steps[2].Outcome != seat.StepResultOutcomeNotAsked || p.Outcome != seat.PipelineOutcomeFailed || !strings.Contains(p.Why, "lint") {
|
|
t.Errorf("asked %d; %+v", len(asker.asked), p)
|
|
}
|
|
}
|
|
|
|
// An optional step still waiting (a code review nobody has given) does not hold a pipeline's end; a required one does
|
|
// (design 47 G A-104). A mover with no step placed, waiting on its registration (A-327) or on the publish of a mover it
|
|
// builds on (§746), holds the end while every placed mover's required steps passed or one is open, and once a placed one
|
|
// did not pass the pipeline ends failed, naming each with its own reason (H-A-163, H-A-171).
|
|
func TestAnOptionalStepStillWaitingHoldsNoEnd(t *testing.T) {
|
|
now := time.Date(2026, 11, 11, 12, 0, 0, 0, time.UTC)
|
|
// lib is registered and awaits core's package, which core's passed build has not published yet; contracts has no
|
|
// registration.
|
|
starter := &Starter{Registration: func(m string) (catalog.Registration, bool) { return catalog.Registration{Module: m}, m != "contracts" }}
|
|
view := func(string) (Half, bool) {
|
|
return Half{Entries: map[string]catalog.CatalogEntry{"lib": {Edges: []catalog.Edge{{From: "core:go", To: "lib:program", Kind: 1}}}}}, true
|
|
}
|
|
unplaced := func(p seat.Pipeline, m string) string { return starter.Unplaced(p, m, view) }
|
|
for name, c := range map[string]struct {
|
|
review, build, unit string
|
|
waiting []string
|
|
ends bool
|
|
outcome string
|
|
why []string
|
|
}{
|
|
"optional review waiting": {seat.StepResultStatusOptional, seat.StepResultOutcomePassed, seat.StepResultOutcomePassed, nil, true, seat.PipelineOutcomePassed, nil},
|
|
"required review waiting": {seat.StepResultStatusRequired, seat.StepResultOutcomePassed, seat.StepResultOutcomePassed, nil, false, "", nil},
|
|
"unregistered mover, the placed one passed": {seat.StepResultStatusOptional, seat.StepResultOutcomePassed, seat.StepResultOutcomePassed, []string{"contracts"}, false, "", nil},
|
|
"unregistered mover, the placed one failed": {seat.StepResultStatusOptional, seat.StepResultOutcomeFailed, seat.StepResultOutcomePassed, []string{"contracts"}, true, seat.PipelineOutcomeFailed, []string{"contracts has no registration"}},
|
|
"unregistered mover, failed and a step open": {seat.StepResultStatusOptional, seat.StepResultOutcomeFailed, seat.StepResultOutcomeRunning, []string{"contracts"}, false, "", nil},
|
|
"unregistered mover, the placed one could not run": {seat.StepResultStatusOptional, seat.StepResultOutcomePassed, seat.StepResultOutcomeCouldNotRun, []string{"contracts"}, true, seat.PipelineOutcomeFailed, []string{"contracts has no registration"}},
|
|
"a mover waiting on a publish, the placed one failed": {seat.StepResultStatusOptional, seat.StepResultOutcomeFailed, seat.StepResultOutcomePassed, []string{"contracts", "lib"}, true, seat.PipelineOutcomeFailed,
|
|
[]string{"contracts has no registration", "lib waits on the publish of core:go"}},
|
|
} {
|
|
p := seat.Pipeline{Outcome: seat.PipelineOutcomeRunning, Movers: []seat.Mover{{Module: "app"}, {Module: "core"}}, Steps: []seat.StepResult{
|
|
{Step: seat.StepResultStepBuild, Module: "app", Status: seat.StepResultStatusRequired, Outcome: c.build},
|
|
{Step: seat.StepResultStepUnit, Module: "app", Status: seat.StepResultStatusRequired, Outcome: c.unit},
|
|
{Step: seat.StepResultStepReview, Module: "app", Status: c.review, Outcome: seat.StepResultOutcomeWaiting},
|
|
{Step: seat.StepResultStepApproval, Module: "app", Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomePassed},
|
|
{Step: seat.StepResultStepBuild, Module: "core", Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomePassed},
|
|
}}
|
|
for _, m := range c.waiting {
|
|
p.Movers = append(p.Movers, seat.Mover{Module: m})
|
|
}
|
|
if got := endPipeline(&p, now, unplaced); got != c.ends {
|
|
t.Errorf("%s: ended = %v, want %v", name, got, c.ends)
|
|
}
|
|
if c.ends && p.Outcome != c.outcome {
|
|
t.Errorf("%s: outcome %s, want %s", name, p.Outcome, c.outcome)
|
|
}
|
|
for _, w := range c.why {
|
|
if !strings.Contains(p.Why, w) {
|
|
t.Errorf("%s: why %q, want it to name %q", name, p.Why, w)
|
|
}
|
|
}
|
|
if strings.Contains(p.Why, "lib has no registration") {
|
|
t.Errorf("%s: why %q names a registered mover as having no registration", name, p.Why)
|
|
}
|
|
}
|
|
}
|
|
|
|
type askerFunc func(accept, id string, body any) error
|
|
|
|
func (f askerFunc) AskStep(accept, id string, body any) error { return f(accept, id, body) }
|
|
|
|
// A recovery's steps are asked on the build seats' stream delivery, ahead of the first round; the seats with no such stream keep
|
|
// their own accept subject; every other commit's steps go on check (design 47 G §86, §415).
|
|
func TestARecoverysStepsAreAskedOnTheStreamDelivery(t *testing.T) {
|
|
asks := []Asked{{Seat: nodebuildgo.Seat, ID: "s1", Ask: 1}, {Seat: wants.Seat, ID: "s2", Ask: 2}}
|
|
for _, c := range []struct {
|
|
recovery bool
|
|
want string
|
|
}{{true, "mesh.seat.node-build-go.accept.delivery.mesh-pipeline-runner," + wants.AcceptSubjectStep}, {false, "mesh.seat.node-build-go.accept.check.mesh-pipeline-runner," + wants.AcceptSubjectStep}} {
|
|
var to []string
|
|
asker := askerFunc(func(accept, _ string, _ any) error { to = append(to, accept); return nil })
|
|
if err := askAll(asker, "k", asks, func(string) bool { return c.recovery }); err != nil || strings.Join(to, ",") != c.want {
|
|
t.Errorf("recovery %v: asked on %v (%v), want %s", c.recovery, to, err, c.want)
|
|
}
|
|
}
|
|
// Starter.recovered reads the commit; a failed read asks on check and says so.
|
|
var said []string
|
|
s := &Starter{Logf: func(f string, a ...any) { said = append(said, f) }, Recovered: func(c string) (bool, error) {
|
|
if c == "bad" {
|
|
return false, errors.New("unread")
|
|
}
|
|
return c == "rec", nil
|
|
}}
|
|
if !s.recovered("k", "rec") || s.recovered("k", "other") || s.recovered("k", "bad") || len(said) != 1 {
|
|
t.Errorf("recovered: said %v", said)
|
|
}
|
|
}
|