Files
mesh-delivery/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/step_integration_test.go
T
jschoubben 7dbd440a4e B1: the builder pulls the seat mesh-builds' work queue and takes each ask once
An ask put while the builder is down waited for nobody: the plain subscription
heard only what came while it ran. The builder now pulls every waiting ask from
the seat's one worker, takes it once by its id in its state taken (for
ask-taken-bound), says ask-taken at the pull, sends in-progress while it builds
and acknowledges once the step's end is said. Its publish to a registry seat is
a kept call carrying the publish's ask id. The manifest declares taken and the
kept-call pace and ask-taken-bound as runtime settings.

Builds: design 47 H2 §775, §777, §820; H-A-381
2026-11-22 00:45:40 +01:00

117 lines
4.5 KiB
Go

//go:build integration
package main
import (
"encoding/json"
"runtime"
"strings"
"testing"
"time"
"github.com/nats-io/nats.go"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
"git.novox.be/novox/mesh-sdk/go/buscompose"
)
// The runner's build step ask on the seat mesh-builds' accept subject, naming an entry by its fingerprint, is built through the
// module's one claim and answered as the seat's step-ended.<node> under the ask's id (design 47 G A-97, A-99).
func TestTheRunnersBuildStepAskIsAnsweredAsStepEnded(t *testing.T) {
b := startBed(t)
b.module(t, "netcheck", "catalogue-a67f0196-netcheck.module.json", "modules/netcheck")
sub, err := nats.Connect(b.srvURL, nats.UserInfo("ctl", "pw"))
if err != nil {
t.Fatal(err)
}
defer sub.Close()
ended := make(chan *nats.Msg, 4)
s, err := sub.ChanSubscribe(meshbuilds.SubjectStepEndedAll, ended)
if err != nil {
t.Fatal(err)
}
defer s.Unsubscribe()
taken := make(chan *nats.Msg, 4)
st, err := sub.ChanSubscribe(meshbuilds.SubjectAskTakenAll, taken)
if err != nil {
t.Fatal(err)
}
defer st.Unsubscribe()
// Design 47 H2 §777: an ask put on the seat's work queue while the builder is stopped waits there, and is taken (ask-taken)
// and ended once the builder starts.
run := meshbuilds.StepRun{Pipeline: "main.1.netcheck", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 1,
Entries: []meshbuilds.BuildEntry{{Module: "netcheck", Fingerprint: fp}}}
data, _ := json.Marshal(run)
msg := nats.NewMsg(meshbuilds.AcceptSubjectStep)
msg.Data = data
msg.Header.Set("x-event-id", "ask-1")
msg.Header.Set(nats.MsgIdHdr, "ask-1")
if _, err := b.js.PublishMsg(b.ctx, msg); err != nil {
t.Fatalf("the ask is not put on the seat's work queue: %v", err)
}
b.start(t, "n1", nil)
select {
case m := <-taken:
var at meshbuilds.AskTakenEvent
if err := json.Unmarshal(m.Data, &at); err != nil || at.Ask != "ask-1" || at.Node != "n1" || at.At.IsZero() || m.Subject != meshbuilds.SubjectAskTaken("ask-1") {
t.Fatalf("ask-taken on %s = %+v, %v; want ask-1 taken on n1", m.Subject, at, err)
}
case <-time.After(20 * time.Second):
t.Fatal("no ask-taken within 20 s of the start")
}
select {
case m := <-ended:
var end meshbuilds.StepEnded
if err := json.Unmarshal(m.Data, &end); err != nil || end.ID != "ask-1" || end.Outcome != meshbuilds.StepEndedOutcomePassed || end.Pipeline != "main.1.netcheck" || m.Subject != meshbuilds.SubjectStepEnded("n1") {
t.Fatalf("step-ended on %s = %+v, %v; want the ask ask-1 passed on n1", m.Subject, end, err)
}
case <-time.After(20 * time.Second):
t.Fatal("no step-ended within 20 s")
}
// H-A-155: an ask naming a source revision the builder's picture of main does not hold yet waits for it, said in the
// journal, and is answered once a revision taken in from it arrives.
run.Pipeline, run.Revision, run.Source = "main.2.netcheck", 2, 2
data, _ = json.Marshal(run)
msg = nats.NewMsg(meshbuilds.AcceptSubjectStep)
msg.Data = data
msg.Header.Set("x-event-id", "ask-2")
if err := sub.PublishMsg(msg); err != nil {
t.Fatal(err)
}
b.awaitSaid(t, "main.2.netcheck: revision 2 of main not in the builder's picture yet")
b.catalog.mu.Lock()
b.catalog.source = 2
b.catalog.mu.Unlock()
// Revision 2, taken in from source 2, moves another module: netcheck's entry is the one the picture holds already.
b.moduleFP(t, "ca-trust", "catalogue-a67f0196-ca-trust.module.json", "modules/ca-trust", nil, commit, "src2:"+strings.Repeat("4", 64), 0)
select {
case m := <-ended:
var end meshbuilds.StepEnded
if err := json.Unmarshal(m.Data, &end); err != nil || end.ID != "ask-2" || end.Outcome != meshbuilds.StepEndedOutcomePassed {
t.Fatalf("step-ended = %+v, %v; want the ask ask-2 passed once the picture held source revision 2", end, err)
}
case <-time.After(20 * time.Second):
t.Fatal("no step-ended for ask-2 within 20 s")
}
// Each ask is acknowledged once its end was said: the seat's worker holds none pending.
stream, worker := buscompose.SeatQueueStreamName(meshbuilds.Seat), buscompose.SeatQueueWorkerName(meshbuilds.Seat)
deadline := time.Now().Add(10 * time.Second)
for {
c, err := b.js.Consumer(b.ctx, stream, worker)
if err != nil {
t.Fatal(err)
}
info, err := c.Info(b.ctx)
if err != nil {
t.Fatal(err)
}
if info.NumPending == 0 && info.NumAckPending == 0 {
break
}
if time.Now().After(deadline) {
t.Fatalf("the seat's worker holds %d waiting and %d taken after both asks ended, want none", info.NumPending, info.NumAckPending)
}
runtime.Gosched()
}
}