Files
mesh-delivery/modules/mesh-delivery-builder/buildrun/assignerholder_test.go
T
jschoubben 6d9a7b8aae Checker follows the assignments of the holder of the seat mesh-module-assigner found at run time; FollowAssignments, AssignerModule and AssignmentsBucket go
buildrun gains AssignerHolder, AssignmentsOf and SleepFor (moved from the builder's program, which uses them), so
the builder and the checker follow the holder's first-view tool, views family and state alike; the checker's
manifest consumes the seat's views assignments and reads its assignments state, its composition reads the
picture once followed. The assigner's callers list for the first view gains the checker.

Builds: design 47 G A-82, A-119, A-126, A-131
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 01:38:34 +01:00

38 lines
1.5 KiB
Go

package buildrun
import (
"context"
"encoding/json"
"errors"
"testing"
"time"
"git.novox.be/novox/mesh-sdk/go/seatlist"
)
// The builder and the checker find the assigner's holder at run time: asked again while the seat list does not answer, and the names of the view
// are made from the holder (design 47 G A-119), not fixed in code.
func TestTheAssignerHolderIsFoundAtRunTime(t *testing.T) {
asks, slept := 0, 0
call := func(key string, _ any) (json.RawMessage, error) {
if key != seatlist.HolderKey() {
t.Errorf("asked %q, want %q", key, seatlist.HolderKey())
}
if asks++; asks == 1 {
return nil, errors.New("down")
}
return json.RawMessage(`{"seats":[{"seat":"mesh-module-assigner","holders":[{"module":"acme-assigner"}]}]}`), nil
}
holder, ok := AssignerHolder(context.Background(), call, time.Second, func(context.Context, time.Duration) bool { slept++; return true }, func(string, ...any) {})
if !ok || holder != "acme-assigner" || slept != 1 {
t.Fatalf("holder = %q, %v after %d pauses, want acme-assigner after one", holder, ok, slept)
}
if n := AssignmentsOf(holder); n.Tool != "acme-assigner.assignments" || n.Bucket != "acme-assigner_assignments" {
t.Errorf("names = %+v", n)
}
if _, ok := AssignerHolder(context.Background(), func(string, any) (json.RawMessage, error) { return nil, errors.New("down") }, time.Second,
func(context.Context, time.Duration) bool { return false }, func(string, ...any) {}); ok {
t.Error("a holder was found though ctx ended")
}
}