From 65944090847409c474cee0dd6f1fba33b127b6b8 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 22:43:14 +0100 Subject: [PATCH] Wait for the shadow's settled answer and end the second shadow before its setting is restored fix-a-bug-met-twice, the kind: TestTheNodeComposesItsWantsFromTheBus asserted on output its composer and shadows still produced, or let their goroutines outlive a setting they read. The groups' answers are now waited for until every group is answered as it should be, not read from whichever answer came first (which flaked, and the settled one then read as handed again for nothing changed); the second shadow is ended before the test's cleanup restores notReadyAfter. Carries the ghost-entry order and the first shadow's end from the packet filter branch. Builds: design 47 H H-A-312 --- internal/selfcompose/selfcompose_test.go | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/internal/selfcompose/selfcompose_test.go b/internal/selfcompose/selfcompose_test.go index 6c7892e4..8fc5ddeb 100644 --- a/internal/selfcompose/selfcompose_test.go +++ b/internal/selfcompose/selfcompose_test.go @@ -1292,7 +1292,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 }, @@ -1327,11 +1327,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 { @@ -1482,8 +1490,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)