Merge pull request 'selfcompose: one compose pass at a time, and tests that wait on sync points, not wall time (issue 721)' (#257) from fix/selfcompose-race into main
This commit was merged in pull request #257.
This commit is contained in:
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
// Issue 1965 (shanks 2026-11-05 22:27: the verb compose gave no answer in 30 s while a pass waited on the bus): an ask
|
||||
// that comes while a pass runs is answered at once, says one more pass is queued and what the running one waits on, and
|
||||
// the queued pass is made when the running one ends.
|
||||
// the queued pass is made when the running one ends. A pass made by hand meanwhile is made after the running one too.
|
||||
func composeAnsweredWhileAPassRuns(t *testing.T) {
|
||||
b := newFakeBus()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -30,7 +30,10 @@ func composeAnsweredWhileAPassRuns(t *testing.T) {
|
||||
reached := make(chan struct{}, 8)
|
||||
env.Running = func() []compositions.Composed {
|
||||
passes.Add(1)
|
||||
reached <- struct{}{}
|
||||
select {
|
||||
case reached <- struct{}{}:
|
||||
default: // a pass reads what runs more than once: past eight reads unheard, a read is told to nobody and never waits
|
||||
}
|
||||
if passes.Load() == 1 {
|
||||
<-hold // the first pass waits on the bus
|
||||
}
|
||||
@@ -72,12 +75,28 @@ func composeAnsweredWhileAPassRuns(t *testing.T) {
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("the verb compose gave no answer while a pass ran")
|
||||
}
|
||||
// 721/AC2: a pass made by hand while the loop's runs does not begin until that pass ends. While the loop's pass is held,
|
||||
// the lock of a whole pass is taken (no second pass can begin), and the pass made by hand ends once the held one did.
|
||||
byHand := make(chan struct{})
|
||||
go func() {
|
||||
defer close(byHand)
|
||||
c.compose(ctx)
|
||||
}()
|
||||
if c.passMu.TryLock() {
|
||||
c.passMu.Unlock()
|
||||
t.Error("the loop's pass runs without the lock of a whole pass: a pass made by hand would begin beside it")
|
||||
}
|
||||
close(hold)
|
||||
select {
|
||||
case <-reached: // the queued pass
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the queued pass was not made when the running one ended")
|
||||
}
|
||||
select {
|
||||
case <-byHand:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the pass made by hand was not made when the running one ended")
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-480: the composer's watch ends with the agent's stop: once its ctx ended, Wait returns only after its loop ended,
|
||||
|
||||
@@ -309,6 +309,10 @@ type Composer struct {
|
||||
asked chan chan Pass
|
||||
// passing is set while a pass is made.
|
||||
passing atomic.Bool
|
||||
// passMu is held for the whole of a pass (compose, composeEarly): a second pass over this composer's state waits for
|
||||
// the one running to end, never runs beside it (issue 721 note 11: a pass beside the loop's handed again what the
|
||||
// other had taken back).
|
||||
passMu sync.Mutex
|
||||
// early is true while the early pass of a start runs (design 47 G §683, A-117).
|
||||
early atomic.Bool
|
||||
// assignmentsRead is set once the watch of the seat's assignments has caught up: from then the placements this composer holds
|
||||
@@ -1089,8 +1093,16 @@ func (c *Composer) takeValue(u agent.Update) {
|
||||
}
|
||||
|
||||
// compose composes the node once and answers the updates to hand: each composition whose digest differs from the one
|
||||
// handed, and a deletion for each handed one no want names any more.
|
||||
// handed, and a deletion for each handed one no want names any more. It holds passMu for the whole pass, so a pass asked
|
||||
// while another runs is made after it.
|
||||
func (c *Composer) compose(ctx context.Context) []agent.Update {
|
||||
c.passMu.Lock()
|
||||
defer c.passMu.Unlock()
|
||||
return c.composePass(ctx)
|
||||
}
|
||||
|
||||
// composePass is compose's pass, made with passMu held.
|
||||
func (c *Composer) composePass(ctx context.Context) []agent.Update {
|
||||
early := c.early.Load()
|
||||
pass := Pass{}
|
||||
defer func() {
|
||||
@@ -2645,8 +2657,11 @@ func (c *Composer) standing() bool {
|
||||
|
||||
// composeEarly is the pass of a start before the assignments, haves and resolved values are read: it composes only the modules whose
|
||||
// kept want and kept entry it holds, a kept want standing for their placement, and leaves every other module as it runs; the full
|
||||
// pass follows once the inputs are read (design 47 G §683, A-95, A-117).
|
||||
// pass follows once the inputs are read (design 47 G §683, A-95, A-117). The placement it stands in for the assignments, and
|
||||
// its taking back, are within the pass: passMu is held for all of it.
|
||||
func (c *Composer) composeEarly(ctx context.Context) []agent.Update {
|
||||
c.passMu.Lock()
|
||||
defer c.passMu.Unlock()
|
||||
node := c.env.Node
|
||||
c.mu.Lock()
|
||||
_, hadRecord := c.records[node]
|
||||
@@ -2684,5 +2699,5 @@ func (c *Composer) composeEarly(ctx context.Context) []agent.Update {
|
||||
}
|
||||
}()
|
||||
c.env.Say("the node composes the modules it kept a want and an entry of, before its other inputs are read")
|
||||
return c.compose(ctx)
|
||||
return c.composePass(ctx)
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"testing/synctest"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-networking/modules/mesh-connectivity-contracts/go/seats/nodepacketfilter"
|
||||
@@ -393,17 +394,21 @@ func testTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
// Issue 1966 (novox, 2026-11-09): every pass names each wanted module it composed nothing of, or composed from the indexer's
|
||||
// manifest for want of a done build, with why, and a want it did not take; said once; the agent's word that it waits
|
||||
// hands a composition the node believes handed again.
|
||||
// 721/AC2: the passes of this step are made by hand on a copy of what c holds, which runs no loop: beside c's loop, a pass
|
||||
// it makes when an entry is answered composed tool too, and handed it on out (pipelines main.266, main.459, main.479).
|
||||
sc := c.scratch()
|
||||
sc.env.Running = nil // composed counts c's passes alone
|
||||
tfp := toolFp
|
||||
c.holdEntry(t, "tool", tfp, toolBody)
|
||||
sc.holdEntry(t, "tool", tfp, toolBody)
|
||||
for module, w := range map[string]meshwants.WantsByWantNodeModuleValue{"tool": {Fp: tfp, Self: true}, "ghost": {Fp: ghostFp, Self: true}, "nofp": {Self: true}} {
|
||||
raw, _ := bucketstest.Want(w)
|
||||
c.takeWant(agent.Update{Key: "want.n1." + module, Value: raw})
|
||||
sc.takeWant(agent.Update{Key: "want.n1." + module, Value: raw})
|
||||
}
|
||||
c.mu.Lock()
|
||||
placed := c.assignments["n1"]
|
||||
sc.mu.Lock()
|
||||
placed := sc.assignments["n1"]
|
||||
placed.Modules = append(slices.Clone(placed.Modules), meshmoduleassigner.PlacedModule{Module: "tool"})
|
||||
c.assignments["n1"] = placed
|
||||
c.mu.Unlock()
|
||||
sc.assignments["n1"] = placed
|
||||
sc.mu.Unlock()
|
||||
said := func(sub string) (n int) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
@@ -414,27 +419,18 @@ func testTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
}
|
||||
return n
|
||||
}
|
||||
c.compose(ctx)
|
||||
sc.compose(ctx)
|
||||
saidOfNofp := said("the node composes nothing of nofp")
|
||||
why := map[string]string{"tool": c.LastHeld()["tool"], "ghost": c.LastHeld()["ghost"], "nofp": c.WhyUnmade("nofp"), "lemurs": c.WhyUnmade("lemurs")}
|
||||
why := map[string]string{"tool": sc.LastHeld()["tool"], "ghost": sc.LastHeld()["ghost"], "nofp": sc.WhyUnmade("nofp"), "lemurs": sc.WhyUnmade("lemurs")}
|
||||
if !strings.Contains(why["tool"], "tool at "+tfp) || !strings.Contains(why["ghost"], "entry-asked: the entry of the build "+ghostFp) ||
|
||||
!strings.Contains(why["nofp"], "want not taken: its want names no fingerprint") || why["lemurs"] != "" {
|
||||
t.Errorf("the pass says it composed nothing of %q", why)
|
||||
}
|
||||
readGhost()
|
||||
c.compose(ctx)
|
||||
sc.compose(ctx)
|
||||
if n := said("the node composes nothing of nofp"); n != saidOfNofp || n == 0 {
|
||||
t.Errorf("the journal says why nofp is not composed %d times after the second pass, %d after the first: want the same, not none", n, saidOfNofp)
|
||||
}
|
||||
// The state of this step is taken away again, and the pass that takes back what it handed is made here.
|
||||
for _, module := range []string{"tool", "ghost", "nofp"} {
|
||||
c.takeWant(agent.Update{Key: "want.n1." + module, Deleted: true})
|
||||
}
|
||||
c.mu.Lock()
|
||||
placed.Modules = placed.Modules[:len(placed.Modules)-1]
|
||||
c.assignments["n1"] = placed
|
||||
c.mu.Unlock()
|
||||
c.compose(ctx)
|
||||
// The agent waits for what the node believes it handed: handed again; for what it never handed, nothing is.
|
||||
c.Waiting("ghost", fp)
|
||||
select {
|
||||
@@ -1208,285 +1204,293 @@ func testTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
readOnly.kv[composedBucket+"/"+key] = raw
|
||||
readOnly.mu.Unlock()
|
||||
}
|
||||
answered := make(chan map[string]nodeengine.CandidateAnswer, 8)
|
||||
sh := NewShadow(senv, func(_ context.Context, a map[string]nodeengine.CandidateAnswer) { answered <- a })
|
||||
sctx, scancel := context.WithCancel(ctx)
|
||||
defer scancel()
|
||||
// Review of L2b, round 1, finding 2: the candidates' state is not there when the node starts (a delivery before the
|
||||
// indexer made it): the shadow tries again, and answers once it appears.
|
||||
sb.missing(buckets.ProposalCandidates, true)
|
||||
kept := make(chan struct{})
|
||||
go func() { sh.Keep(sctx, func(int) time.Duration { return 5 * time.Millisecond }); close(kept) }()
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
sb.missing(buckets.ProposalCandidates, false)
|
||||
sb.made(6)
|
||||
// What the shadow and the steps after it are given.
|
||||
rec, _ := nodeengineclient.EncodeHaveNode(nodeengine.HaveByNodeNodeValue{Record: &nodeengine.NodeRecord{Node: "n1", TunnelKey: "k", SealingKey: "sk", Capabilities: []string{"systemd"}}})
|
||||
tp := assignedValues(t, trunk)
|
||||
sb.putAssigned(tp, 1)
|
||||
sb.put(buckets.Have, "n1.node", rec, 1)
|
||||
wantLemurs := meshwants.WantsByWantNodeModuleKey("n1", "lemurs")
|
||||
var lemursDigest string
|
||||
for _, c := range running {
|
||||
if c.Module == "lemurs" {
|
||||
lemursDigest, _ = compositions.DigestOf(c)
|
||||
}
|
||||
}
|
||||
wantRaw, err := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{Fp: fp})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sb.put(buckets.Wants, wantLemurs, wantRaw, 1)
|
||||
wantNode := meshwants.WantsByWantNodeNodeKey("n1")
|
||||
nodeRaw, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{})
|
||||
sb.put(buckets.Wants, wantNode, nodeRaw, 1)
|
||||
candidate := func(group string, rev uint64, modules ...string) {
|
||||
p := trunk
|
||||
p.Modules = nil
|
||||
for _, m := range modules {
|
||||
p.Modules = append(p.Modules, meshmoduleassigner.PlacedModule{Module: m})
|
||||
}
|
||||
raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: group, Assignments: &p})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey(group, "n1")
|
||||
sb.put(buckets.ProposalCandidates, k, raw, rev)
|
||||
}
|
||||
candidate("same", 3, "lemurs")
|
||||
candidate("adds", 4, "lemurs", "keeper")
|
||||
candidate("drops", 5)
|
||||
candidate("ghost", 6, "lemurs", "ghost")
|
||||
candidate("nofp", 11, "lemurs", "nofp")
|
||||
// A module with an artifact: held when the candidate gives no part for it, built from its entry and the parts when it does.
|
||||
for group, added := range map[string]map[string]meshmoduleassigner.AddedModule{
|
||||
"art-without": nil,
|
||||
"art-with": {"art": {Version: "1"}},
|
||||
} {
|
||||
p := trunk
|
||||
p.Modules = []meshmoduleassigner.PlacedModule{{Module: "lemurs"}, {Module: "art"}}
|
||||
raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: group, Assignments: &p, Added: added})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sb.put(buckets.ProposalCandidates, meshmoduleassigner.CandidatesByProposalNodeKey(group, "n1"), raw, 10)
|
||||
}
|
||||
// A head deleting n1's assignment file (the seed's revert, mesh-catalog #526): n1 returns to the controller's
|
||||
// compositions, answered as such, not as every module removed.
|
||||
if raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: "deletes"}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey("deletes", "n1")
|
||||
sb.put(buckets.ProposalCandidates, k, raw, 7)
|
||||
}
|
||||
// A proposal that changes another node's key and reaches n1's composition (ADR 0567 §3): n1's candidate holds no
|
||||
// assignment of its own change (Reached, nil), and n1 answers against its current assignment, never as one whose key
|
||||
// the proposal takes away.
|
||||
if raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: "reach", Reached: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey("reach", "n1")
|
||||
sb.put(buckets.ProposalCandidates, k, raw, 8)
|
||||
}
|
||||
sb.caught()
|
||||
var answers map[string]nodeengine.CandidateAnswer
|
||||
waitFor := func(why string, ok func(map[string]nodeengine.CandidateAnswer) bool) {
|
||||
t.Helper()
|
||||
deadline := time.After(10 * time.Second)
|
||||
for answers == nil || !ok(answers) {
|
||||
select {
|
||||
case answers = <-answered:
|
||||
case <-deadline:
|
||||
t.Fatalf("%s: last answers %+v", why, answers)
|
||||
// 721/AC2, the kind (issue 721 note 15: a test that waits a fixed quiet window): the shadow runs in a bubble of its own
|
||||
// (testing/synctest), so each wait below for it to answer nothing more, or to try again, ends once every goroutine of the
|
||||
// bubble is idle and its clock has passed the wait, never after a stretch of wall time on a loaded build node.
|
||||
synctest.Test(t, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
answered := make(chan map[string]nodeengine.CandidateAnswer, 8)
|
||||
sh := NewShadow(senv, func(_ context.Context, a map[string]nodeengine.CandidateAnswer) { answered <- a })
|
||||
sctx, scancel := context.WithCancel(ctx)
|
||||
defer scancel()
|
||||
// Review of L2b, round 1, finding 2: the candidates' state is not there when the node starts (a delivery before the
|
||||
// indexer made it): the shadow tries again, and answers once it appears.
|
||||
sb.missing(buckets.ProposalCandidates, true)
|
||||
kept := make(chan struct{})
|
||||
go func() { sh.Keep(sctx, func(int) time.Duration { return 5 * time.Millisecond }); close(kept) }()
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
sb.missing(buckets.ProposalCandidates, false)
|
||||
sb.made(6)
|
||||
sb.putAssigned(tp, 1)
|
||||
sb.put(buckets.Have, "n1.node", rec, 1)
|
||||
var lemursDigest string
|
||||
for _, c := range running {
|
||||
if c.Module == "lemurs" {
|
||||
lemursDigest, _ = compositions.DigestOf(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
waitFor("every group answered", func(a map[string]nodeengine.CandidateAnswer) bool { return len(a) == 6 })
|
||||
// keeper, which the candidate adds and no want names, is asked of the catalog half (its entry by the verb entry after the verb
|
||||
// module): the answer waits for it, and is the same as before the shadow watched no modules once it comes (A-312).
|
||||
waitFor("the added module's entry answered", func(a map[string]nodeengine.CandidateAnswer) bool { return len(a["adds"].Added) == 1 })
|
||||
// Every watch and get the shadow makes is one the node's grant allows (issue 1126, 2026-10-27 09:21).
|
||||
sb.mu.Lock()
|
||||
for _, w := range sb.watches {
|
||||
if !grantAllows(t, "n1", w.bucket, w.pattern) {
|
||||
t.Errorf("the shadow watches %s of %s, which the node's grant does not allow", w.pattern, w.bucket)
|
||||
sb.put(buckets.Wants, wantLemurs, wantRaw, 1)
|
||||
wantNode := meshwants.WantsByWantNodeNodeKey("n1")
|
||||
nodeRaw, _ := bucketstest.Want(meshwants.WantsByWantNodeModuleValue{})
|
||||
sb.put(buckets.Wants, wantNode, nodeRaw, 1)
|
||||
candidate := func(group string, rev uint64, modules ...string) {
|
||||
p := trunk
|
||||
p.Modules = nil
|
||||
for _, m := range modules {
|
||||
p.Modules = append(p.Modules, meshmoduleassigner.PlacedModule{Module: m})
|
||||
}
|
||||
raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: group, Assignments: &p})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey(group, "n1")
|
||||
sb.put(buckets.ProposalCandidates, k, raw, rev)
|
||||
}
|
||||
if w.bucket == buckets.Modules {
|
||||
t.Errorf("the shadow watches the indexer's modules (%s), which design 47 G A-308 ends", w.pattern)
|
||||
candidate("same", 3, "lemurs")
|
||||
candidate("adds", 4, "lemurs", "keeper")
|
||||
candidate("drops", 5)
|
||||
candidate("ghost", 6, "lemurs", "ghost")
|
||||
candidate("nofp", 11, "lemurs", "nofp")
|
||||
// A module with an artifact: held when the candidate gives no part for it, built from its entry and the parts when it does.
|
||||
for group, added := range map[string]map[string]meshmoduleassigner.AddedModule{
|
||||
"art-without": nil,
|
||||
"art-with": {"art": {Version: "1"}},
|
||||
} {
|
||||
p := trunk
|
||||
p.Modules = []meshmoduleassigner.PlacedModule{{Module: "lemurs"}, {Module: "art"}}
|
||||
raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: group, Assignments: &p, Added: added})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sb.put(buckets.ProposalCandidates, meshmoduleassigner.CandidatesByProposalNodeKey(group, "n1"), raw, 10)
|
||||
}
|
||||
}
|
||||
sb.mu.Unlock()
|
||||
readOnly.mu.Lock()
|
||||
for _, r := range readOnly.reads {
|
||||
if !grantAllows(t, "n1", r[0], r[1]) {
|
||||
t.Errorf("the shadow reads %s of %s, which the node's grant does not allow", r[1], r[0])
|
||||
// A head deleting n1's assignment file (the seed's revert, mesh-catalog #526): n1 returns to the controller's
|
||||
// compositions, answered as such, not as every module removed.
|
||||
if raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: "deletes"}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey("deletes", "n1")
|
||||
sb.put(buckets.ProposalCandidates, k, raw, 7)
|
||||
}
|
||||
}
|
||||
readOnly.mu.Unlock()
|
||||
groups := map[string]func(nodeengine.CandidateAnswer) bool{
|
||||
"same": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictSame && a.Proposal == "same" && a.Revision == 3 && len(a.Same) == 2
|
||||
},
|
||||
"adds": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictDiffers && len(a.Added) == 1 && a.Added[0].Module == "keeper" &&
|
||||
len(a.Added[0].Unissued) == 1 && len(a.Refusals) == 0
|
||||
},
|
||||
"art-without": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictSame && len(a.Held) == 1 && a.Held[0].Module == "art" &&
|
||||
strings.Contains(a.Held[0].Why, "the candidate's version resolves no digest of art:files of art's build "+artFp)
|
||||
},
|
||||
"art-with": func(a nodeengine.CandidateAnswer) bool {
|
||||
return len(a.Added) == 1 && a.Added[0].Module == "art" && len(a.Held) == 0
|
||||
},
|
||||
"drops": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictDiffers && len(a.Removed) == 1 && a.Removed[0] == "lemurs"
|
||||
},
|
||||
// A module the verb module answers an error for, or no fingerprint, is held with the verb's reason (A-312), the rest composed.
|
||||
"ghost": func(a nodeengine.CandidateAnswer) bool {
|
||||
return len(a.Held) == 1 && a.Held[0].Module == "ghost" && strings.Contains(a.Held[0].Why, "the catalog holds no module ghost") && a.Refused == ""
|
||||
},
|
||||
"nofp": func(a nodeengine.CandidateAnswer) bool {
|
||||
return len(a.Held) == 1 && a.Held[0].Module == "nofp" && strings.Contains(a.Held[0].Why, "gives nofp no fingerprint: its build is not made yet")
|
||||
},
|
||||
"reach": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictSame && a.Returns == "" && a.Revision == 8 && len(a.Removed) == 0 &&
|
||||
fmt.Sprint(a.Same) == "[lemurs node]"
|
||||
},
|
||||
// Issue 1126, A7: a candidate deleting the node's assignment is refused, never answered as a return to the
|
||||
// controller's compositions: no composition made elsewhere is applied, so the node would compose nothing.
|
||||
"deletes": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictRefused && a.Returns == "" && a.Revision == 7 &&
|
||||
strings.Contains(a.Refused, "composes nothing")
|
||||
},
|
||||
}
|
||||
// Answered as each group should be: the shadow answers again while what it reads comes in (what runs, an entry), so an
|
||||
// answer before the last may still hold lemurs as it runs; the test waits for the answer that settles every group
|
||||
// (fix-a-bug-met-twice: asserting on whichever answer came first flaked, and the settled one then read as "handed
|
||||
// again for nothing changed").
|
||||
waitFor("every group answered as it should be", func(a map[string]nodeengine.CandidateAnswer) bool {
|
||||
for group, want := range groups {
|
||||
if !want(a[group]) {
|
||||
return false
|
||||
// A proposal that changes another node's key and reaches n1's composition (ADR 0567 §3): n1's candidate holds no
|
||||
// assignment of its own change (Reached, nil), and n1 answers against its current assignment, never as one whose key
|
||||
// the proposal takes away.
|
||||
if raw, err := bucketstest.Candidate(meshmoduleassigner.CandidatesByProposalNodeValue{Proposal: "reach", Reached: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey("reach", "n1")
|
||||
sb.put(buckets.ProposalCandidates, k, raw, 8)
|
||||
}
|
||||
sb.caught()
|
||||
var answers map[string]nodeengine.CandidateAnswer
|
||||
waitFor := func(why string, ok func(map[string]nodeengine.CandidateAnswer) bool) {
|
||||
t.Helper()
|
||||
deadline := time.After(10 * time.Second)
|
||||
for answers == nil || !ok(answers) {
|
||||
select {
|
||||
case answers = <-answered:
|
||||
case <-deadline:
|
||||
t.Fatalf("%s: last answers %+v", why, answers)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
// The node's own key changing (its answers written) composes nothing again; a group's key deleted drops its answer.
|
||||
sb.put(buckets.Have, "n1.node", rec, 2)
|
||||
select {
|
||||
case a := <-answered:
|
||||
t.Errorf("answers handed again for nothing changed: %+v", a)
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
// Issue 1126, 2026-10-28 (shanks answered probe/1126-seed-7 at revision 84 every 13-17 s): a candidate revision is
|
||||
// answered once. A module's have whose health or words alone move (each look rewrites them), and a assignment, a
|
||||
// module or a config value written again with the value it held, answer nothing again; a new revision answers its
|
||||
// group alone, and what runs moving answers every group once.
|
||||
answering := func() int {
|
||||
waitFor("every group answered", func(a map[string]nodeengine.CandidateAnswer) bool { return len(a) == 6 })
|
||||
// keeper, which the candidate adds and no want names, is asked of the catalog half (its entry by the verb entry after the verb
|
||||
// module): the answer waits for it, and is the same as before the shadow watched no modules once it comes (A-312).
|
||||
waitFor("the added module's entry answered", func(a map[string]nodeengine.CandidateAnswer) bool { return len(a["adds"].Added) == 1 })
|
||||
// Every watch and get the shadow makes is one the node's grant allows (issue 1126, 2026-10-27 09:21).
|
||||
sb.mu.Lock()
|
||||
for _, w := range sb.watches {
|
||||
if !grantAllows(t, "n1", w.bucket, w.pattern) {
|
||||
t.Errorf("the shadow watches %s of %s, which the node's grant does not allow", w.pattern, w.bucket)
|
||||
}
|
||||
if w.bucket == buckets.Modules {
|
||||
t.Errorf("the shadow watches the indexer's modules (%s), which design 47 G A-308 ends", w.pattern)
|
||||
}
|
||||
}
|
||||
sb.mu.Unlock()
|
||||
readOnly.mu.Lock()
|
||||
defer readOnly.mu.Unlock()
|
||||
n := 0
|
||||
for _, l := range readOnly.said {
|
||||
if strings.HasPrefix(l, "answering assignment candidate ") {
|
||||
n++
|
||||
for _, r := range readOnly.reads {
|
||||
if !grantAllows(t, "n1", r[0], r[1]) {
|
||||
t.Errorf("the shadow reads %s of %s, which the node's grant does not allow", r[1], r[0])
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
drain := func() {
|
||||
for {
|
||||
select {
|
||||
case answers = <-answered:
|
||||
case <-time.After(150 * time.Millisecond):
|
||||
return
|
||||
readOnly.mu.Unlock()
|
||||
groups := map[string]func(nodeengine.CandidateAnswer) bool{
|
||||
"same": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictSame && a.Proposal == "same" && a.Revision == 3 && len(a.Same) == 2
|
||||
},
|
||||
"adds": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictDiffers && len(a.Added) == 1 && a.Added[0].Module == "keeper" &&
|
||||
len(a.Added[0].Unissued) == 1 && len(a.Refusals) == 0
|
||||
},
|
||||
"art-without": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictSame && len(a.Held) == 1 && a.Held[0].Module == "art" &&
|
||||
strings.Contains(a.Held[0].Why, "the candidate's version resolves no digest of art:files of art's build "+artFp)
|
||||
},
|
||||
"art-with": func(a nodeengine.CandidateAnswer) bool {
|
||||
return len(a.Added) == 1 && a.Added[0].Module == "art" && len(a.Held) == 0
|
||||
},
|
||||
"drops": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictDiffers && len(a.Removed) == 1 && a.Removed[0] == "lemurs"
|
||||
},
|
||||
// A module the verb module answers an error for, or no fingerprint, is held with the verb's reason (A-312), the rest composed.
|
||||
"ghost": func(a nodeengine.CandidateAnswer) bool {
|
||||
return len(a.Held) == 1 && a.Held[0].Module == "ghost" && strings.Contains(a.Held[0].Why, "the catalog holds no module ghost") && a.Refused == ""
|
||||
},
|
||||
"nofp": func(a nodeengine.CandidateAnswer) bool {
|
||||
return len(a.Held) == 1 && a.Held[0].Module == "nofp" && strings.Contains(a.Held[0].Why, "gives nofp no fingerprint: its build is not made yet")
|
||||
},
|
||||
"reach": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictSame && a.Returns == "" && a.Revision == 8 && len(a.Removed) == 0 &&
|
||||
fmt.Sprint(a.Same) == "[lemurs node]"
|
||||
},
|
||||
// Issue 1126, A7: a candidate deleting the node's assignment is refused, never answered as a return to the
|
||||
// controller's compositions: no composition made elsewhere is applied, so the node would compose nothing.
|
||||
"deletes": func(a nodeengine.CandidateAnswer) bool {
|
||||
return a.Verdict == nodeengine.CandidateAnswerVerdictRefused && a.Returns == "" && a.Revision == 7 &&
|
||||
strings.Contains(a.Refused, "composes nothing")
|
||||
},
|
||||
}
|
||||
// Answered as each group should be: the shadow answers again while what it reads comes in (what runs, an entry), so an
|
||||
// answer before the last may still hold lemurs as it runs; the test waits for the answer that settles every group
|
||||
// (fix-a-bug-met-twice: asserting on whichever answer came first flaked, and the settled one then read as "handed
|
||||
// again for nothing changed").
|
||||
waitFor("every group answered as it should be", func(a map[string]nodeengine.CandidateAnswer) bool {
|
||||
for group, want := range groups {
|
||||
if !want(a[group]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
// The node's own key changing (its answers written) composes nothing again; a group's key deleted drops its answer.
|
||||
sb.put(buckets.Have, "n1.node", rec, 2)
|
||||
select {
|
||||
case a := <-answered:
|
||||
t.Errorf("answers handed again for nothing changed: %+v", a)
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
// Issue 1126, 2026-10-28 (shanks answered probe/1126-seed-7 at revision 84 every 13-17 s): a candidate revision is
|
||||
// answered once. A module's have whose health or words alone move (each look rewrites them), and a assignment, a
|
||||
// module or a config value written again with the value it held, answer nothing again; a new revision answers its
|
||||
// group alone, and what runs moving answers every group once.
|
||||
answering := func() int {
|
||||
readOnly.mu.Lock()
|
||||
defer readOnly.mu.Unlock()
|
||||
n := 0
|
||||
for _, l := range readOnly.said {
|
||||
if strings.HasPrefix(l, "answering assignment candidate ") {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
drain := func() {
|
||||
for {
|
||||
select {
|
||||
case answers = <-answered:
|
||||
case <-time.After(150 * time.Millisecond):
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lemursHave := func(detail string, rev uint64) {
|
||||
raw, err := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fp, Composed: lemursDigest, Phase: nodeengineclient.PhaseRunning,
|
||||
Health: nodeengineclient.HealthFailed, Detail: detail})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
lemursHave := func(detail string, rev uint64) {
|
||||
raw, err := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fp, Composed: lemursDigest, Phase: nodeengineclient.PhaseRunning,
|
||||
Health: nodeengineclient.HealthFailed, Detail: detail})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
hk, _ := nodeengineclient.HaveKey("n1", "lemurs")
|
||||
sb.put(buckets.Have, hk, raw, rev)
|
||||
}
|
||||
lemursHave("its tool lemurs_health: no link to the bus is open", 10)
|
||||
drain()
|
||||
settled := answering()
|
||||
lemursHave("its tool lemurs_health: no answer within 10s", 11)
|
||||
lemursHave("its tool lemurs_health: no answer within 20s", 12)
|
||||
sb.putAssigned(tp, 2)
|
||||
sb.put(buckets.Wants, wantLemurs, wantRaw, 2)
|
||||
drain()
|
||||
if got := answering(); got != settled {
|
||||
t.Errorf("answered %d more time(s) with no candidate revision and no input of the node changed", got-settled)
|
||||
}
|
||||
candidate("same", 8, "lemurs")
|
||||
waitFor("the new revision answered", func(a map[string]nodeengine.CandidateAnswer) bool { return a["same"].Revision == 8 })
|
||||
drain()
|
||||
if got := answering(); got != settled+1 {
|
||||
t.Errorf("a new revision of one group answered %d group(s), want 1", got-settled)
|
||||
}
|
||||
// Issue 1126, 2026-10-28 (seed-9's probe): each answer says which input woke it, so a loop is told from inputs moving.
|
||||
lastSaid := func(prefix string) string {
|
||||
readOnly.mu.Lock()
|
||||
defer readOnly.mu.Unlock()
|
||||
for i := len(readOnly.said) - 1; i >= 0; i-- {
|
||||
if strings.HasPrefix(readOnly.said[i], prefix) {
|
||||
return readOnly.said[i]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
if got := lastSaid("answering assignment candidate same "); got != "answering assignment candidate same (revision 8; woken by the candidate)" {
|
||||
t.Errorf("a new revision's answer said %q", got)
|
||||
}
|
||||
settled = answering()
|
||||
hk, _ := nodeengineclient.HaveKey("n1", "lemurs")
|
||||
sb.put(buckets.Have, hk, raw, rev)
|
||||
}
|
||||
lemursHave("its tool lemurs_health: no link to the bus is open", 10)
|
||||
drain()
|
||||
settled := answering()
|
||||
lemursHave("its tool lemurs_health: no answer within 10s", 11)
|
||||
lemursHave("its tool lemurs_health: no answer within 20s", 12)
|
||||
sb.putAssigned(tp, 2)
|
||||
sb.put(buckets.Wants, wantLemurs, wantRaw, 2)
|
||||
drain()
|
||||
if got := answering(); got != settled {
|
||||
t.Errorf("answered %d more time(s) with no candidate revision and no input of the node changed", got-settled)
|
||||
}
|
||||
candidate("same", 8, "lemurs")
|
||||
waitFor("the new revision answered", func(a map[string]nodeengine.CandidateAnswer) bool { return a["same"].Revision == 8 })
|
||||
drain()
|
||||
if got := answering(); got != settled+1 {
|
||||
t.Errorf("a new revision of one group answered %d group(s), want 1", got-settled)
|
||||
}
|
||||
// Issue 1126, 2026-10-28 (seed-9's probe): each answer says which input woke it, so a loop is told from inputs moving.
|
||||
lastSaid := func(prefix string) string {
|
||||
readOnly.mu.Lock()
|
||||
defer readOnly.mu.Unlock()
|
||||
for i := len(readOnly.said) - 1; i >= 0; i-- {
|
||||
if strings.HasPrefix(readOnly.said[i], prefix) {
|
||||
return readOnly.said[i]
|
||||
}
|
||||
moved, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fp, Composed: "sha256:" + strings.Repeat("e", 64), Phase: nodeengineclient.PhaseRunning})
|
||||
sb.put(buckets.Have, hk, moved, 13)
|
||||
drain()
|
||||
if got := answering(); got != settled+len(answers) {
|
||||
t.Errorf("what runs moved, and %d answer(s) were composed again for %d group(s)", got-settled, len(answers))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
if got := lastSaid("answering assignment candidate same "); got != "answering assignment candidate same (revision 8; woken by the candidate)" {
|
||||
t.Errorf("a new revision's answer said %q", got)
|
||||
}
|
||||
settled = answering()
|
||||
hk, _ := nodeengineclient.HaveKey("n1", "lemurs")
|
||||
moved, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: fp, Composed: "sha256:" + strings.Repeat("e", 64), Phase: nodeengineclient.PhaseRunning})
|
||||
sb.put(buckets.Have, hk, moved, 13)
|
||||
drain()
|
||||
if got := answering(); got != settled+len(answers) {
|
||||
t.Errorf("what runs moved, and %d answer(s) were composed again for %d group(s)", got-settled, len(answers))
|
||||
}
|
||||
if got := lastSaid("answering assignment candidate drops "); got != "answering assignment candidate drops (revision 5; woken by haves)" {
|
||||
t.Errorf("an answer woken by what runs moving said %q", got)
|
||||
}
|
||||
// A read the bus did not answer is no answer to keep: the group is answered again after a bound, though nothing moved.
|
||||
setFor(t, &laterAgain, []time.Duration{20 * time.Millisecond})
|
||||
ownFails.Store(true)
|
||||
candidate("adds", 9, "lemurs", "keeper")
|
||||
waitFor("the answer met the vault not answering", func(a map[string]nodeengine.CandidateAnswer) bool {
|
||||
return a["adds"].Revision == 9 && strings.Contains(a["adds"].Refused, "no responders")
|
||||
})
|
||||
ownFails.Store(false)
|
||||
waitFor("answered again once the bus answers, with nothing else moved", func(a map[string]nodeengine.CandidateAnswer) bool {
|
||||
return a["adds"].Revision == 9 && a["adds"].Verdict == nodeengine.CandidateAnswerVerdictDiffers
|
||||
})
|
||||
drain()
|
||||
if got := lastSaid("answering assignment candidate adds "); got != "answering assignment candidate adds (revision 9; woken by a retry after a read the bus did not answer)" {
|
||||
t.Errorf("an answer composed again after the bus did not answer said %q", got)
|
||||
}
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey("same", "n1")
|
||||
sb.del(buckets.ProposalCandidates, k)
|
||||
waitFor("the deleted group's answer stays", func(a map[string]nodeengine.CandidateAnswer) bool { _, ok := a["same"]; return !ok && len(a) == 8 })
|
||||
if got := lastSaid("answering assignment candidate drops "); got != "answering assignment candidate drops (revision 5; woken by haves)" {
|
||||
t.Errorf("an answer woken by what runs moving said %q", got)
|
||||
}
|
||||
// A read the bus did not answer is no answer to keep: the group is answered again after a bound, though nothing moved.
|
||||
setFor(t, &laterAgain, []time.Duration{20 * time.Millisecond})
|
||||
ownFails.Store(true)
|
||||
candidate("adds", 9, "lemurs", "keeper")
|
||||
waitFor("the answer met the vault not answering", func(a map[string]nodeengine.CandidateAnswer) bool {
|
||||
return a["adds"].Revision == 9 && strings.Contains(a["adds"].Refused, "no responders")
|
||||
})
|
||||
ownFails.Store(false)
|
||||
waitFor("answered again once the bus answers, with nothing else moved", func(a map[string]nodeengine.CandidateAnswer) bool {
|
||||
return a["adds"].Revision == 9 && a["adds"].Verdict == nodeengine.CandidateAnswerVerdictDiffers
|
||||
})
|
||||
drain()
|
||||
if got := lastSaid("answering assignment candidate adds "); got != "answering assignment candidate adds (revision 9; woken by a retry after a read the bus did not answer)" {
|
||||
t.Errorf("an answer composed again after the bus did not answer said %q", got)
|
||||
}
|
||||
k := meshmoduleassigner.CandidatesByProposalNodeKey("same", "n1")
|
||||
sb.del(buckets.ProposalCandidates, k)
|
||||
waitFor("the deleted group's answer stays", func(a map[string]nodeengine.CandidateAnswer) bool { _, ok := a["same"]; return !ok && len(a) == 8 })
|
||||
|
||||
// Review of L2b, round 2: a watch ends while the link stays; a group's key is deleted before the shadow watches
|
||||
// again. The new run reads afresh, so that group is no longer answered.
|
||||
sb.missing(buckets.ProposalCandidates, true)
|
||||
sb.end(buckets.Wants)
|
||||
dropsKey := meshmoduleassigner.CandidatesByProposalNodeKey("drops", "n1")
|
||||
sb.del(buckets.ProposalCandidates, dropsKey)
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
sb.missing(buckets.ProposalCandidates, false)
|
||||
waitFor("a group deleted while the shadow was down is still answered", func(a map[string]nodeengine.CandidateAnswer) bool {
|
||||
_, ok := a["drops"]
|
||||
return !ok && len(a) == 7
|
||||
})
|
||||
// Review of L2b, round 2: a watch ends while the link stays; a group's key is deleted before the shadow watches
|
||||
// again. The new run reads afresh, so that group is no longer answered.
|
||||
sb.missing(buckets.ProposalCandidates, true)
|
||||
sb.end(buckets.Wants)
|
||||
dropsKey := meshmoduleassigner.CandidatesByProposalNodeKey("drops", "n1")
|
||||
sb.del(buckets.ProposalCandidates, dropsKey)
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
sb.missing(buckets.ProposalCandidates, false)
|
||||
waitFor("a group deleted while the shadow was down is still answered", func(a map[string]nodeengine.CandidateAnswer) bool {
|
||||
_, ok := a["drops"]
|
||||
return !ok && len(a) == 7
|
||||
})
|
||||
|
||||
// The shadow ends here: its tries read notReadyAfter, which the step below sets (review round 2, the race detector).
|
||||
scancel()
|
||||
<-kept
|
||||
// The shadow ends here: its tries read notReadyAfter, which the step below sets (review round 2, the race detector).
|
||||
scancel()
|
||||
<-kept
|
||||
})
|
||||
|
||||
// Issue 1126, A7 AC1: a assignment that cannot be read composes nothing and says why; the node never applies a
|
||||
// composition made elsewhere instead. (A assignment read without the node's key composes nothing either: above.)
|
||||
@@ -1552,9 +1556,6 @@ func testTheNodeComposesItsWantsFromTheBus(t *testing.T) {
|
||||
t.Errorf("a shadow not ready said %q", nsaid)
|
||||
}
|
||||
nmu.Unlock()
|
||||
// The first shadow ends before slowAfter is set: it reads it while it answers (a race the race detector names).
|
||||
scancel()
|
||||
<-kept
|
||||
setFor(t, &slowAfter, time.Nanosecond) // every answer is slow: said, and noted in words that do not move with the time
|
||||
nb.send(ResolvedBucket, agent.Update{Caught: true})
|
||||
select {
|
||||
@@ -1746,7 +1747,7 @@ type patternWatch struct {
|
||||
|
||||
func newPatternBus() *patternBus { return &patternBus{} }
|
||||
|
||||
func (b *patternBus) watch(_ context.Context, bucket, pattern string) (<-chan agent.Update, error) {
|
||||
func (b *patternBus) watch(ctx context.Context, bucket, pattern string) (<-chan agent.Update, error) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
if b.absent[bucket] {
|
||||
@@ -1754,6 +1755,20 @@ func (b *patternBus) watch(_ context.Context, bucket, pattern string) (<-chan ag
|
||||
}
|
||||
w := patternWatch{bucket: bucket, pattern: pattern, ch: make(chan agent.Update, 64)}
|
||||
b.watches = append(b.watches, w)
|
||||
// A watch ends with its context, as the bus's own does: its reader is not left waiting on it (a bubble of synctest ends
|
||||
// only once every goroutine in it did).
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
for i, kept := range b.watches {
|
||||
if kept.ch == w.ch {
|
||||
close(w.ch)
|
||||
b.watches = append(b.watches[:i], b.watches[i+1:]...)
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
if b.replay {
|
||||
for key, u := range b.kv[bucket] {
|
||||
if matches(pattern, key) {
|
||||
|
||||
Reference in New Issue
Block a user