runner: no holder is read from the seat-holders view, and an ask waits for its holder with no five-minute bound (R4)
A step queued for a present holder was ended failed after five minutes; the five-minute ask bound goes, and a seat ends its steps could not run only when the seat mesh-module-assigner's view seat-holders, followed from its first view on, names no holder for it. Builds: design 47 G §535, §647 (as A-466y and A-466z amend them), §717 (the follower)
This commit is contained in:
@@ -36,7 +36,7 @@ func deleteBound(ctx context.Context, bounds jetstream.KeyValue) func(key string
|
||||
// armDropBound arms the five-minute bound of a drop, a key of the state bounds with its own time to live (A-77, A-222).
|
||||
func armDropBound(ctx context.Context, bounds jetstream.KeyValue) func(key string) error {
|
||||
return func(key string) error {
|
||||
_, err := bounds.Create(ctx, key, []byte(`{"drop":"`+key+`"}`), jetstream.KeyTTL(pipeline.AskBound))
|
||||
_, err := bounds.Create(ctx, key, []byte(`{"drop":"`+key+`"}`), jetstream.KeyTTL(pipeline.DropBound))
|
||||
if errors.Is(err, jetstream.ErrKeyExists) {
|
||||
return nil
|
||||
}
|
||||
@@ -67,26 +67,19 @@ func dropUnanswered(ctx context.Context, w callFindings, module string, now func
|
||||
return w.Write(ctx, condseat.Finding{Scope: mcc.ScopeCall, ID: id, Kind: mcc.KindCallUnanswered, Severity: condseat.FindingSeverityWarning,
|
||||
Summary: fmt.Sprintf("the call %s of ask %s is unanswered", call, ask),
|
||||
Headline: "A call whose answer is kept is not answered",
|
||||
Explanation: fmt.Sprintf("The drop of the superseded step's ask %s was asked of the seat %s as a kept call and no holder answered it within %s, so the build it names may still run.", ask, buildSeat, pipeline.AskBound),
|
||||
Explanation: fmt.Sprintf("The drop of the superseded step's ask %s was asked of the seat %s as a kept call and no holder answered it within %s, so the build it names may still run.", ask, buildSeat, pipeline.DropBound),
|
||||
Source: module + "." + mcc.KindCallUnanswered, Observer: module, At: now().UTC(), Subject: condseat.Subject{Scope: mcc.ScopeCall, ID: id}})
|
||||
}
|
||||
}
|
||||
|
||||
// boundExpired takes the expiry of a key of the state bounds: a drop's says the drop unanswered, an ask's ends the step no
|
||||
// holder took (§32, §535, A-77); another key is none of the runner's.
|
||||
func boundExpired(h *pipeline.Hearer, unanswered func(buildSeat, ask string) error, logf func(string, ...any)) func(key string) {
|
||||
// boundExpired takes the expiry of a key of the state bounds: a drop's says the drop unanswered (A-222); another key is none
|
||||
// of the runner's, an ask having no bound of its own (§535, §647 as A-466y amends them).
|
||||
func boundExpired(unanswered func(buildSeat, ask string) error, logf func(string, ...any)) func(key string) {
|
||||
return func(key string) {
|
||||
if s, ask, ok := pipeline.ParseDropBound(key); ok {
|
||||
if err := unanswered(s, ask); err != nil {
|
||||
logf("the drop of ask %s on %s, unanswered, is not said: %v", ask, s, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if !pipeline.IsAskKey(key) {
|
||||
return
|
||||
}
|
||||
if err := h.NotTaken(key, pipeline.AskBound); err != nil {
|
||||
logf("the step of ask %s, which no holder took, is not ended: %v", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func (f *fakeFindings) Clear(_ context.Context, scope, id, kind, _ string) error
|
||||
func TestADropBoundsExpirySaysCallUnanswered(t *testing.T) {
|
||||
w := &fakeFindings{}
|
||||
var logged int
|
||||
expired := boundExpired(nil, dropUnanswered(context.Background(), w, "the-runner", func() time.Time { return time.Unix(100, 0) }), func(string, ...any) { logged++ })
|
||||
expired := boundExpired(dropUnanswered(context.Background(), w, "the-runner", func() time.Time { return time.Unix(100, 0) }), func(string, ...any) { logged++ })
|
||||
expired("not-a-bound")
|
||||
if len(w.written) != 0 {
|
||||
t.Fatalf("a key of no drop was said: %+v", w.written)
|
||||
|
||||
@@ -67,8 +67,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// The bound of each ask a build seat's holder must take: a key with its own time to live, its expiry heard (§535, A-77).
|
||||
bounds, err := process.EssentialBucket(ctx, js, "pipeline runner", ownBucket(cred.Module, "bounds"), "bound an ask no holder takes")
|
||||
// The bound of each superseded step's drop: a key with its own time to live, its expiry heard (A-222, A-77).
|
||||
bounds, err := process.EssentialBucket(ctx, js, "pipeline runner", ownBucket(cred.Module, "bounds"), "bound a drop no holder answers")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -151,14 +151,15 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// for its step.
|
||||
starter := &pipeline.Starter{Pipelines: createdKV{ctx: ctx, kv: pipelines}, Logf: logger.Printf, Say: say,
|
||||
Registration: rv.Registrations.Registration, Steps: busStepAsker{ctx: ctx, js: js, cred: cred}, Name: cred.Module,
|
||||
Arm: armBound(ctx, bounds), Kept: keptReader(ctx, kept), Toolchain: toolchainReader(ctx, toolchains),
|
||||
Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has}
|
||||
Kept: keptReader(ctx, kept), Toolchain: toolchainReader(ctx, toolchains),
|
||||
Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has, Holders: rv.Holders.Holders}
|
||||
placeHalf := func(ev catalog.CatalogRevisionEvent, half pipeline.Half) error {
|
||||
n, err := starter.PlaceRun(ev, half, rv.Catalog.View)
|
||||
logger.Printf("the candidate %s's revision %d placed %d pipelines of its run", ev.Group, ev.Revision, n)
|
||||
return err
|
||||
}
|
||||
resume := func(branch string) {
|
||||
rv.Holders.refresh() // a half held may name the claimant of the seat-holders view (§647)
|
||||
half, ok := rv.Catalog.View(branch)
|
||||
if !ok {
|
||||
return
|
||||
@@ -182,6 +183,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
resumer.Store(&resume)
|
||||
// The view reaching a newer revision places the steps of the pipelines that waited for it, and asks nothing again (A-448, §200).
|
||||
advance := func(branch string) {
|
||||
rv.Holders.refresh()
|
||||
if n, err := starter.Waiting(pipelineStore{ctx: ctx, kv: pipelines}, branch, rv.Catalog.View); err != nil || n > 0 {
|
||||
logger.Printf("the pipelines of %s that waited for a newer revision of its half: %d placed (%v)", branch, n, err)
|
||||
}
|
||||
@@ -227,7 +229,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// A newer commit or publish supersedes the older running pipelines it replaces, their asks dropped as kept calls (§31,
|
||||
// §350; A-182, A-202).
|
||||
starter.Supersede = func(newer seat.Pipeline) {
|
||||
n, err := hearer.Supersede(newer, pipeline.BoundDrop(dropAsk(calls, cred.Module), armDropBound(ctx, bounds), dropAnswered(ctx, deleteBound(ctx, bounds), rv.Findings)), dropBound(ctx, bounds))
|
||||
n, err := hearer.Supersede(newer, pipeline.BoundDrop(dropAsk(calls, cred.Module), armDropBound(ctx, bounds), dropAnswered(ctx, deleteBound(ctx, bounds), rv.Findings)))
|
||||
if err != nil {
|
||||
logger.Printf("the pipelines %s supersedes: %d ended, then %v", newer.Pipeline, n, err)
|
||||
} else if n > 0 {
|
||||
@@ -258,10 +260,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
}
|
||||
return hearer.RunTaken(ask, node)
|
||||
}
|
||||
if err := hearAskTaken(ctx, heard, bounds, taken, logger.Printf); err != nil {
|
||||
if err := hearAskTaken(heard, taken, logger.Printf); err != nil {
|
||||
return err
|
||||
}
|
||||
expired := boundExpired(hearer, dropUnanswered(ctx, rv.Findings, cred.Module, time.Now), logger.Printf)
|
||||
expired := boundExpired(dropUnanswered(ctx, rv.Findings, cred.Module, time.Now), logger.Printf)
|
||||
if err := watchBounds(ctx, bounds, expired, logger.Printf); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -295,7 +297,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// mesh-wants), never on EVENTS: bound here, or no step of any pipeline is ever heard ending (G-1 §24).
|
||||
logger.Printf("the kept seat events heard: %d streams bound", hub.StartKept(ctx, js, cred))
|
||||
// The seat's write verbs are answered here, by the process that holds the pipelines (A-107).
|
||||
stopVerbs, err := answerVerbs(calls, seats, writeVerbs(ctx, hearer, starter, func(branch string) (pipeline.Half, bool) { return rv.Catalog.View(branch) }, calls, bounds))
|
||||
stopVerbs, err := answerVerbs(calls, seats, writeVerbs(hearer, starter, func(branch string) (pipeline.Half, bool) { return rv.Catalog.View(branch) }, calls))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -137,11 +137,10 @@ func hearStepEnded(hub handlers, h *pipeline.Hearer, logf func(string, ...any))
|
||||
return nil
|
||||
}
|
||||
|
||||
// hearAskTaken deletes the bound of each ask a build seat's holder took (§602, §647) and keeps on its step the node that took
|
||||
// it (A-182): the ask is answered, so its five minutes end with no finding.
|
||||
func hearAskTaken(ctx context.Context, hub handlers, bounds jetstream.KeyValue, taken func(ask, node string) error, logf func(string, ...any)) error {
|
||||
// hearAskTaken keeps on its step the node whose build seat holder took an ask (§602, §647; A-182), so a drop of it is asked of
|
||||
// that node's holder, and begins the clock of a test run's ask (§725).
|
||||
func hearAskTaken(hub handlers, taken func(ask, node string) error, logf func(string, ...any)) error {
|
||||
for _, ts := range pipeline.TakenSeats {
|
||||
ts := ts
|
||||
err := hub.Handle(ts.Subject, func(m jetstream.Msg) {
|
||||
var ev nodebuildgo.AskTaken
|
||||
if err := json.Unmarshal(m.Data(), &ev); err != nil || ev.Ask == "" {
|
||||
@@ -149,12 +148,6 @@ func hearAskTaken(ctx context.Context, hub handlers, bounds jetstream.KeyValue,
|
||||
_ = m.Term()
|
||||
return
|
||||
}
|
||||
if err := bounds.Delete(ctx, ev.Ask); err != nil && !errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
logf("the bound of ask %s, taken on %s, is not deleted, heard again: %v", ev.Ask, ev.Node, err)
|
||||
_ = m.Nak()
|
||||
return
|
||||
}
|
||||
// The step keeps the node that took its ask, so a drop of it is asked of that node's holder (A-182).
|
||||
if err := taken(ev.Ask, ev.Node); err != nil {
|
||||
logf("the node %s that took ask %s is not kept on its step, heard again: %v", ev.Node, ev.Ask, err)
|
||||
_ = m.Nak()
|
||||
@@ -169,19 +162,8 @@ func hearAskTaken(ctx context.Context, hub handlers, bounds jetstream.KeyValue,
|
||||
return nil
|
||||
}
|
||||
|
||||
// armBound is the bound of an ask: a key of the state bounds with its own time to live, named for the ask.
|
||||
func armBound(ctx context.Context, bounds jetstream.KeyValue) pipeline.Arm {
|
||||
return func(ask string) error {
|
||||
_, err := bounds.Create(ctx, ask, []byte(`{"ask":"`+ask+`"}`), jetstream.KeyTTL(pipeline.AskBound))
|
||||
if errors.Is(err, jetstream.ErrKeyExists) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// watchBounds hears the end of each ask's bound, the bus's marker of the key's expiry, and ends the step no holder took (§32,
|
||||
// §535, A-77), and says a drop no holder answered unanswered (A-222): no timer in the process.
|
||||
// watchBounds hears the end of each drop's bound, the bus's marker of the key's expiry, and says a drop no holder answered
|
||||
// unanswered (A-222, A-77): no timer in the process.
|
||||
func watchBounds(ctx context.Context, bounds jetstream.KeyValue, expired func(key string), logf func(string, ...any)) error {
|
||||
w, err := bounds.WatchAll(ctx, jetstream.UpdatesOnly())
|
||||
if err != nil {
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
@@ -54,21 +51,10 @@ func writeHandlers(v pipeline.Verbs) map[string]process.SeatHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// dropBound deletes the bound of an ask a cancelled pipeline no longer waits on.
|
||||
func dropBound(ctx context.Context, bounds jetstream.KeyValue) func(string) error {
|
||||
return func(ask string) error {
|
||||
if err := bounds.Delete(ctx, ask); err != nil && !errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// writeVerbs are the verbs over the hearer and the starter, their hand acts recorded through the seat mesh-hand-acts.
|
||||
func writeVerbs(ctx context.Context, h *pipeline.Hearer, s *pipeline.Starter, view func(string) (pipeline.Half, bool),
|
||||
calls *process.Conn, bounds jetstream.KeyValue) pipeline.Verbs {
|
||||
func writeVerbs(h *pipeline.Hearer, s *pipeline.Starter, view func(string) (pipeline.Half, bool), calls *process.Conn) pipeline.Verbs {
|
||||
candidate := func(group, branch string, revision int64) (pipeline.Half, error) {
|
||||
return readCandidate(calls.CallKept, catalog.CatalogRevisionEvent{Kind: "candidate", Group: group, Branch: branch, Revision: revision})
|
||||
}
|
||||
return pipeline.Verbs{Hearer: h, Starter: s, View: view, Candidate: candidate, Acts: meshhandactsclient.Recorder{Ask: calls.Call}, Drop: dropBound(ctx, bounds)}
|
||||
return pipeline.Verbs{Hearer: h, Starter: s, View: view, Candidate: candidate, Acts: meshhandactsclient.Recorder{Ask: calls.Call}}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
"mesh-delivery-pipeline/internal/pipeline"
|
||||
@@ -26,6 +28,70 @@ type runnerViews struct {
|
||||
// Findings is the runner's held finding writer: it raises the finding pipeline-failed (§33) and says the runner's own
|
||||
// findings (A-206).
|
||||
Findings *findingsWriter
|
||||
// Holders follows the seat-holders view of the seat mesh-module-assigner's claimant (§535, §647; A-466z).
|
||||
Holders *holderView
|
||||
}
|
||||
|
||||
// holderView follows the view seat-holders of the module the catalog halves name as the claimant of the seat
|
||||
// mesh-module-assigner (seatlist.HolderSeat), as the runner's manifest consumes it, `seat:mesh-module-assigner.views.seat-holders`
|
||||
// (design 47 G §535, §647 as A-466z amends them; §717): a claimant named anew drops the view followed and follows the new one's.
|
||||
// Nothing is asked on a timer: it is read again whenever a branch's half is held or advances.
|
||||
type holderView struct {
|
||||
reader *views.ProcessReader
|
||||
catalog *pipeline.Views
|
||||
logf func(string, ...any)
|
||||
mu sync.Mutex
|
||||
owner string
|
||||
pic *views.Picture
|
||||
}
|
||||
|
||||
// refresh follows the claimant's seat-holders view when the claimant is another than the one followed.
|
||||
func (h *holderView) refresh() {
|
||||
var halves []pipeline.Half
|
||||
for _, b := range h.catalog.Branches() {
|
||||
if half, ok := h.catalog.View(b); ok {
|
||||
halves = append(halves, half)
|
||||
}
|
||||
}
|
||||
claimant, ok := pipeline.ClaimantOf(halves, seatlist.HolderSeat)
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
if !ok || claimant == h.owner {
|
||||
return
|
||||
}
|
||||
if h.owner != "" {
|
||||
if err := h.reader.Drop(h.owner, seatHoldersState); err != nil {
|
||||
h.logf("the seat-holders view of %s is not dropped: %v", h.owner, err)
|
||||
}
|
||||
h.owner, h.pic = "", nil
|
||||
}
|
||||
pic, err := h.reader.Follow(claimant, seatHoldersState, claimant+"."+seatHoldersState)
|
||||
if err != nil {
|
||||
h.logf("the seat-holders view of %s is not followed: %v", claimant, err)
|
||||
return
|
||||
}
|
||||
h.owner, h.pic = claimant, pic
|
||||
h.logf("the seat-holders view of %s, the claimant of %s, is followed", claimant, seatlist.HolderSeat)
|
||||
}
|
||||
|
||||
// seatHoldersState is the seat mesh-module-assigner's view of who holds each seat (§616, §699).
|
||||
const seatHoldersState = "seat-holders"
|
||||
|
||||
// Holders are the modules the followed view names for seatName, and whether its first view is read: before it, and with
|
||||
// no claimant followed, nothing is judged (A-466y).
|
||||
func (h *holderView) Holders(seatName string) ([]string, bool) {
|
||||
h.mu.Lock()
|
||||
pic := h.pic
|
||||
h.mu.Unlock()
|
||||
if pic == nil {
|
||||
return nil, false
|
||||
}
|
||||
select {
|
||||
case <-pic.Follower().Ready():
|
||||
default:
|
||||
return nil, false
|
||||
}
|
||||
return seatlist.HoldersIn(func() (map[string]json.RawMessage, error) { return pic.Follower().Values(), nil })(seatName), true
|
||||
}
|
||||
|
||||
// startViews wires the runner's views on hub and asks each first view; register every other handler on hub before or
|
||||
@@ -88,7 +154,7 @@ func startViews(ctx context.Context, js jetstream.JetStream, conn *nats.Conn, cr
|
||||
return nil, err
|
||||
}
|
||||
reader.Start(ctx, js, cred, status)
|
||||
return &runnerViews{Registrations: regs, Catalog: cv, Findings: findings}, nil
|
||||
return &runnerViews{Registrations: regs, Catalog: cv, Findings: findings, Holders: &holderView{reader: reader, catalog: cv, logf: logf}}, nil
|
||||
}
|
||||
|
||||
// catalogView is a branch's meshcatalogclient.Catalog as the runner reads it.
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
nodebuildimage "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildimage"
|
||||
nodebuildnode "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildnode"
|
||||
)
|
||||
|
||||
// AskBound is how long an ask on a build seat's work queue may wait for its holder to take it (design 47 G §535, §647): five
|
||||
// minutes, the bound of a key of the state `bounds` with its own time to live (A-77, A-104), never a timer.
|
||||
const AskBound = 5 * time.Minute
|
||||
// DropBound is how long a superseded step's drop may go unanswered before it is said (design 47 G A-222, A-77): five minutes,
|
||||
// a key of the state `bounds` with its own time to live. An ask waiting for its holder has no such bound (§535, §647 as
|
||||
// A-466y amends them): it is timed by §86's build-capacity finding and, for a test run, by run-untaken-bound (§725).
|
||||
const DropBound = 5 * time.Minute
|
||||
|
||||
// TakenSeat is a build seat whose holder says `ask-taken` when it takes an ask (design 47 G §602): where the runner hears it.
|
||||
type TakenSeat struct {
|
||||
@@ -23,15 +22,15 @@ type TakenSeat struct {
|
||||
Subject string
|
||||
}
|
||||
|
||||
// TakenSeats are the three build seats, from their contracts: the seat mesh-builds and the seat mesh-wants say no ask-taken,
|
||||
// so no bound is armed for their asks.
|
||||
// TakenSeats are the three build seats, from their contracts: the seat mesh-builds and the seat mesh-wants say no ask-taken.
|
||||
var TakenSeats = []TakenSeat{
|
||||
{Seat: nodebuildgo.Seat, Subject: nodebuildgo.SubjectAskTakenAll},
|
||||
{Seat: nodebuildnode.Seat, Subject: nodebuildnode.SubjectAskTakenAll},
|
||||
{Seat: nodebuildimage.Seat, Subject: nodebuildimage.SubjectAskTakenAll},
|
||||
}
|
||||
|
||||
// BoundSeat says whether the holder of a seat says ask-taken, so an ask put on its work queue has a bound.
|
||||
// BoundSeat says whether the holder of a seat says ask-taken: a build seat, whose asks are dropped and whose test steps share
|
||||
// a run (§724).
|
||||
func BoundSeat(name string) bool {
|
||||
for _, s := range TakenSeats {
|
||||
if s.Seat == name {
|
||||
@@ -41,63 +40,6 @@ func BoundSeat(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Arm puts a bound of one ask's wait for its holder: a key of the state `bounds` named for the ask, written with its own
|
||||
// time to live. It is armed before the ask is put, so an ask-taken heard at once finds it.
|
||||
type Arm func(ask string) error
|
||||
|
||||
// NotTaken ends the step asked under ask that no holder took within its bound, the bound's expiry heard (design 47 G §32,
|
||||
// §535, §647, A-77): the step ends `could not run` naming the seat, so its pipeline ends failed once the others end, never
|
||||
// a silent wait. A step that ended or was never asked of a seat takes nothing.
|
||||
func (h *Hearer) NotTaken(ask string, bound time.Duration) error {
|
||||
pkeys, err := h.Store.Keys("*.*.*")
|
||||
if err != nil {
|
||||
return fmt.Errorf("the pipelines are not listed: %w", err)
|
||||
}
|
||||
for _, key := range pkeys {
|
||||
p, _, err := h.Store.Get(key)
|
||||
if err != nil || p.Outcome != seat.PipelineOutcomeRunning || stepOfAsk(p, ask) < 0 {
|
||||
continue
|
||||
}
|
||||
return h.endNotTaken(key, ask, bound)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *Hearer) endNotTaken(key, ask string, bound time.Duration) error {
|
||||
for {
|
||||
p, rev, err := h.Store.Get(key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the pipeline %s is not read: %w", key, err)
|
||||
}
|
||||
i := stepOfAsk(p, ask)
|
||||
if i < 0 || p.Steps[i].Outcome != seat.StepResultOutcomeRunning {
|
||||
return nil
|
||||
}
|
||||
now := h.now()
|
||||
s := &p.Steps[i]
|
||||
s.Outcome, s.Ended = seat.StepResultOutcomeCouldNotRun, &now
|
||||
s.Why = fmt.Sprintf("the seat %s has no holder that took ask %s within %s", s.Seat, ask, bound)
|
||||
p.Unlogged = append(p.Unlogged, endEntry(key, *s, now))
|
||||
ended := endPipeline(&p, now)
|
||||
if _, err := h.Store.Update(key, p, rev); errors.Is(err, ErrChanged) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("pipeline %s cannot be written: %w", key, err)
|
||||
}
|
||||
h.Failures.StepEnded(h.Store, p, *s)
|
||||
if err := h.say(seat.EventStepEnded, p, s); err != nil {
|
||||
return fmt.Errorf("pipeline %s's %s is written but not said: %w", key, seat.EventStepEnded, err)
|
||||
}
|
||||
h.appendUnlogged(key)
|
||||
h.Ager.Age()
|
||||
h.Fills.Check()
|
||||
return h.said(p, false, ended)
|
||||
}
|
||||
}
|
||||
|
||||
// IsAskKey says whether a key of the state `bounds` is an ask's bound.
|
||||
func IsAskKey(key string) bool { return strings.HasPrefix(key, "step-") && !strings.Contains(key, ".") }
|
||||
|
||||
// DropBoundPrefix begins the key of a superseded step's drop in the state `bounds`, `drop.<build seat>.<ask>` (design 47 G
|
||||
// A-222, A-77): its five-minute expiry says the drop unanswered.
|
||||
const DropBoundPrefix = "drop."
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestAPipelinePinsItsCatalogRevisionWhileItRuns(t *testing.T) {
|
||||
}
|
||||
want(0, delivery.SubjectFreed, "pipeline."+pkey, 12)
|
||||
said = nil
|
||||
if n, err := h.Supersede(seat.Pipeline{Pipeline: "main.6.app", Branch: "main", Source: 6, Module: "app", Commit: "c2", Fingerprint: "src2:bb", Outcome: seat.PipelineOutcomeRunning}, nil, nil); n != 1 || err != nil {
|
||||
if n, err := h.Supersede(seat.Pipeline{Pipeline: "main.6.app", Branch: "main", Source: 6, Module: "app", Commit: "c2", Fingerprint: "src2:bb", Outcome: seat.PipelineOutcomeRunning}, nil); n != 1 || err != nil {
|
||||
t.Fatalf("supersede %d (%v)", n, err)
|
||||
}
|
||||
want(0, delivery.SubjectFreed, "pipeline."+pkey, 12)
|
||||
|
||||
@@ -203,8 +203,9 @@ func stepAsk(p seat.Pipeline, e catalog.CatalogEntry, a catalog.Artifact, step,
|
||||
Module: p.Module, Pipeline: p.Pipeline, Revision: p.Source, Step: step}}
|
||||
}
|
||||
|
||||
// askAll puts each ask on its seat's work queue; the first refusal is named, the rest are still put.
|
||||
func askAll(asker StepAsker, arm Arm, key string, asks []Asked, recovery bool) error {
|
||||
// askAll puts each ask on its seat's work queue; the first refusal is named, the rest are still put. An ask waits for its
|
||||
// holder with no bound of the runner's own (§535, §647 as A-466y amends them).
|
||||
func askAll(asker StepAsker, key string, asks []Asked, recovery bool) error {
|
||||
var first error
|
||||
for _, a := range asks {
|
||||
accept, ok := acceptStep[a.Seat]
|
||||
@@ -212,15 +213,6 @@ func askAll(asker StepAsker, arm Arm, key string, asks []Asked, recovery bool) e
|
||||
accept = to
|
||||
}
|
||||
err := fmt.Errorf("the seat %s is no build seat the runner asks", a.Seat)
|
||||
if ok {
|
||||
// A build seat's holder says ask-taken: the ask's bound is armed before it is put (§535, §647).
|
||||
if arm != nil && BoundSeat(a.Seat) {
|
||||
if aerr := arm(a.ID); aerr != nil {
|
||||
err = fmt.Errorf("its bound is not armed: %w", aerr)
|
||||
ok = false
|
||||
}
|
||||
}
|
||||
}
|
||||
if ok {
|
||||
err = asker.AskStep(accept, a.ID, a.Ask)
|
||||
}
|
||||
|
||||
@@ -448,3 +448,55 @@ func TestATestRunIsAskedOncePerCandidateLevelAndDigest(t *testing.T) {
|
||||
t.Errorf("a second revision asked %d test steps, want its own three", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A seat with no holder is read only from the seat-holders view (design 47 G §535, §647 as A-466y and A-466z amend them):
|
||||
// once that view's first view is read, a build step whose seat it names no holder for ends could not run naming the seat
|
||||
// and is asked of no one; before it is read, or with a holder named, the step is asked and waits with no bound of the
|
||||
// runner's own; the claimant of the view is the one module the catalog halves name.
|
||||
func TestASeatWithNoHolderIsReadFromTheSeatHoldersView(t *testing.T) {
|
||||
reg, entries := placeFixture()
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
holders []string
|
||||
read bool
|
||||
asked bool
|
||||
}{{"the view not read yet", nil, false, true}, {"a holder named", []string{"mesh-build-go"}, true, true}, {"no holder named", nil, true, false}} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
store, asks := memStore{}, &stepAsks{}
|
||||
s := &Starter{Pipelines: memCreated{store}, Say: func(string, any) error { return nil }, Steps: asks, Name: "the-runner",
|
||||
Registration: func(string) (catalog.Registration, bool) { return reg, true },
|
||||
Holders: func(string) ([]string, bool) { return c.holders, c.read }}
|
||||
if ok, err := s.Start(Begin{Branch: "main", Source: 4, Module: "app", Commit: "c1", Fp: "src2:aa", Entries: entries}); !ok || err != nil {
|
||||
t.Fatalf("start = %v, %v", ok, err)
|
||||
}
|
||||
p, _, _ := store.Get("main.4.app")
|
||||
lint := stepNamed(p, "app:program", "lint")
|
||||
asked := false
|
||||
for _, id := range asks.ids {
|
||||
asked = asked || id == lint.Ask
|
||||
}
|
||||
if c.asked && (lint.Outcome != seat.StepResultOutcomeRunning || !asked) {
|
||||
t.Errorf("the lint step = %+v, asked %v; want it running and asked", lint, asked)
|
||||
}
|
||||
if !c.asked && (lint.Outcome != seat.StepResultOutcomeCouldNotRun || !strings.Contains(lint.Why, "node-build-go has no holder") || len(asks.ids) != 2) {
|
||||
t.Errorf("the lint step = %+v, %d asked; want could not run naming the seat, only the build and composition asked", lint, len(asks.ids))
|
||||
}
|
||||
})
|
||||
}
|
||||
claims := func(seats ...string) map[string]any {
|
||||
var cs []any
|
||||
for _, n := range seats {
|
||||
cs = append(cs, map[string]any{"name": n, "scope": "mesh"})
|
||||
}
|
||||
return map[string]any{"module": "x", "version": "0.1", "claims": cs}
|
||||
}
|
||||
half := Half{Entries: map[string]catalog.CatalogEntry{"assigner": {Module: "assigner", Manifest: claims("mesh-module-assigner", "mesh-wants")},
|
||||
"app": {Module: "app", Manifest: claims()}}}
|
||||
if got, ok := ClaimantOf([]Half{half, {}}, "mesh-module-assigner"); !ok || got != "assigner" {
|
||||
t.Errorf("the claimant = %q, %v", got, ok)
|
||||
}
|
||||
other := Half{Entries: map[string]catalog.CatalogEntry{"other": {Module: "other", Manifest: claims("mesh-module-assigner")}}}
|
||||
if got, ok := ClaimantOf([]Half{half, other}, "mesh-module-assigner"); ok {
|
||||
t.Errorf("halves that disagree name %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@ package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
// Status is a step's status for one artifact of a module, read from the module's registration and never from a
|
||||
@@ -212,3 +214,35 @@ func (r *Readiness) Observe(rev int64) (first, advanced bool) {
|
||||
}
|
||||
return false, false
|
||||
}
|
||||
|
||||
// ClaimantOf is the module the catalog halves name as the claimant of seatName (design 47 G §614, A-82): the one module whose
|
||||
// entry's manifest claims it, the same in every half that names one; none, more than one, or halves that disagree name none.
|
||||
func ClaimantOf(halves []Half, seatName string) (string, bool) {
|
||||
found := ""
|
||||
for _, h := range halves {
|
||||
var named []string
|
||||
for _, e := range h.Entries {
|
||||
raw, err := json.Marshal(e.Manifest)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
m, err := catalogue.Decode(raw)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, c := range m.Claims {
|
||||
if c.Name == seatName {
|
||||
named = append(named, e.Module)
|
||||
}
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case len(named) == 0:
|
||||
continue
|
||||
case len(named) > 1, found != "" && found != named[0]:
|
||||
return "", false
|
||||
}
|
||||
found = named[0]
|
||||
}
|
||||
return found, found != ""
|
||||
}
|
||||
|
||||
@@ -232,6 +232,7 @@ func (s *Starter) placeRunPipeline(key, id string, revision int64, half Half) (b
|
||||
if s.Registration != nil {
|
||||
if reg, ok := s.Registration(p.Module); ok {
|
||||
p.Steps, asks = Place(p, reg, half.Entries, now, s.Name)
|
||||
asks = s.holderless(p.Steps, asks, now)
|
||||
} else {
|
||||
s.logf("%s has no registration yet: its pipeline is placed with no step", key)
|
||||
}
|
||||
|
||||
@@ -73,8 +73,9 @@ type Starter struct {
|
||||
// Toolchain is the toolchain of a language as the runner heard it agreed (§416, A-104): its language and version; nil when
|
||||
// none was heard, which asks the step with none.
|
||||
Toolchain func(language string) (*nodebuildgo.ToolchainUsed, error)
|
||||
// Arm arms the bound of an ask put on a build seat's work queue (§535, §647); nil arms none.
|
||||
Arm Arm
|
||||
// Holders are the modules the seat mesh-module-assigner's view seat-holders names for a seat, and whether that view's
|
||||
// first view is read (§535, §647 as A-466y, A-466z amend them); nil, or a view not read yet, judges no seat holderless.
|
||||
Holders func(seat string) ([]string, bool)
|
||||
// Fills refuses a start while a store of the runner is full (§366); nil refuses none.
|
||||
Fills *Fills
|
||||
// Recovered says whether a commit is named a recovery (§81, §86): its steps are asked on the build seats' stream delivery.
|
||||
@@ -94,6 +95,38 @@ type Starter struct {
|
||||
EndReaders func(run string, readers []seat.TestRunReader, r seat.TestRun) error
|
||||
}
|
||||
|
||||
// holderless ends, as it is placed, each build step whose seat the seat mesh-module-assigner's view seat-holders names no holder
|
||||
// for, `could not run` naming the seat, and asks it of no one (design 47 G §535, §647 as A-466y and A-466z amend them): judged
|
||||
// only once that view's first view is read, never from the picture before it. It answers the asks still to put.
|
||||
func (s *Starter) holderless(steps []seat.StepResult, asks []Asked, now time.Time) []Asked {
|
||||
if s.Holders == nil {
|
||||
return asks
|
||||
}
|
||||
none := map[string]bool{}
|
||||
for i := range steps {
|
||||
st := &steps[i]
|
||||
if st.Outcome != seat.StepResultOutcomeRunning || !BoundSeat(st.Seat) {
|
||||
continue
|
||||
}
|
||||
if holders, read := s.Holders(st.Seat); !read || len(holders) > 0 {
|
||||
continue
|
||||
}
|
||||
st.Outcome, st.Ended, st.Ask, st.Shared = seat.StepResultOutcomeCouldNotRun, &now, "", nil
|
||||
st.Why = fmt.Sprintf("the seat %s has no holder: the seat-holders view names none", st.Seat)
|
||||
none[st.Seat] = true
|
||||
}
|
||||
if len(none) == 0 {
|
||||
return asks
|
||||
}
|
||||
out := asks[:0:0]
|
||||
for _, a := range asks {
|
||||
if !none[a.Seat] {
|
||||
out = append(out, a)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// askSteps puts a placed pipeline's asks (§22, §24): a test run another step asked is read, not asked again (share), then
|
||||
// the kept results and toolchain are carried and each ask is put.
|
||||
func (s *Starter) askSteps(key, commit string, asks []Asked) error {
|
||||
@@ -102,7 +135,7 @@ func (s *Starter) askSteps(key, commit string, asks []Asked) error {
|
||||
return nil
|
||||
}
|
||||
s.carry(key, asks)
|
||||
return askAll(s.Steps, s.Arm, key, asks, s.recovered(key, commit))
|
||||
return askAll(s.Steps, key, asks, s.recovered(key, commit))
|
||||
}
|
||||
|
||||
func newPipeline(b Begin, key string, now time.Time) seat.Pipeline {
|
||||
@@ -140,6 +173,7 @@ func (s *Starter) Start(b Begin) (bool, error) {
|
||||
} else if s.Registration != nil {
|
||||
if reg, ok := s.Registration(b.Module); ok {
|
||||
p.Steps, asks = Place(p, reg, b.Entries, now, s.Name)
|
||||
asks = s.holderless(p.Steps, asks, now)
|
||||
} else {
|
||||
s.logf("%s has no registration yet: its pipeline starts with no step and waits on the registration of %s, which places them (A-327)", key, b.Module)
|
||||
}
|
||||
@@ -311,6 +345,7 @@ func (s *Starter) placeWaiting(store Updater, pattern string, reg func(seat.Pipe
|
||||
}
|
||||
var asks []Asked
|
||||
p.Steps, asks = Place(p, r, half.Entries, now, s.Name)
|
||||
asks = s.holderless(p.Steps, asks, now)
|
||||
if _, err := store.Update(key, p, rev); err != nil {
|
||||
s.logf("%s is written meanwhile, so nothing is placed in it now: %v", key, err)
|
||||
continue
|
||||
|
||||
@@ -302,49 +302,6 @@ func TestAnOptionalStepStillWaitingHoldsNoEnd(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// An ask no holder took within its bound ends its step `could not run` naming the seat, and with the rest ended the pipeline
|
||||
// failed (design 47 G §32, §535, §647, A-104); a step that ended, or ask nobody placed, ends nothing.
|
||||
func TestAnAskNoHolderTookEndsItsStepNamingTheSeat(t *testing.T) {
|
||||
h, store, said, _, _, _ := fixture()
|
||||
e := store[pkey]
|
||||
e.p.Steps[1].Outcome = seat.StepResultOutcomePassed // the unit step ended; only lint is waiting for a holder
|
||||
e.p.Steps[2].Outcome = seat.StepResultOutcomeNotAsked
|
||||
store[pkey] = e
|
||||
if err := h.NotTaken("nobody-asked", AskBound); err != nil || store[pkey].p.Steps[0].Outcome != seat.StepResultOutcomeRunning {
|
||||
t.Fatalf("an ask no step names ended something: %v", err)
|
||||
}
|
||||
if err := h.NotTaken("a1", AskBound); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := store[pkey].p
|
||||
if p.Steps[0].Outcome != seat.StepResultOutcomeCouldNotRun || !strings.Contains(p.Steps[0].Why, nodebuildgo.Seat) ||
|
||||
p.Outcome != seat.PipelineOutcomeFailed || !strings.Contains(strings.Join(*said, " "), seat.EventPipelineEnded) {
|
||||
t.Errorf("step %+v, pipeline %s (%s), said %v: want could not run naming %s and a failed pipeline", p.Steps[0], p.Outcome, p.Why, *said, nodebuildgo.Seat)
|
||||
}
|
||||
// Its end taken once: the bound's expiry heard again changes nothing.
|
||||
n := len(*said)
|
||||
if err := h.NotTaken("a1", AskBound); err != nil || len(*said) != n {
|
||||
t.Errorf("a second expiry said %d more events: %v", len(*said)-n, err)
|
||||
}
|
||||
}
|
||||
|
||||
// The bound is armed before the ask is put, only for the build seats whose holder says ask-taken, and an ask whose bound is
|
||||
// not armed is not put (§535, §647).
|
||||
func TestTheBoundIsArmedBeforeAnAskIsPut(t *testing.T) {
|
||||
var order []string
|
||||
asker := askerFunc(func(accept, id string, _ any) error { order = append(order, "put "+id); return nil })
|
||||
arm := Arm(func(ask string) error { order = append(order, "arm "+ask); return nil })
|
||||
asks := []Asked{{Seat: nodebuildgo.Seat, ID: "step-1", Ask: 1}, {Seat: wants.Seat, ID: "step-2", Ask: 2}}
|
||||
if err := askAll(asker, arm, "k", asks, false); err != nil || strings.Join(order, ",") != "arm step-1,put step-1,put step-2" {
|
||||
t.Errorf("order %v, %v; want the build seat's bound armed first and mesh-wants' ask with none", order, err)
|
||||
}
|
||||
order = nil
|
||||
failing := Arm(func(string) error { return errors.New("bucket gone") })
|
||||
if err := askAll(asker, failing, "k", asks[:1], false); err == nil || len(order) != 0 {
|
||||
t.Errorf("an ask whose bound cannot be armed was put or said nothing: %v %v", order, err)
|
||||
}
|
||||
}
|
||||
|
||||
type askerFunc func(accept, id string, body any) error
|
||||
|
||||
func (f askerFunc) AskStep(accept, id string, body any) error { return f(accept, id, body) }
|
||||
@@ -359,7 +316,7 @@ func TestARecoverysStepsAreAskedOnTheStreamDelivery(t *testing.T) {
|
||||
}{{true, "mesh.seat.node-build-go.accept.delivery.mesh-pipeline-runner," + wants.AcceptSubjectStep}, {false, "mesh.seat.node-build-go.accept.check.mesh-pipeline-runner," + wants.AcceptSubjectStep}} {
|
||||
var to []string
|
||||
asker := askerFunc(func(accept, _ string, _ any) error { to = append(to, accept); return nil })
|
||||
if err := askAll(asker, nil, "k", asks, c.recovery); err != nil || strings.Join(to, ",") != c.want {
|
||||
if err := askAll(asker, "k", asks, c.recovery); err != nil || strings.Join(to, ",") != c.want {
|
||||
t.Errorf("recovery %v: asked on %v (%v), want %s", c.recovery, to, err, c.want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ func (h *Hearer) Taken(ask, node string) error {
|
||||
// whose fingerprint newer's commit changed, and for a publish's pipeline each an older publish of the package started
|
||||
// (design 47 G §31, §119; ADR 0666 §9; A-202): the pipeline and each step not ended
|
||||
// `superseded`, naming the newer commit, and it says pipeline-ended. A module the newer commit left as it was finishes its
|
||||
// pipeline. The ask of each superseded step on a build seat that serves `drop` is dropped (drop; its bound deleted through
|
||||
// unbound); a step on mesh-builds or mesh-wants, whose seats serve no drop, is only ended superseded (A-182). A run on
|
||||
// pipeline. The ask of each superseded step on a build seat that serves `drop` is dropped (drop); a step of a test run leaves
|
||||
// it, its ask dropped only with its last reader (§726); a step on mesh-builds or mesh-wants, whose seats serve no drop, is only ended superseded (A-182). A run on
|
||||
// request's pipeline neither supersedes nor is superseded. It says how many pipelines it ended.
|
||||
func (h *Hearer) Supersede(newer seat.Pipeline, drop Drop, unbound func(ask string) error) (int, error) {
|
||||
func (h *Hearer) Supersede(newer seat.Pipeline, drop Drop) (int, error) {
|
||||
if newer.Run != "" || newer.Source <= 0 {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func (h *Hearer) Supersede(newer seat.Pipeline, drop Drop, unbound func(ask stri
|
||||
if key == newer.Pipeline {
|
||||
continue
|
||||
}
|
||||
done, err := h.supersedeOne(key, newer, why, drop, unbound)
|
||||
done, err := h.supersedeOne(key, newer, why, drop)
|
||||
if err != nil && first == nil {
|
||||
first = err
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func supersededWhy(newer seat.Pipeline) string {
|
||||
return fmt.Sprintf("the newer commit %s of %s changed %s's fingerprint", newer.Commit, newer.Branch, newer.Module)
|
||||
}
|
||||
|
||||
func (h *Hearer) supersedeOne(key string, newer seat.Pipeline, why string, drop Drop, unbound func(string) error) (bool, error) {
|
||||
func (h *Hearer) supersedeOne(key string, newer seat.Pipeline, why string, drop Drop) (bool, error) {
|
||||
for {
|
||||
p, rev, err := h.Store.Get(key)
|
||||
if err != nil || !superseded(p, newer) {
|
||||
@@ -146,11 +146,6 @@ func (h *Hearer) supersedeOne(key string, newer seat.Pipeline, why string, drop
|
||||
h.logf("the drop of ask %s of the superseded %s is not answered: %v", s.Ask, key, err)
|
||||
}
|
||||
}
|
||||
if unbound != nil {
|
||||
if err := unbound(s.Ask); err != nil {
|
||||
h.logf("the bound of ask %s of the superseded %s is not dropped: %v", s.Ask, key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := h.said(p, false, true); err != nil && first == nil {
|
||||
first = err
|
||||
|
||||
@@ -29,7 +29,6 @@ func TestSupersede(t *testing.T) {
|
||||
}
|
||||
type dropped struct{ seat, node, ask string }
|
||||
var drops []dropped
|
||||
var unbound []string
|
||||
drop := func(s, node, ask, why string) error {
|
||||
if !strings.Contains(why, "c2") {
|
||||
t.Errorf("the drop of %s names no newer commit: %q", ask, why)
|
||||
@@ -37,7 +36,6 @@ func TestSupersede(t *testing.T) {
|
||||
drops = append(drops, dropped{s, node, ask})
|
||||
return nil
|
||||
}
|
||||
unbind := func(ask string) error { unbound = append(unbound, ask); return nil }
|
||||
newer := func(key string, source int64, fp string, run string, pub *seat.Published) seat.Pipeline {
|
||||
return seat.Pipeline{Pipeline: key, Branch: "main", Source: source, Module: "app", Commit: "c2", Fingerprint: fp, Run: run, Published: pub,
|
||||
Outcome: seat.PipelineOutcomeRunning}
|
||||
@@ -50,12 +48,12 @@ func TestSupersede(t *testing.T) {
|
||||
{"a run on request", newer("main.r1.app", 6, "src2:bb", "r1", nil)},
|
||||
{"an older source revision", newer("main.4.app", 4, "src2:bb", "", nil)},
|
||||
} {
|
||||
if n, err := h.Supersede(c.newer, drop, unbind); n != 0 || err != nil {
|
||||
if n, err := h.Supersede(c.newer, drop); n != 0 || err != nil {
|
||||
t.Errorf("%s superseded %d (%v)", c.name, n, err)
|
||||
}
|
||||
}
|
||||
*said = nil
|
||||
if n, err := h.Supersede(newer("main.6.app", 6, "src2:bb", "", nil), drop, unbind); n != 1 || err != nil {
|
||||
if n, err := h.Supersede(newer("main.6.app", 6, "src2:bb", "", nil), drop); n != 1 || err != nil {
|
||||
t.Fatalf("a changed fingerprint superseded %d (%v)", n, err)
|
||||
}
|
||||
p, _, _ := store.Get(pkey)
|
||||
@@ -68,13 +66,13 @@ func TestSupersede(t *testing.T) {
|
||||
}
|
||||
}
|
||||
want := []dropped{{nodebuildgo.Seat, "n7", "a1"}, {nodebuildgo.Seat, "", "a2"}}
|
||||
if !slices.Equal(drops, want) || !slices.Equal(unbound, []string{"a1", "a2"}) {
|
||||
t.Errorf("dropped %+v and unbound %v, want %+v (the mesh-builds step only ended)", drops, unbound, want)
|
||||
if !slices.Equal(drops, want) {
|
||||
t.Errorf("dropped %+v, want %+v (the mesh-builds step only ended)", drops, want)
|
||||
}
|
||||
if n := len(*said); n != 5 || (*said)[4] != seat.EventPipelineEnded+".app.main.c1" {
|
||||
t.Errorf("said %v, want four step-ended then pipeline-ended", *said)
|
||||
}
|
||||
if n, _ := h.Supersede(newer("main.7.app", 7, "src2:cc", "", nil), drop, unbind); n != 0 {
|
||||
if n, _ := h.Supersede(newer("main.7.app", 7, "src2:cc", "", nil), drop); n != 0 {
|
||||
t.Errorf("a superseded pipeline was superseded again: %d", n)
|
||||
}
|
||||
|
||||
@@ -82,10 +80,10 @@ func TestSupersede(t *testing.T) {
|
||||
pub := memStore{"main.5.lib": {p: seat.Pipeline{Pipeline: "main.5.lib", Branch: "main", Source: 5, Module: "lib", Fingerprint: "src2:aa",
|
||||
Outcome: seat.PipelineOutcomeRunning, Published: &seat.Published{Artifact: "core:pkg", Version: "v1"}}, rev: 1}}
|
||||
h.Store = pub
|
||||
if n, _ := h.Supersede(newer("main.6.app", 6, "src2:aa", "", &seat.Published{Artifact: "core:pkg", Version: "v1"}), drop, unbind); n != 0 {
|
||||
if n, _ := h.Supersede(newer("main.6.app", 6, "src2:aa", "", &seat.Published{Artifact: "core:pkg", Version: "v1"}), drop); n != 0 {
|
||||
t.Errorf("a publish of the same version superseded %d", n)
|
||||
}
|
||||
if n, err := h.Supersede(newer("main.6.app", 6, "src2:aa", "", &seat.Published{Artifact: "core:pkg", Version: "v2"}), drop, unbind); n != 1 || err != nil {
|
||||
if n, err := h.Supersede(newer("main.6.app", 6, "src2:aa", "", &seat.Published{Artifact: "core:pkg", Version: "v2"}), drop); n != 1 || err != nil {
|
||||
t.Fatalf("a newer publish superseded %d (%v)", n, err)
|
||||
}
|
||||
if p, _, _ := pub.Get("main.5.lib"); p.Outcome != seat.PipelineOutcomeSuperseded || !strings.Contains(p.Why, "v2") {
|
||||
@@ -105,9 +103,6 @@ func TestBoundDrop(t *testing.T) {
|
||||
if _, _, ok := ParseDropBound("step-ab"); ok {
|
||||
t.Error("an ask's bound was read as a drop's")
|
||||
}
|
||||
if IsAskKey(DropBoundKey("s", "step-ab")) {
|
||||
t.Error("a drop's bound was taken for an ask's")
|
||||
}
|
||||
err := BoundDrop(func(string, string, string, string) error { return nil }, arm, done)(nodebuildgo.Seat, "n1", "step-ab", "why")
|
||||
if err != nil || len(armed) != 1 || armed[0] != "drop."+nodebuildgo.Seat+".step-ab" || len(answered) != 1 {
|
||||
t.Errorf("an answered drop: %v, armed %v, answered %v", err, armed, answered)
|
||||
|
||||
@@ -262,13 +262,13 @@ func TestATestRunsEndMovesEveryReaderAndIsCountedOnce(t *testing.T) {
|
||||
}
|
||||
// a, superseded, leaves the lint run to b's readers; b, superseded after, leaves none: the ask is dropped and the run ends.
|
||||
lint := stepNamed(a, "app:program", "lint")
|
||||
if _, err := f.h.Supersede(seat.Pipeline{Pipeline: "main.5.app", Branch: "main", Source: 5, Module: "app", Commit: "c2", Fingerprint: "src2:bb"}, nil, nil); err != nil {
|
||||
if _, err := f.h.Supersede(seat.Pipeline{Pipeline: "main.5.app", Branch: "main", Source: 5, Module: "app", Commit: "c2", Fingerprint: "src2:bb"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r, _, _ := f.runs.Get(lint.Shared[0].Run); r.Ended != nil || len(r.Readers) != 2 || len(f.drops) != 0 {
|
||||
t.Fatalf("after a left the lint run = %+v, drops %v; want it running for b's two readers", r, f.drops)
|
||||
}
|
||||
if _, err := f.h.Supersede(seat.Pipeline{Pipeline: "main.7.app", Branch: "main", Source: 7, Module: "app", Commit: "c3", Fingerprint: "src2:cc"}, nil, nil); err != nil {
|
||||
if _, err := f.h.Supersede(seat.Pipeline{Pipeline: "main.7.app", Branch: "main", Source: 7, Module: "app", Commit: "c3", Fingerprint: "src2:cc"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r, _, _ := f.runs.Get(lint.Shared[0].Run); r.Outcome != seat.StepResultOutcomeCouldNotRun || r.Said != NoReaderLeft || len(f.drops) != 2 || f.drops[0] != "node-build-go "+lint.Ask {
|
||||
|
||||
@@ -27,8 +27,6 @@ type Verbs struct {
|
||||
Candidate func(group, branch string, revision int64) (Half, error)
|
||||
// Acts records a hand act before the verb does it (rerun, accept, cancel); a nil Acts refuses the verb, nothing recorded.
|
||||
Acts views.HandActs
|
||||
// Drop drops the bound of an ask a cancelled pipeline no longer waits on.
|
||||
Drop func(ask string) error
|
||||
}
|
||||
|
||||
func (v Verbs) now() time.Time { return v.Hearer.now() }
|
||||
@@ -185,8 +183,8 @@ func (v Verbs) Accept(caller string, in seat.AcceptInput) (seat.AcceptAnswer, er
|
||||
return seat.AcceptAnswer{Result: p.Steps[i]}, nil
|
||||
}
|
||||
|
||||
// Cancel ends a running pipeline `cancelled`, each step not ended cancelled and the bound of each ask dropped, recorded in
|
||||
// the hand-act log first (§394); it says pipeline-ended.
|
||||
// Cancel ends a running pipeline `cancelled`, each step not ended cancelled and each step of a test run leaving it, recorded
|
||||
// in the hand-act log first (§394, §726); it says pipeline-ended.
|
||||
func (v Verbs) Cancel(caller string, in seat.CancelInput) (seat.CancelAnswer, error) {
|
||||
h := v.Hearer
|
||||
recorded := false
|
||||
@@ -205,7 +203,6 @@ func (v Verbs) Cancel(caller string, in seat.CancelInput) (seat.CancelAnswer, er
|
||||
recorded = true
|
||||
}
|
||||
now := h.now()
|
||||
var drop []string
|
||||
var leave []seat.StepResult
|
||||
for i := range p.Steps {
|
||||
s := &p.Steps[i]
|
||||
@@ -215,9 +212,6 @@ func (v Verbs) Cancel(caller string, in seat.CancelInput) (seat.CancelAnswer, er
|
||||
if sharedRun(*s) != "" && s.Seat != wants.Seat {
|
||||
leave = append(leave, *s) // it leaves its test run, dropped only with the last reader (§726)
|
||||
}
|
||||
if s.Ask != "" {
|
||||
drop = append(drop, s.Ask)
|
||||
}
|
||||
s.Outcome, s.By, s.Why, s.Ended = seat.StepResultOutcomeCancelled, caller, in.Why, &now
|
||||
}
|
||||
p.Outcome, p.Why, p.Ended = seat.PipelineOutcomeCancelled, in.Why, &now
|
||||
@@ -230,13 +224,6 @@ func (v Verbs) Cancel(caller string, in seat.CancelInput) (seat.CancelAnswer, er
|
||||
for _, s := range leave {
|
||||
h.leaveRun(in.Pipeline, s, "the pipeline "+in.Pipeline+" is cancelled: "+in.Why)
|
||||
}
|
||||
if v.Drop != nil {
|
||||
for _, ask := range drop {
|
||||
if err := v.Drop(ask); err != nil {
|
||||
h.logf("the bound of ask %s of the cancelled %s is not dropped: %v", ask, in.Pipeline, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return seat.CancelAnswer{Pipeline: p}, h.said(p, false, true)
|
||||
}
|
||||
}
|
||||
@@ -296,7 +283,7 @@ func (v Verbs) Rerun(caller string, in seat.RerunInput) (seat.RerunAnswer, error
|
||||
v.Hearer.pin(p) // a pipeline that runs again keeps its revision again (A-449)
|
||||
if ask != nil {
|
||||
v.Starter.carry(in.Pipeline, []Asked{*ask})
|
||||
if err := askAll(v.Starter.Steps, v.Starter.Arm, in.Pipeline, []Asked{*ask}, v.Starter.recovered(in.Pipeline, p.Commit)); err != nil {
|
||||
if err := askAll(v.Starter.Steps, in.Pipeline, []Asked{*ask}, v.Starter.recovered(in.Pipeline, p.Commit)); err != nil {
|
||||
return seat.RerunAnswer{}, fmt.Errorf("the step is written running but not asked, it is asked again at the next start: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,9 @@ func verbsFixture() (Verbs, memStore, *[]string, *stepAsks, *actLog, *[]string)
|
||||
asks, acts, dropped := &stepAsks{}, &actLog{}, &[]string{}
|
||||
s := &Starter{Steps: asks, Name: "the-runner", Registration: func(string) (catalog.Registration, bool) { return reg, true },
|
||||
Now: h.Now}
|
||||
return Verbs{Hearer: h, Starter: s, View: func(string) (Half, bool) { return Half{Entries: entries}, true }, Acts: acts,
|
||||
Drop: func(ask string) error { *dropped = append(*dropped, ask); return nil }}, store, said, asks, acts, dropped
|
||||
h.DropRun = func(_, _, ask, _ string) error { *dropped = append(*dropped, ask); return nil }
|
||||
return Verbs{Hearer: h, Starter: s, View: func(string) (Half, bool) { return Half{Entries: entries}, true }, Acts: acts},
|
||||
store, said, asks, acts, dropped
|
||||
}
|
||||
|
||||
func stepNamed(p seat.Pipeline, artifact, step string) seat.StepResult {
|
||||
@@ -81,7 +82,8 @@ func TestReviewEndsThePlacedReviewStepWithItsProvenCaller(t *testing.T) {
|
||||
|
||||
// accept takes only a failed optional step, writes its hand act first, and refuses without one; rerun asks the step again
|
||||
// under a new ask saying it is a rerun and its caller, reopens a failed pipeline and asks nothing of a refused one; cancel ends
|
||||
// a running pipeline cancelled, each step cancelled and each ask's bound dropped (design 47 G §22, §30, §325, §394).
|
||||
// a running pipeline cancelled, each step cancelled, no ask's bound left to drop (design 47 G §22, §30, §325, §394; §647 as
|
||||
// A-466y amends it).
|
||||
func TestAcceptRerunAndCancelWriteByCompareAndSetAndRecordTheirHandAct(t *testing.T) {
|
||||
v, store, said, asks, acts, dropped := verbsFixture()
|
||||
end := func(step, outcome string) {
|
||||
@@ -134,7 +136,7 @@ func TestAcceptRerunAndCancelWriteByCompareAndSetAndRecordTheirHandAct(t *testin
|
||||
}
|
||||
// A cancel ends the pipeline cancelled and drops the bounds of the asks still held.
|
||||
c, err := v.Cancel("operator", seat.CancelInput{Pipeline: pkey, Why: "wrong branch"})
|
||||
if err != nil || c.Pipeline.Outcome != "cancelled" || c.Pipeline.EndCount != 1 || len(*dropped) == 0 {
|
||||
if err != nil || c.Pipeline.Outcome != "cancelled" || c.Pipeline.EndCount != 1 || len(*dropped) != 0 {
|
||||
t.Fatalf("cancel = %+v, %v, dropped %v", c.Pipeline, err, *dropped)
|
||||
}
|
||||
if s := stepNamed(c.Pipeline, "app:program", "lint"); s.Outcome != "cancelled" || s.By != "operator" {
|
||||
|
||||
@@ -85,7 +85,9 @@ func TestManifest(t *testing.T) {
|
||||
"node-build-go.step-progress", "node-build-node.step-progress", "node-build-image.step-progress", "mesh-wants.step-ended", "mesh-catalog.registration-changed",
|
||||
"mesh-catalog.catalog-revision", "mesh-conditions.findings-asked", "mesh-delivery.recovery-merged",
|
||||
// A-186: the seat list its write verbs' callers are checked against, heard as it changes.
|
||||
"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed"})},
|
||||
"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed",
|
||||
// §647 as A-466z amends it: no holder is read from the seat-holders view.
|
||||
"seat:mesh-module-assigner.views.seat-holders"})},
|
||||
// RN2 (§21, §195, §200, §77): the registrations and the catalog half asked by their verbs, the first views read and
|
||||
// asked again by hand (a hand act).
|
||||
{"invokes", equalSets(m.Invokes, []string{"seat:mesh-catalog.registrations",
|
||||
|
||||
@@ -50,7 +50,8 @@
|
||||
"mesh-conditions.findings-asked",
|
||||
"mesh-delivery.recovery-merged",
|
||||
"mesh-catalog.seat-definition-changed",
|
||||
"mesh-catalog.seat-definition-removed"
|
||||
"mesh-catalog.seat-definition-removed",
|
||||
"seat:mesh-module-assigner.views.seat-holders"
|
||||
],
|
||||
"invokes": [
|
||||
"seat:mesh-catalog.seat-definitions",
|
||||
|
||||
Reference in New Issue
Block a user