From 203454b1a93dee5be4d9396ae77035a6478ea6b4 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 14:59:47 +0100 Subject: [PATCH] Assigner test: read the keeping's need only once the keeping took it TestAPassWritesWantsWhileAKeepingIsBlocked read the graph's need right after two passes, while the keeping takes it on its own goroutine; on a loaded build node it read too early (pipeline main.251). The blocked object bucket now says when a keeping meets its gate, and the test waits on that, bounded by the level bound, as it does on the pass and the wake. Builds: design 47 H2 H-A-476 --- .../mesh-delivery-assigner/graphkept_test.go | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept_test.go index fdf8d4fd0..b8078d174 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/graphkept_test.go @@ -19,6 +19,7 @@ import ( mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-sdk/go/catalogue" + "git.novox.be/novox/mesh-sdk/go/testbus" "mesh-delivery-assigner/internal/assign" "mesh-delivery-assigner/internal/assigngraph" @@ -170,15 +171,21 @@ func TestTheWantsAreSaidWantedFromTheKeptAssignmentGraphRevision(t *testing.T) { } // blockedObjects is an object bucket whose listing waits while a gate stands: a keeping that does not end until it is opened. +// A listing that meets the gate closes entered: the keeping took its need and runs it (H-A-476). type blockedObjects struct { memObjects - mu sync.Mutex - gate chan struct{} + mu sync.Mutex + gate chan struct{} + entered chan struct{} } func (b *blockedObjects) Names(ctx context.Context) ([]string, error) { b.mu.Lock() - gate := b.gate + gate, entered := b.gate, b.entered + if gate != nil && entered != nil { + close(entered) + b.entered = nil + } b.mu.Unlock() if gate != nil { <-gate @@ -204,16 +211,33 @@ func (b *blockedObjects) Get(ctx context.Context, name string) ([]byte, error) { func (b *blockedObjects) block() func() { gate := make(chan struct{}) b.mu.Lock() - b.gate = gate + b.gate, b.entered = gate, make(chan struct{}) b.mu.Unlock() return func() { b.mu.Lock() - b.gate = nil + b.gate, b.entered = nil, nil b.mu.Unlock() close(gate) } } +// awaitBlocked returns once a keeping meets the standing gate, so what the keeping took is read after it took it, and fails the +// test when none did within bound (H-A-476: a test waits on the signal of the work it reads after, never on an order it assumes). +func (b *blockedObjects) awaitBlocked(t *testing.T, bound time.Duration, what string) { + t.Helper() + b.mu.Lock() + entered := b.entered + b.mu.Unlock() + if entered == nil { + return // met already + } + select { + case <-entered: + case <-time.After(bound): + t.Fatalf("no keeping met the gate within %s: %s", bound, what) + } +} + // Design 47 H-A-259, H-A-261: the keeping of the assignment graph runs off the pass loop. At the start, while the first keeping is // blocked, a pass returns and writes no want; the keeping's end wakes a pass, which writes the passed pipeline's want. Later, while a // keeping of new inputs is blocked, a pass writes the wants from the revision it holds, and a pass of the same inputs hands nothing @@ -222,6 +246,7 @@ func TestAPassWritesWantsWhileAKeepingIsBlocked(t *testing.T) { fp := mcc.SourcePrefix2 + strings.Repeat("a", 64) wantsKV := &memKV{values: map[string][]byte{}} p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, time.Now()) + bound := testbus.SetupBound(t) // every wait on a goroutine's work, never a value in the test (H-A-476) var mu sync.Mutex var journal strings.Builder p.logf = func(f string, a ...any) { mu.Lock(); fmt.Fprintf(&journal, f+"\n", a...); mu.Unlock() } @@ -252,7 +277,7 @@ func TestAPassWritesWantsWhileAKeepingIsBlocked(t *testing.T) { go func() { p.pass(context.Background()); close(done) }() select { case <-done: - case <-time.After(10 * time.Second): + case <-time.After(bound): t.Fatal("the pass waits on the keeping of the assignment graph") } } @@ -281,7 +306,7 @@ func TestAPassWritesWantsWhileAKeepingIsBlocked(t *testing.T) { open() select { case <-woke: - case <-time.After(10 * time.Second): + case <-time.After(bound): t.Fatal("the first keeping's end wakes no pass") } pass() @@ -292,7 +317,8 @@ func TestAPassWritesWantsWhileAKeepingIsBlocked(t *testing.T) { open = objects.block() // a keeping of new inputs is blocked placeOn(t, p.w, "g14", "web") pass() - pass() // the same inputs again + pass() // the same inputs again + objects.awaitBlocked(t, bound, "the keeping of new inputs never took its need") // H-A-476: read the need once it was taken if w, err := wantOf("g14"); err != nil || w.Fp != fp || w.Version != "0.1.2" { t.Errorf("the want of web on g14 = %+v (%v), want the passed version while a keeping is blocked", w, err) } -- 2.54.0