selfcompose: the shadow part of the test waits on its bubble going idle, not wall time

Review round 1 of fd7f049e, the kind "a test waits a fixed quiet window"
(the 50 ms window of the hand pass was the first, note 14's shadow part the
second). The shadow part of TheNodeComposesItsWantsFromTheBus counted its
answers after fixed windows (150 ms drains, a 100 ms no-answer window, two
30 ms sleeps) and failed under load on trunk too (2 of 48 processes).

It now runs in a bubble of testing/synctest: each of those waits ends only
once every goroutine of the bubble is idle and the bubble's clock passed
it, so a slow build node cannot end it early. The pattern bus's watch ends
with its context, as the bus's own does, so the bubble's readers end with
it. What the steps after the shadow use (the record, the assignment, the
want) is made before the bubble; the shadow ends inside it.

Under load (48 processes x 5, GOMAXPROCS=2, race detector): 240 of 240
passed (trunk: 6 of 48 processes failed).

Issue 721 (note 15, acceptance criterion 721/AC2).
This commit is contained in:
2026-11-23 16:00:59 +01:00
parent 1d1ca05349
commit e4926f706e
+279 -259
View File
@@ -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"
@@ -1203,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.)
@@ -1547,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 {
@@ -1741,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] {
@@ -1749,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) {