Merge main into feat/47-H2: the self-compose test fixes (#247)

This commit is contained in:
2026-11-22 02:58:26 +01:00
+26 -7
View File
@@ -281,6 +281,14 @@ func testTheNodeComposesItsWantsFromTheBus(t *testing.T) {
if err != nil {
t.Fatal(err)
}
// The composer's loop has ended (its out closed) before the test's cleanup restores composeAgain, laterAgain,
// passSaysEvery and slowAfter, which its passes read (fix-a-bug-met-twice: a goroutine outliving the setting it reads,
// as the shadows below).
defer func() {
cancel()
for range out {
}
}()
// oldie is placed and no want names it (a module at a build of the old form, nats on novox): the node runs it inside
// its own composition, and composes it there again, even before the agent has applied anything (Running empty).
oldie := `{"module":"oldie","version":"1","capabilities":["systemd"],"resources":[{"id":"service","type":"service","unit":"oldie.service","state":"running","boot":"enabled"}]}`
@@ -1293,7 +1301,7 @@ func testTheNodeComposesItsWantsFromTheBus(t *testing.T) {
}
}
readOnly.mu.Unlock()
for group, want := range map[string]func(nodeengine.CandidateAnswer) bool{
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
},
@@ -1328,11 +1336,19 @@ func testTheNodeComposesItsWantsFromTheBus(t *testing.T) {
return a.Verdict == nodeengine.CandidateAnswerVerdictRefused && a.Returns == "" && a.Revision == 7 &&
strings.Contains(a.Refused, "composes nothing")
},
} {
if !want(answers[group]) {
t.Errorf("%s: %+v", group, answers[group])
}
}
// 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 {
@@ -1483,8 +1499,11 @@ func testTheNodeComposesItsWantsFromTheBus(t *testing.T) {
nanswered := make(chan map[string]nodeengine.CandidateAnswer, 8)
nsh := NewShadow(nenv, func(_ context.Context, a map[string]nodeengine.CandidateAnswer) { nanswered <- a })
nctx, ncancel := context.WithCancel(ctx)
defer ncancel()
go func() { _ = nsh.Run(nctx) }()
// The shadow has ended before the test's cleanup restores notReadyAfter, which its run reads (fix-a-bug-met-twice:
// a goroutine outliving the setting it reads, the race of the first shadow above too).
nDone := make(chan struct{})
defer func() { ncancel(); <-nDone }()
go func() { _ = nsh.Run(nctx); close(nDone) }()
nb.made(6)
nb.putAssigned(tp, 1)
nb.put(buckets.Have, "n1.node", rec, 1)