Merge pull request 'A failed mover is started again at the head; a reopening pins its revision again (H-A-479)' (#331) from fix/runner-start-modules into main
This commit was merged in pull request #331.
This commit is contained in:
@@ -14,13 +14,13 @@ const Seat = "mesh-pipeline-runner"
|
||||
|
||||
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
|
||||
// a reader of a value of another form says "form N, this reader knows M".
|
||||
const Form = 7
|
||||
const Form = 8
|
||||
|
||||
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
|
||||
// whose fields changed while its forms did not (design 47 H2 §780).
|
||||
const (
|
||||
generatedForms = "7"
|
||||
generatedFieldsDigest = "AcceptAnswer=224df0394653 Accepted=d2b011e5090f AskAgainAnswer=224df0394653 CancelAnswer=a0dcc32b3f57 EndAgainAnswer=a0dcc32b3f57 FailedStep=cd7184342136 Fill=7a76c9ceb157 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 KeptAnswer=dfe0d48bc169 KeptByLevelDigestValue=f06c90f7da7f KeptResult=af5f81f189b7 ListAnswer=284210b3c054 LogEntry=b059967b2ae4 Member=8a103baec01f Mover=5db376275bcf MoverEnded=4b35095f6829 MoverRow=b61f41d131a3 Pipeline=2663792125bf PipelineEnded=523f8fc0fe41 PipelineEndedEvent=cb44007f7173 PipelineEndedPhases=9d1c33ce4cc4 PipelineEndedPhasesBuild=a08d49692a09 PipelineEndedPhasesComposition=a08d49692a09 PipelineEndedPhasesIntegration=a08d49692a09 PipelineEndedPhasesLint=a08d49692a09 PipelineEndedPhasesUnit=a08d49692a09 PipelineEndedPhasesValidate=a08d49692a09 PipelineRow=f58dbdcaf2d4 PipelineStarted=a3d000f095db PipelineStartedEvent=eaa401af4117 PipelinesByBranchRevisionUnfinishedModuleValue=693580eed498 PipelinesByBranchRevisionValue=693580eed498 PipelinesByBranchRunRunValue=693580eed498 PipelinesByBranchSourcePublishedPackageVersionValue=693580eed498 PipelinesByStepsPipelineMoverValue=94de99db7816 PlaceAnswer=a0dcc32b3f57 PlaceUnfinishedAnswer=ed94ced4513a Published=d9af3024dacc QueueByQueueNextValue=765a2918a728 QueueByRunningPipelineValue=ed94ced4513a QueueByWaitingSequenceValue=99605298ae13 RePinnedEvent=92fd04bfa6d3 RerunAnswer=9b7efd0df344 ReviewAnswer=f397b8965179 RoomEvent=5bd4df78ed84 RunAnswer=96bd45aa2e62 RunStarted=b280617410c3 RunStartedEvent=0767a9358fa3 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 ShowAnswer=48b8cecc529a StandsAnswer=0afa3693bf3b StartAnswer=ed94ced4513a StepEndedEvent=799020642c19 StepEvent=64f18c40ed5d StepLogByPipelineValue=ffdde090a101 StepResult=0dac0e15d017 StepStartedEvent=799020642c19 TestCounts=9c1332427159 TestRun=ca5a87f3b6b8 TestRunPackage=a7d30558470d TestRunReader=c9b30cc4d0d0 TestRunsAnswer=7ab81a45ca33 TestRunsDropAnswer=8ee70b35469d ToolchainUsed=43b6d42376fb Wait=21e4ee7a3ef1 WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 Waiting=ed94ced4513a WhyCarriedAnswer=8e2fcea6479f Widening=e2790a307466"
|
||||
generatedForms = "8"
|
||||
generatedFieldsDigest = "AcceptAnswer=224df0394653 Accepted=d2b011e5090f AskAgainAnswer=224df0394653 CancelAnswer=a0dcc32b3f57 EndAgainAnswer=a0dcc32b3f57 FailedStep=cd7184342136 Fill=7a76c9ceb157 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 KeptAnswer=dfe0d48bc169 KeptByLevelDigestValue=f06c90f7da7f KeptResult=af5f81f189b7 ListAnswer=284210b3c054 LogEntry=b059967b2ae4 Member=8a103baec01f Mover=5db376275bcf MoverEnded=4b35095f6829 MoverRow=b61f41d131a3 Pipeline=2663792125bf PipelineEnded=523f8fc0fe41 PipelineEndedEvent=cb44007f7173 PipelineEndedPhases=9d1c33ce4cc4 PipelineEndedPhasesBuild=a08d49692a09 PipelineEndedPhasesComposition=a08d49692a09 PipelineEndedPhasesIntegration=a08d49692a09 PipelineEndedPhasesLint=a08d49692a09 PipelineEndedPhasesUnit=a08d49692a09 PipelineEndedPhasesValidate=a08d49692a09 PipelineRow=f58dbdcaf2d4 PipelineStarted=a3d000f095db PipelineStartedEvent=eaa401af4117 PipelinesByBranchRevisionAgainNValue=693580eed498 PipelinesByBranchRevisionUnfinishedModuleValue=693580eed498 PipelinesByBranchRevisionValue=693580eed498 PipelinesByBranchRunRunValue=693580eed498 PipelinesByBranchSourcePublishedPackageVersionValue=693580eed498 PipelinesByStepsPipelineMoverValue=94de99db7816 PlaceAnswer=a0dcc32b3f57 PlaceUnfinishedAnswer=ed94ced4513a Published=d9af3024dacc QueueByQueueNextValue=765a2918a728 QueueByRunningPipelineValue=ed94ced4513a QueueByWaitingSequenceValue=99605298ae13 RePinnedEvent=92fd04bfa6d3 RerunAnswer=9b7efd0df344 ReviewAnswer=f397b8965179 RoomEvent=5bd4df78ed84 RunAnswer=96bd45aa2e62 RunStarted=b280617410c3 RunStartedEvent=0767a9358fa3 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 ShowAnswer=48b8cecc529a StandsAnswer=0afa3693bf3b StartAnswer=ed94ced4513a StepEndedEvent=799020642c19 StepEvent=64f18c40ed5d StepLogByPipelineValue=ffdde090a101 StepResult=0dac0e15d017 StepStartedEvent=799020642c19 TestCounts=9c1332427159 TestRun=ca5a87f3b6b8 TestRunPackage=a7d30558470d TestRunReader=c9b30cc4d0d0 TestRunsAnswer=7ab81a45ca33 TestRunsDropAnswer=8ee70b35469d ToolchainUsed=43b6d42376fb Wait=21e4ee7a3ef1 WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 Waiting=ed94ced4513a WhyCarriedAnswer=8e2fcea6479f Widening=e2790a307466"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -69,7 +69,7 @@ func VerbDescription(verb string) string {
|
||||
case VerbRun:
|
||||
return "The run on request of one or more members, each a module at a named commit, through their pipelines; delivers nothing, replacing the checker's try (ADR 0666 section 18). Says run-started."
|
||||
case VerbStart:
|
||||
return "A delivering pipeline for a watched branch's head, by hand; written in the hand-act log."
|
||||
return "A delivering pipeline for a watched branch's head, by hand; written in the hand-act log. With modules, a pipeline at the head keyed <branch>.<revision>.again.<n> carrying the named modules whose newest entry has no passed pipeline, at the take-in's tiers; a module whose newest entry passed is refused by name. Exactly one of module or modules (design 47 H2 H-A-479)."
|
||||
case VerbShow:
|
||||
return "One pipeline: naming a mover, its steps alone; with no mover, each mover's row (its module, outcome and failed step), never every step of every mover, or the steps of any mover the step and state filters hold; and its step log, with the stores' fill (design 47 H2 §789, H-A-376). Reads only."
|
||||
case VerbList:
|
||||
@@ -354,6 +354,44 @@ func DecodePipelinesByBranchRevisionUnfinishedModuleValue(raw []byte) (Pipelines
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// PipelinesByBranchRevisionAgainNKey is the key of one value of the state pipelines under the form "<branch>.<revision>.again.<n>".
|
||||
func PipelinesByBranchRevisionAgainNKey(branch, revision, n string) string {
|
||||
return branch + "." + revision + ".again." + n
|
||||
}
|
||||
|
||||
// ParsePipelinesByBranchRevisionAgainNKey reads the parts of a key of the form "<branch>.<revision>.again.<n>", in the order of the form; the last result is false for a key of another form.
|
||||
func ParsePipelinesByBranchRevisionAgainNKey(key string) (string, string, string, bool) {
|
||||
rest := key
|
||||
v0, after0, found0 := strings.Cut(rest, ".")
|
||||
if !found0 || v0 == "" {
|
||||
return "", "", "", false
|
||||
}
|
||||
rest = after0
|
||||
v2, after2, found2 := strings.Cut(rest, ".again.")
|
||||
if !found2 || v2 == "" {
|
||||
return "", "", "", false
|
||||
}
|
||||
rest = after2
|
||||
if rest == "" {
|
||||
return "", "", "", false
|
||||
}
|
||||
v4 := rest
|
||||
rest = ""
|
||||
if rest != "" {
|
||||
return "", "", "", false
|
||||
}
|
||||
return v0, v2, v4, true
|
||||
}
|
||||
|
||||
// DecodePipelinesByBranchRevisionAgainNValue reads one value of the state pipelines under the form "<branch>.<revision>.again.<n>" as another part wrote it: a field PipelinesByBranchRevisionAgainNValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
|
||||
func DecodePipelinesByBranchRevisionAgainNValue(raw []byte) (PipelinesByBranchRevisionAgainNValue, int, error) {
|
||||
var v PipelinesByBranchRevisionAgainNValue
|
||||
if err := json.Unmarshal(raw, &v); err != nil {
|
||||
return v, 0, err
|
||||
}
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// PipelinesByStepsPipelineMoverKey is the key of one value of the state pipelines under the form "steps.<pipeline>.<mover>".
|
||||
func PipelinesByStepsPipelineMoverKey(pipeline, mover string) string {
|
||||
return "steps." + pipeline + "." + mover
|
||||
@@ -1244,7 +1282,10 @@ type RunAnswer struct {
|
||||
// StartInput is what start takes.
|
||||
type StartInput struct {
|
||||
Branch string `json:"branch"`
|
||||
Module string `json:"module"`
|
||||
// the one mover of the head's pipeline <branch>.<revision>; absent when modules is given
|
||||
Module string `json:"module,omitempty"`
|
||||
// the modules started again at the head, each whose newest entry has no passed pipeline (a failed, cut or superseded one); absent when module is given (design 47 H2 H-A-479)
|
||||
Modules []string `json:"modules,omitempty"`
|
||||
// why, written with the caller the runtime proves in the hand-act log
|
||||
Why string `json:"why"`
|
||||
}
|
||||
@@ -1637,6 +1678,9 @@ type PipelinesByBranchRunRunValue = Pipeline
|
||||
// PipelinesByBranchRevisionUnfinishedModuleValue is one value of the state pipelines under the key <branch>.<revision>.unfinished.<module>.
|
||||
type PipelinesByBranchRevisionUnfinishedModuleValue = Pipeline
|
||||
|
||||
// PipelinesByBranchRevisionAgainNValue is one value of the state pipelines under the key <branch>.<revision>.again.<n>.
|
||||
type PipelinesByBranchRevisionAgainNValue = Pipeline
|
||||
|
||||
// PipelinesByStepsPipelineMoverValue is one value of the state pipelines under the key steps.<pipeline>.<mover>.
|
||||
type PipelinesByStepsPipelineMoverValue struct {
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
|
||||
@@ -50,12 +50,20 @@
|
||||
},
|
||||
{
|
||||
"name": "start",
|
||||
"description": "A delivering pipeline for a watched branch's head, by hand; written in the hand-act log.",
|
||||
"description": "A delivering pipeline for a watched branch's head, by hand; written in the hand-act log. With modules, a pipeline at the head keyed <branch>.<revision>.again.<n> carrying the named modules whose newest entry has no passed pipeline, at the take-in's tiers; a module whose newest entry passed is refused by name. Exactly one of module or modules (design 47 H2 H-A-479).",
|
||||
"input": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"module": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"description": "the one mover of the head's pipeline <branch>.<revision>; absent when modules is given"
|
||||
},
|
||||
"modules": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "the modules started again at the head, each whose newest entry has no passed pipeline (a failed, cut or superseded one); absent when module is given (design 47 H2 H-A-479)"
|
||||
},
|
||||
"branch": {
|
||||
"type": "string"
|
||||
@@ -66,7 +74,6 @@
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"module",
|
||||
"branch",
|
||||
"why"
|
||||
]
|
||||
@@ -910,6 +917,13 @@
|
||||
},
|
||||
"description": "a pipeline of its own of one mover kept in the runner's state unfinished, put in it by place-unfinished; the revision the unfinished entry names (design 47 H2 §86, H-A-398)"
|
||||
},
|
||||
{
|
||||
"key": "<branch>.<revision>.again.<n>",
|
||||
"value": {
|
||||
"$ref": "#/defs/Pipeline"
|
||||
},
|
||||
"description": "a pipeline started again at the head by start with modules, its movers the named modules whose newest entry has no passed pipeline; n from 1, taken by writing on absence (design 47 H2 H-A-479)"
|
||||
},
|
||||
{
|
||||
"key": "steps.<pipeline>.<mover>",
|
||||
"value": {
|
||||
@@ -2353,5 +2367,5 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"form": 7
|
||||
"form": 8
|
||||
}
|
||||
|
||||
@@ -121,6 +121,12 @@ export declare function pipelinesByBranchRevisionUnfinishedModuleKey(branch: str
|
||||
/** The parts of a key of the form "<branch>.<revision>.unfinished.<module>", or undefined for a key of another form. */
|
||||
export declare function parsePipelinesByBranchRevisionUnfinishedModuleKey(_key: string): { branch: string; revision: string; module: string } | undefined;
|
||||
|
||||
/** The key of one value of the state pipelines under the form "<branch>.<revision>.again.<n>". */
|
||||
export declare function pipelinesByBranchRevisionAgainNKey(branch: string, revision: string, n: string): string;
|
||||
|
||||
/** The parts of a key of the form "<branch>.<revision>.again.<n>", or undefined for a key of another form. */
|
||||
export declare function parsePipelinesByBranchRevisionAgainNKey(_key: string): { branch: string; revision: string; n: string } | undefined;
|
||||
|
||||
/** The key of one value of the state pipelines under the form "steps.<pipeline>.<mover>". */
|
||||
export declare function pipelinesByStepsPipelineMoverKey(pipeline: string, mover: string): string;
|
||||
|
||||
@@ -699,7 +705,10 @@ export interface RunAnswer {
|
||||
/** is what start takes. */
|
||||
export interface StartInput {
|
||||
"branch": string;
|
||||
"module": string;
|
||||
/** the one mover of the head's pipeline <branch>.<revision>; absent when modules is given */
|
||||
"module"?: string;
|
||||
/** the modules started again at the head, each whose newest entry has no passed pipeline (a failed, cut or superseded one); absent when module is given (design 47 H2 H-A-479) */
|
||||
"modules"?: string[];
|
||||
/** why, written with the caller the runtime proves in the hand-act log */
|
||||
"why": string;
|
||||
}
|
||||
@@ -1031,6 +1040,9 @@ export type PipelinesByBranchRunRunValue = Pipeline;
|
||||
/** is one value of the state pipelines under the key <branch>.<revision>.unfinished.<module>. */
|
||||
export type PipelinesByBranchRevisionUnfinishedModuleValue = Pipeline;
|
||||
|
||||
/** is one value of the state pipelines under the key <branch>.<revision>.again.<n>. */
|
||||
export type PipelinesByBranchRevisionAgainNValue = Pipeline;
|
||||
|
||||
/** is one value of the state pipelines under the key steps.<pipeline>.<mover>. */
|
||||
export interface PipelinesByStepsPipelineMoverValue {
|
||||
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
|
||||
|
||||
@@ -199,6 +199,29 @@ export function parsePipelinesByBranchRevisionUnfinishedModuleKey(_key) {
|
||||
return { branch, revision, module };
|
||||
}
|
||||
|
||||
/** The key of one value of the state pipelines under the form "<branch>.<revision>.again.<n>". */
|
||||
export function pipelinesByBranchRevisionAgainNKey(branch, revision, n) {
|
||||
return branch + "." + revision + ".again." + n;
|
||||
}
|
||||
|
||||
/** The parts of a key of the form "<branch>.<revision>.again.<n>", or undefined for a key of another form. */
|
||||
export function parsePipelinesByBranchRevisionAgainNKey(_key) {
|
||||
let _rest = _key;
|
||||
const _at0 = _rest.indexOf(".");
|
||||
if (_at0 <= 0) return undefined;
|
||||
const branch = _rest.slice(0, _at0);
|
||||
_rest = _rest.slice(_at0 + 1);
|
||||
const _at2 = _rest.indexOf(".again.");
|
||||
if (_at2 <= 0) return undefined;
|
||||
const revision = _rest.slice(0, _at2);
|
||||
_rest = _rest.slice(_at2 + 7);
|
||||
if (_rest === "") return undefined;
|
||||
const n = _rest;
|
||||
_rest = "";
|
||||
if (_rest !== "") return undefined;
|
||||
return { branch, revision, n };
|
||||
}
|
||||
|
||||
/** The key of one value of the state pipelines under the form "steps.<pipeline>.<mover>". */
|
||||
export function pipelinesByStepsPipelineMoverKey(pipeline, mover) {
|
||||
return "steps." + pipeline + "." + mover;
|
||||
|
||||
@@ -105,9 +105,14 @@ func (ix *Indexer) HeardPins(ctx context.Context, started *runner.PipelineStarte
|
||||
}
|
||||
}
|
||||
}
|
||||
// A pipeline that did not pass withdraws the reservations its revision holds (design 47 H2 §805, H-A-418 (1)).
|
||||
// A pipeline that did not pass withdraws the reservations its revision holds of its own movers, never another open
|
||||
// pipeline's at that revision (design 47 H2 §805, H-A-418 (1), H-A-479 second addendum).
|
||||
if ended.Outcome != runner.PipelineEndedOutcomePassed {
|
||||
if err := ix.Withdraw(ctx, ended.Branch, ended.Revision); err != nil {
|
||||
movers := make([]string, 0, len(ended.Movers))
|
||||
for _, m := range ended.Movers {
|
||||
movers = append(movers, m.Module)
|
||||
}
|
||||
if err := ix.Withdraw(ctx, ended.Branch, ended.Revision, movers); err != nil {
|
||||
return fmt.Errorf("the reservations of %s are not withdrawn: %w", BranchObject(ended.Branch, ended.Revision), err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -151,7 +152,14 @@ func TestAReleaseRepinsAnEntryNamingItsPackageWithNoPin(t *testing.T) {
|
||||
if err := ix.Settle(ctx, next); err != nil || newest() != 4 {
|
||||
t.Fatalf("the reservation of 0.1.29 settled (%v) keeping main's newest %d, want 4", err, newest())
|
||||
}
|
||||
if err := ix.Withdraw(ctx, "main", 3); err != nil || newest() != 5 {
|
||||
// H-A-479 second addendum: a pipeline at the same revision whose movers are others withdraws none of mesh-sdk's.
|
||||
if err := ix.Withdraw(ctx, "main", 3, []string{"app"}); err != nil || newest() != 4 {
|
||||
t.Fatalf("another pipeline's withdrawal (%v) kept main's newest %d, want 4: nothing of mesh-sdk withdrawn", err, newest())
|
||||
}
|
||||
if _, _, kept, _ := heard.Get(ctx, ReservedKey(next, "mesh-sdk")); !kept {
|
||||
t.Fatalf("another pipeline's withdrawal took mesh-sdk's reservation")
|
||||
}
|
||||
if err := ix.Withdraw(ctx, "main", 3, []string{"mesh-sdk"}); err != nil || newest() != 5 {
|
||||
t.Fatalf("the withdrawal (%v) kept main's newest %d, want 5", err, newest())
|
||||
}
|
||||
if now, _ := moduleOf(t, mods, "g"); now.Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.28" {
|
||||
@@ -160,4 +168,31 @@ func TestAReleaseRepinsAnEntryNamingItsPackageWithNoPin(t *testing.T) {
|
||||
if _, _, kept, _ := heard.Get(ctx, ReservedKey(next, "mesh-sdk")); kept {
|
||||
t.Errorf("the withdrawn reservation is still kept")
|
||||
}
|
||||
// H-A-479 second addendum: two pipelines' movers reserve at one revision while its gathering is open; withdrawing one
|
||||
// pipeline's mover keeps the gathering and the other's reservation, withdrawing the last removes the gathering too.
|
||||
six := BranchObject("main", 6)
|
||||
for _, m := range []string{"one", "two"} {
|
||||
raw, _ := json.Marshal(Reserved{V: 1, Revision: six, Module: m})
|
||||
if err := heard.Create(ctx, ReservedKey(six, m), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := heard.Create(ctx, SettlingKey(six), []byte(`{}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ix.Withdraw(ctx, "main", 6, []string{"one"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _, gathering, _ := heard.Get(ctx, SettlingKey(six))
|
||||
_, _, one, _ := heard.Get(ctx, ReservedKey(six, "one"))
|
||||
_, _, two, _ := heard.Get(ctx, ReservedKey(six, "two"))
|
||||
if !gathering || one || !two {
|
||||
t.Fatalf("withdrawing one: gathering %v, one kept %v, two kept %v; want the gathering and two kept, one gone", gathering, one, two)
|
||||
}
|
||||
if err := ix.Withdraw(ctx, "main", 6, []string{"two"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, gathering, _ := heard.Get(ctx, SettlingKey(six)); gathering {
|
||||
t.Error("withdrawing the last reservation kept the revision's gathering")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,20 +350,35 @@ func (ix *Indexer) settleNow(ctx context.Context, revision string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Withdraw takes a pipeline-ended not passed of branch's revision in: each reservation the revision holds is withdrawn, its
|
||||
// series' numbered set back to the newest released version, its importers re-pinned to that, and its key deleted.
|
||||
func (ix *Indexer) Withdraw(ctx context.Context, branch string, revision int64) error {
|
||||
// Withdraw takes a pipeline-ended not passed of branch's revision in: each reservation the revision holds of one of the
|
||||
// ended pipeline's own movers is withdrawn, its series' numbered set back to the newest released version, its importers
|
||||
// re-pinned to that, and its key deleted. Another open pipeline's reservations at the same revision are kept, and the
|
||||
// revision's gathering is withdrawn only when none of them is left (design 47 H2 H-A-479 second addendum).
|
||||
func (ix *Indexer) Withdraw(ctx context.Context, branch string, revision int64, movers []string) error {
|
||||
if ix.Heard == nil {
|
||||
return nil
|
||||
}
|
||||
name := BranchObject(branch, revision)
|
||||
if _, rev, found, err := ix.Heard.Get(ctx, SettlingKey(name)); err == nil && found {
|
||||
_ = ix.Heard.Delete(ctx, SettlingKey(name), rev) // the gathering is withdrawn with it
|
||||
}
|
||||
held, revs, err := ix.reservedOf(ctx, name)
|
||||
if err != nil || len(held) == 0 {
|
||||
all, revs, err := ix.reservedOf(ctx, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
held := map[string]Reserved{}
|
||||
for key, r := range all {
|
||||
if slices.Contains(movers, r.Module) {
|
||||
held[key] = r
|
||||
} else {
|
||||
delete(revs, key)
|
||||
}
|
||||
}
|
||||
if len(held) == len(all) {
|
||||
if _, rev, found, err := ix.Heard.Get(ctx, SettlingKey(name)); err == nil && found {
|
||||
_ = ix.Heard.Delete(ctx, SettlingKey(name), rev) // the gathering is withdrawn with it
|
||||
}
|
||||
}
|
||||
if len(held) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, r := range held {
|
||||
for _, one := range r.Reservations {
|
||||
if err := ix.withdrawNumbered(ctx, one); err != nil {
|
||||
|
||||
@@ -19,11 +19,11 @@ func VerbTools(ask func(key string, body any) (json.RawMessage, error)) []stdio.
|
||||
}
|
||||
return []stdio.Tool{
|
||||
verbTool[seat.StartInput](ask, "start", seat.VerbStart,
|
||||
"Start by hand the delivering pipeline of the head of a watched branch for a module, by the seat verb start: the branch, the module and why. A head whose pipeline is written already is refused by the verb, naming it.",
|
||||
obj([]string{"branch", "module", "why"}, map[string]any{"branch": str, "module": str, "why": str}),
|
||||
"Start by hand the delivering pipeline of the head of a watched branch for a module, by the seat verb start: the branch, the module and why. A head whose pipeline is written already is refused by the verb, naming it. With modules instead of module, the named modules whose newest entry has no passed pipeline (a failed, cut or superseded one) are started again at the head, keyed <branch>.<revision>.again.<n>; a module whose newest entry passed is refused by name (design 47 H2 H-A-479).",
|
||||
obj([]string{"branch", "why"}, map[string]any{"branch": str, "module": str, "modules": map[string]any{"type": "array", "items": str}, "why": str}),
|
||||
func(in seat.StartInput) string {
|
||||
if in.Branch == "" || in.Module == "" {
|
||||
return "start names the watched branch and the module"
|
||||
if in.Branch == "" || (in.Module == "") == (len(in.Modules) == 0) {
|
||||
return "start names the watched branch and exactly one of the module or the modules"
|
||||
}
|
||||
return whyOf(in.Why)
|
||||
}),
|
||||
|
||||
@@ -18,7 +18,11 @@ func TestVerbTools(t *testing.T) {
|
||||
{"start", "runner_start", "seat:mesh-pipeline-runner.start", "", map[string]any{"branch": "main", "module": "i3", "why": "cancelled"},
|
||||
seat.StartInput{Branch: "main", Module: "i3", Why: "cancelled"}},
|
||||
{"start no why", "runner_start", "", "names why", map[string]any{"branch": "main", "module": "i3"}, nil},
|
||||
{"start no module", "runner_start", "", "branch and the module", map[string]any{"branch": "main", "why": "x"}, nil},
|
||||
{"start no module", "runner_start", "", "exactly one of the module or the modules", map[string]any{"branch": "main", "why": "x"}, nil},
|
||||
// H-A-479: modules start the named modules again at the head; both together are refused.
|
||||
{"start modules", "runner_start", "seat:mesh-pipeline-runner.start", "", map[string]any{"branch": "main", "modules": []any{"i3", "lib"}, "why": "failed"},
|
||||
seat.StartInput{Branch: "main", Modules: []string{"i3", "lib"}, Why: "failed"}},
|
||||
{"start module and modules", "runner_start", "", "exactly one of the module or the modules", map[string]any{"branch": "main", "module": "i3", "modules": []any{"lib"}, "why": "x"}, nil},
|
||||
{"run", "runner_run", "seat:mesh-pipeline-runner.run", "", map[string]any{"members": []any{map[string]any{}}, "why": "x"},
|
||||
seat.RunInput{Members: []seat.Member{{}}, Why: "x"}},
|
||||
{"run no members", "runner_run", "", "members", map[string]any{}, nil},
|
||||
|
||||
@@ -96,3 +96,34 @@ func TestARevisionHeardIsHandedToItsStart(t *testing.T) {
|
||||
t.Errorf("a body that is no event = %v, want it ended", err)
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-479 addendum (2): a revision is held when the catalog seat's revision verb answers that revision, read fresh; none-yet,
|
||||
// another revision or a refusal saying "no such object" is gone; another failure is said as it is.
|
||||
func TestRevisionHeldReadsTheCatalogsRevisionFresh(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
answer catalog.RevisionAnswer
|
||||
err error
|
||||
gone bool
|
||||
fails bool
|
||||
}{
|
||||
{name: "held", answer: catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: 258}}},
|
||||
{name: "another revision", answer: catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: 259}}, gone: true, fails: true},
|
||||
{name: "none yet", answer: catalog.RevisionAnswer{NoneYet: true}, gone: true, fails: true},
|
||||
{name: "removed", err: errors.New("revision main.258: no such object"), gone: true, fails: true},
|
||||
{name: "unreachable", err: errors.New("no responders"), fails: true},
|
||||
} {
|
||||
var asked catalog.RevisionInput
|
||||
call := func(_ string, body any) (json.RawMessage, error) {
|
||||
asked = body.(catalog.RevisionInput)
|
||||
if c.err != nil {
|
||||
return nil, c.err
|
||||
}
|
||||
return json.Marshal(c.answer)
|
||||
}
|
||||
err := revisionHeld(call)("main", 258)
|
||||
if (err != nil) != c.fails || errors.Is(err, pipeline.ErrRevisionGone) != c.gone || asked.Revision != 258 || asked.Branch != "main" {
|
||||
t.Errorf("%s: %v (asked %+v)", c.name, err, asked)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,14 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
"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"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
|
||||
@@ -65,5 +69,37 @@ func writeVerbs(h *pipeline.Hearer, s *pipeline.Starter, view func(string) (pipe
|
||||
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}}
|
||||
return pipeline.Verbs{Hearer: h, Starter: s, View: view, Candidate: candidate, Acts: meshhandactsclient.Recorder{Ask: calls.Call},
|
||||
RevisionHeld: revisionHeld(calls.CallKept)}
|
||||
}
|
||||
|
||||
// revisionHeld reads the first page of a branch's catalog revision through the catalog seat's verb revision, never a kept
|
||||
// copy, so a rerun reopening an ended pipeline knows whether the catalog still keeps its revision (design 47 H2 H-A-479
|
||||
// addendum (2)): an answer of that revision is kept; none-yet, another revision, or a refusal saying the catalog's
|
||||
// "no such object" is gone (pipeline.ErrRevisionGone); any other failure is said as it is.
|
||||
func revisionHeld(call func(key string, body any) (json.RawMessage, error)) func(string, int64) error {
|
||||
return func(branch string, revision int64) error {
|
||||
raw, err := call(meshcatalogclient.RevisionVerb, catalog.RevisionInput{Branch: keys.EscapeName(branch), Revision: revision})
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no such object") {
|
||||
return fmt.Errorf("%w: %v", pipeline.ErrRevisionGone, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
answer, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
if strings.Contains(said, "no such object") {
|
||||
return fmt.Errorf("%w: %s", pipeline.ErrRevisionGone, said)
|
||||
}
|
||||
return fmt.Errorf("%s answered: %s", meshcatalogclient.RevisionVerb, said)
|
||||
}
|
||||
var a catalog.RevisionAnswer
|
||||
if err := json.Unmarshal(answer, &a); err != nil {
|
||||
return fmt.Errorf("%s answered no revision: %w", meshcatalogclient.RevisionVerb, err)
|
||||
}
|
||||
if a.NoneYet || a.Revision == nil || a.Revision.Revision != revision {
|
||||
return fmt.Errorf("%w: %s answered no revision %d of %s", pipeline.ErrRevisionGone, meshcatalogclient.RevisionVerb, revision, branch)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ func StepsKey(pipeline, mover string) string {
|
||||
func stepsPrefix(pipeline string) string { return StepsKey(pipeline, "") }
|
||||
|
||||
// IsStepsKey says whether a key of the state pipelines is a mover's steps rather than a pipeline's record: `steps.` and a
|
||||
// pipeline key of a take-in's (4 parts), a run's (5 parts, its third `run`), an unfinished mover's own (6 parts, its fourth
|
||||
// `unfinished`, H-A-398) or a publish's (7 parts) and one mover.
|
||||
// pipeline key of a take-in's (4 parts), a run's (5 parts, its third `run`), an unfinished mover's own or one started again at
|
||||
// the head (6 parts, its fourth `unfinished`, H-A-398, or `again`, H-A-479) or a publish's (7 parts) and one mover.
|
||||
func IsStepsKey(key string) bool {
|
||||
parts := strings.Split(key, ".")
|
||||
if parts[0] != "steps" {
|
||||
@@ -42,7 +42,7 @@ func IsStepsKey(key string) bool {
|
||||
case 5:
|
||||
return parts[2] == runToken
|
||||
case 6:
|
||||
return parts[3] == unfinishedToken
|
||||
return parts[3] == unfinishedToken || parts[3] == againToken
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int,
|
||||
// A pipeline is keyed by its revision (H-A-213 (4)), so the pipelines of a source are those naming it, of either key
|
||||
// form a source's pipelines were kept under.
|
||||
var pkeys []string
|
||||
for _, f := range []string{b + ".*", b + ".*.published.*.*", b + ".*." + unfinishedToken + ".*"} {
|
||||
for _, f := range []string{b + ".*", b + ".*.published.*.*", b + ".*." + unfinishedToken + ".*", b + ".*." + againToken + ".*"} {
|
||||
k, err := h.Store.Keys(f)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("the pipelines of source %d are not listed: %w", ev.Source, err)
|
||||
|
||||
@@ -69,8 +69,19 @@ func keyRevision(b Begin) int64 {
|
||||
}
|
||||
|
||||
// keyForms are the filters of every key form of the state pipelines: a revision's, a run's, a publish's kept from before
|
||||
// a release revision started one pipeline (H-A-213 (2)), and an unfinished mover's pipeline of its own (H-A-398).
|
||||
var keyForms = []string{"*.*", "*." + runToken + ".*", "*.*.published.*.*", "*.*." + unfinishedToken + ".*"}
|
||||
// a release revision started one pipeline (H-A-213 (2)), an unfinished mover's pipeline of its own (H-A-398), and a pipeline
|
||||
// started again at the head (H-A-479).
|
||||
var keyForms = []string{"*.*", "*." + runToken + ".*", "*.*.published.*.*", "*.*." + unfinishedToken + ".*", "*.*." + againToken + ".*"}
|
||||
|
||||
// againToken is the third part of the key of a pipeline started again at the head by start with modules,
|
||||
// `<branch>.<revision>.again.<n>` (design 47 H2 H-A-479 addendum (1)).
|
||||
const againToken = "again"
|
||||
|
||||
// AgainPipelineKey is the key of the n-th pipeline started again at revision of branch, `<branch>.<revision>.again.<n>`
|
||||
// (H-A-479 addendum (1)).
|
||||
func AgainPipelineKey(branch string, revision int64, n int) string {
|
||||
return seat.PipelinesByBranchRevisionAgainNKey(keys.EscapeName(branch), strconv.FormatInt(revision, 10), strconv.Itoa(n))
|
||||
}
|
||||
|
||||
// AllKeys are every pipeline's key, of each key form (§746, §747; H-A-83).
|
||||
func AllKeys(store interface {
|
||||
|
||||
@@ -655,6 +655,50 @@ func TestNoWriteOfATestRunActsOnAReadBeforeItsLatestChange(t *testing.T) {
|
||||
t.Error("the step's finding was written before its run's end")
|
||||
}
|
||||
})
|
||||
// H-A-479 addendum (2): a test step's rerun reopening an ended pipeline says its pipeline-started before its run is
|
||||
// started again, so its revision is pinned before the step is asked.
|
||||
t.Run("a test step's rerun reopening an ended pipeline pins its revision first", func(t *testing.T) {
|
||||
f := newRunFixture()
|
||||
p := f.start(t, 4, 9)
|
||||
unit := stepNamed(p, "app:program", "unit")
|
||||
run := unit.Shared[0].Run
|
||||
ended := time.Now()
|
||||
if _, err := f.h.OnStepEnded(stepSeatOf(t, "node-build-go"), "mesh.seat.node-build-go.event.step-ended.ace", StepEnded{ID: unit.Ask,
|
||||
Pipeline: p.Pipeline, Module: "app", Commit: "c1", Fingerprint: "src2:aa", Step: "unit", Node: "ace", Outcome: "failed", Ended: &ended}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
q, rev, _ := f.store.Get(p.Pipeline)
|
||||
q.Outcome, q.Ended = seat.PipelineOutcomeFailed, &ended
|
||||
if _, err := f.store.Update(p.Pipeline, q, rev); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, _, _ := f.runs.Get(run)
|
||||
var started []string
|
||||
f.s.Say = func(_ string, body any) error {
|
||||
if ps, ok := body.(seat.PipelineStarted); ok {
|
||||
if r, _, _ := f.runs.Get(run); r.Ask != before.Ask || r.Ended == nil {
|
||||
t.Errorf("pipeline-started said after the run was started again (ask %s, was %s)", r.Ask, before.Ask)
|
||||
}
|
||||
started = append(started, ps.Pipeline)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
v := Verbs{Hearer: f.h, Starter: f.s, View: func(string) (Half, bool) {
|
||||
return Half{Entries: map[string]catalog.CatalogEntry{
|
||||
"app": {Module: "app", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}},
|
||||
"mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}}}}, true
|
||||
}, Acts: &actLog{}, RevisionHeld: func(string, int64) error { return nil }}
|
||||
a, err := v.Rerun("op@shanks", seat.RerunInput{Pipeline: p.Pipeline, Step: "unit", Artifact: "app:program", Why: "fixed"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(started) != 1 || started[0] != p.Pipeline {
|
||||
t.Errorf("pipeline-started at the reopening = %v, want %s once", started, p.Pipeline)
|
||||
}
|
||||
if r, _, _ := f.runs.Get(run); r.Ask != a.Result.Ask || r.Ended != nil {
|
||||
t.Errorf("the rerun's run = %+v; want the new ask running", r)
|
||||
}
|
||||
})
|
||||
// A rerun whose read of the key is changed before its write (a step joining the ended run) writes from the latest read,
|
||||
// carrying that reader, never answering the change as an error nor putting back the earlier readers.
|
||||
t.Run("a rerun writes its run from the latest read", func(t *testing.T) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -29,8 +30,15 @@ type Verbs struct {
|
||||
Acts views.HandActs
|
||||
// Runs answers the read verb test-runs, answered by the process that holds test-runs-cap-mib (A-470i).
|
||||
Runs RunsRead
|
||||
// RevisionHeld says whether a branch's catalog revision is still kept, read through the catalog seat's verb revision
|
||||
// at the time of the ask: nil when it is, an error wrapping ErrRevisionGone when it is removed (design 47 H2 H-A-479
|
||||
// addendum (2)).
|
||||
RevisionHeld func(branch string, revision int64) error
|
||||
}
|
||||
|
||||
// ErrRevisionGone is a catalog revision the catalog no longer keeps (H-A-479 addendum (2)).
|
||||
var ErrRevisionGone = errors.New("the catalog revision is gone")
|
||||
|
||||
func (v Verbs) now() time.Time { return v.Hearer.now() }
|
||||
|
||||
func (v Verbs) record(verb, what, why string) error {
|
||||
@@ -275,13 +283,89 @@ func (v Verbs) EndAgain(_ string, in seat.EndAgainInput) (seat.EndAgainAnswer, e
|
||||
// the ask saying it is a rerun and the caller the bus proved; a failed pipeline runs again and ends once more with its end
|
||||
// count one higher (§325), an approval never asked waiting again. A review waits again; an approval is asked again by
|
||||
// `ask-again`.
|
||||
//
|
||||
// A rerun of a step in an ended delivering pipeline reopens it: its revision is read first and the rerun refused by name,
|
||||
// nothing asked, when the catalog removed it; once reopened its pipeline-started is said again, so the indexer pins its
|
||||
// revision again until its next end (design 47 H2 H-A-479 addendum (2)).
|
||||
func (v Verbs) Rerun(caller string, in seat.RerunInput) (seat.RerunAnswer, error) {
|
||||
if in.Step == seat.StepResultStepApproval {
|
||||
return seat.RerunAnswer{}, errors.New("an approval is asked again by ask-again, not rerun")
|
||||
}
|
||||
reopens, err := v.reopening(in.Pipeline)
|
||||
if err != nil {
|
||||
return seat.RerunAnswer{}, err
|
||||
}
|
||||
return v.rerun(caller, in, reopens)
|
||||
}
|
||||
|
||||
// sayReopened says pipeline-started again for p, written reopened by a rerun, before its step is asked again, so the
|
||||
// indexer pins its revision again before anything reads it (H-A-479 addendum (2)).
|
||||
func (v Verbs) sayReopened(p seat.Pipeline, reopens bool) {
|
||||
if !reopens || v.Starter == nil || p.Ended != nil {
|
||||
return
|
||||
}
|
||||
v.Starter.sayStartedPipeline(p, v.now())
|
||||
v.Starter.logf("%s reopened by a rerun: its pipeline-started is said again, so its revision %d is pinned again (H-A-479)", p.Pipeline, p.Revision)
|
||||
}
|
||||
|
||||
// reopening says whether a rerun of pipeline key reopens an ended delivering pipeline, refusing it when its revision is
|
||||
// gone (H-A-479 addendum (2)). A pipeline not read, a run's, or one the rerun refuses anyway is left to the rerun.
|
||||
func (v Verbs) reopening(key string) (bool, error) {
|
||||
p, _, err := v.Hearer.Store.Get(key)
|
||||
if err != nil || p.Ended == nil || p.Run != "" || p.Revision <= 0 ||
|
||||
p.Outcome == seat.PipelineOutcomeCancelled || p.Outcome == seat.PipelineOutcomeSuperseded {
|
||||
return false, nil
|
||||
}
|
||||
// A reopening never builds beside an open pipeline carrying one of its movers at the same revision (H-A-479 third
|
||||
// addendum).
|
||||
if open, err := v.openBeside(p); err != nil {
|
||||
return false, err
|
||||
} else if open != "" {
|
||||
return false, fmt.Errorf("the pipeline %s ended and is not reopened: its pipeline %s is running: nothing was asked", key, open)
|
||||
}
|
||||
if v.RevisionHeld != nil {
|
||||
if err := v.RevisionHeld(p.Branch, p.Revision); errors.Is(err, ErrRevisionGone) {
|
||||
return false, fmt.Errorf("the pipeline %s ended and its revision %d is gone; start the mover again at the head: nothing was asked (%v)", key, p.Revision, err)
|
||||
} else if err != nil {
|
||||
return false, fmt.Errorf("the pipeline %s ended and its revision %d is not read, so it is not reopened: nothing was asked: %w", key, p.Revision, err)
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// openBeside is the key of another delivering pipeline of p's branch and revision, not ended, carrying one of p's movers it
|
||||
// did not leave; empty when none (H-A-479 third addendum).
|
||||
func (v Verbs) openBeside(p seat.Pipeline) (string, error) {
|
||||
pkeys, err := branchKeys(v.Hearer.Store, p.Branch)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("the pipelines of %s are not listed, so %s is not reopened: nothing was asked: %w", p.Branch, p.Pipeline, err)
|
||||
}
|
||||
for _, key := range pkeys {
|
||||
if key == p.Pipeline {
|
||||
continue
|
||||
}
|
||||
o, _, err := v.Hearer.Store.Get(key)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("the pipeline %s is not read, so %s is not reopened: nothing was asked: %w", key, p.Pipeline, err)
|
||||
}
|
||||
if o.Run != "" || o.Ended != nil || o.Revision != p.Revision ||
|
||||
(o.Outcome != seat.PipelineOutcomeRunning && o.Outcome != seat.PipelineOutcomeWaiting) {
|
||||
continue
|
||||
}
|
||||
for _, m := range p.Movers {
|
||||
if Moves(o, m.Module) && !slices.Contains(o.Superseded, m.Module) {
|
||||
return key, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// rerun asks one step again (Rerun).
|
||||
func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.RerunAnswer, error) {
|
||||
if p, _, err := v.Hearer.Store.Get(in.Pipeline); err == nil {
|
||||
if i, err := stepOf(p, in.Module, in.Step, in.Artifact); err == nil && v.Hearer.TestRuns != nil && sharedRun(p.Steps[i]) != "" && BoundSeat(p.Steps[i].Seat) {
|
||||
return v.rerunTest(caller, in, p.Steps[i])
|
||||
return v.rerunTest(caller, in, p.Steps[i], reopens)
|
||||
}
|
||||
}
|
||||
var ask *Asked
|
||||
@@ -332,6 +416,7 @@ func (v Verbs) Rerun(caller string, in seat.RerunInput) (seat.RerunAnswer, error
|
||||
if err != nil {
|
||||
return seat.RerunAnswer{}, err
|
||||
}
|
||||
v.sayReopened(p, reopens)
|
||||
if ask != nil {
|
||||
v.Starter.carry(in.Pipeline, []Asked{*ask})
|
||||
if err := askAll(v.Starter.Steps, in.Pipeline, []Asked{*ask}, func(commit string) bool { return v.Starter.recovered(in.Pipeline, commit) }, v.Starter.Asks.arm, v.Starter.logf); err != nil {
|
||||
@@ -349,7 +434,7 @@ func (v Verbs) Rerun(caller string, in seat.RerunInput) (seat.RerunAnswer, error
|
||||
// rerunTest asks a test step of a test run again (design 47 G §727, A-469l): it joins its key's run while that runs, reads one
|
||||
// that started after the step's last end, or else starts a new run under a new ask, replacing the ended key by compare-and-set
|
||||
// and carrying its readers into the new value, so the new run's end moves every former reader that did not pass.
|
||||
func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult) (seat.RerunAnswer, error) {
|
||||
func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult, reopens bool) (seat.RerunAnswer, error) {
|
||||
h := v.Hearer
|
||||
run := sharedRun(st)
|
||||
if open(st) {
|
||||
@@ -430,6 +515,7 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult)
|
||||
if err != nil {
|
||||
return seat.RerunAnswer{}, err
|
||||
}
|
||||
v.sayReopened(p, reopens)
|
||||
switch {
|
||||
case join || read:
|
||||
v.Starter.joinRun(run, reader)
|
||||
@@ -649,10 +735,17 @@ func (v Verbs) Run(caller string, in seat.RunInput) (seat.RunAnswer, error) {
|
||||
|
||||
// Start starts by hand a delivering pipeline for the head of a watched branch the runner's catalog half holds, recorded in
|
||||
// the hand-act log first (§306, §394): the pipeline of that branch's source revision and the module, as a take-in would
|
||||
// start it. A head whose pipeline is written already starts nothing and is refused, naming the pipeline.
|
||||
// start it. A head whose pipeline is written already starts nothing and is refused, naming the pipeline. With modules it
|
||||
// starts the named modules again at the head instead (startAgain, H-A-479); exactly one of module or modules is given.
|
||||
func (v Verbs) Start(_ string, in seat.StartInput) (seat.StartAnswer, error) {
|
||||
if in.Module != "" && len(in.Modules) > 0 {
|
||||
return seat.StartAnswer{}, errors.New("start names the module or the modules, not both: nothing was started")
|
||||
}
|
||||
if in.Branch != "" && len(in.Modules) > 0 {
|
||||
return v.startAgain(in)
|
||||
}
|
||||
if in.Branch == "" || in.Module == "" {
|
||||
return seat.StartAnswer{}, errors.New("start names the watched branch and the module")
|
||||
return seat.StartAnswer{}, errors.New("start names the watched branch and the module or the modules")
|
||||
}
|
||||
if v.Starter == nil || v.View == nil {
|
||||
return seat.StartAnswer{}, errors.New("the runner cannot start a pipeline: it holds no starter or no catalog half")
|
||||
@@ -681,6 +774,117 @@ func (v Verbs) Start(_ string, in seat.StartInput) (seat.StartAnswer, error) {
|
||||
return seat.StartAnswer{Pipeline: key}, nil
|
||||
}
|
||||
|
||||
// startAgain starts by hand, recorded in the hand-act log first, a pipeline at the head of a watched branch carrying the
|
||||
// named modules whose newest entry, the head's, has no passed pipeline (a failed, cut or superseded one), with the head's
|
||||
// revision as its candidate and the take-in's tiers (design 47 H2 H-A-479): keyed `<branch>.<revision>.again.<n>`, n from 1,
|
||||
// taken by writing on absence (addendum (1)). Its pipeline-started pins the head's revision as a take-in's does, and its
|
||||
// versions are reserved at its build steps as a take-in's are. A module the head holds no entry of, or whose newest entry
|
||||
// passed in a pipeline, is refused by name, nothing started.
|
||||
func (v Verbs) startAgain(in seat.StartInput) (seat.StartAnswer, error) {
|
||||
if v.Starter == nil || v.View == nil || v.Hearer == nil || v.Hearer.Store == nil {
|
||||
return seat.StartAnswer{}, errors.New("the runner cannot start a pipeline again: it holds no starter, no catalog half or no state pipelines")
|
||||
}
|
||||
half, ok := v.View(in.Branch)
|
||||
if !ok || half.Source <= 0 {
|
||||
return seat.StartAnswer{}, fmt.Errorf("the catalog half of %s is not held at a source revision yet: nothing was started", in.Branch)
|
||||
}
|
||||
movers := make([]seat.Mover, 0, len(in.Modules))
|
||||
var absent []string
|
||||
for _, m := range in.Modules {
|
||||
e, ok := half.Entries[m]
|
||||
if !ok {
|
||||
absent = append(absent, m)
|
||||
continue
|
||||
}
|
||||
if slices.ContainsFunc(movers, func(x seat.Mover) bool { return x.Module == m }) {
|
||||
continue
|
||||
}
|
||||
movers = append(movers, seat.Mover{Module: m, Commit: e.Commit, Fingerprint: e.Fp, Repository: e.Repository})
|
||||
}
|
||||
if len(absent) > 0 {
|
||||
return seat.StartAnswer{}, fmt.Errorf("the head of %s (revision %d) holds no entry of %s: nothing was started", in.Branch, half.Revision, strings.Join(absent, ", "))
|
||||
}
|
||||
passed, running, err := v.heldEntries(in.Branch, movers)
|
||||
if err != nil {
|
||||
return seat.StartAnswer{}, err
|
||||
}
|
||||
if len(passed) > 0 {
|
||||
return seat.StartAnswer{}, fmt.Errorf("the newest entry of %s passed already: nothing was started", strings.Join(passed, ", "))
|
||||
}
|
||||
if len(running) > 0 {
|
||||
return seat.StartAnswer{}, fmt.Errorf("the newest entry of %s: nothing was started", strings.Join(running, ", "))
|
||||
}
|
||||
movers = Tiers(movers, half.Entries, v.Starter.logf)
|
||||
names := make([]string, 0, len(movers))
|
||||
for _, m := range movers {
|
||||
names = append(names, m.Module)
|
||||
}
|
||||
prefix := AgainPipelineKey(in.Branch, half.Revision, 0)
|
||||
prefix = prefix[:len(prefix)-1]
|
||||
held, err := v.Hearer.Store.Keys(prefix + "*")
|
||||
if err != nil {
|
||||
return seat.StartAnswer{}, fmt.Errorf("the pipelines started again at revision %d of %s are not listed: nothing was started: %w", half.Revision, in.Branch, err)
|
||||
}
|
||||
n := 1
|
||||
for _, k := range held {
|
||||
if i, err := strconv.Atoi(strings.TrimPrefix(k, prefix)); err == nil && i >= n {
|
||||
n = i + 1
|
||||
}
|
||||
}
|
||||
if err := v.record(seat.VerbStart, fmt.Sprintf("started %s again at the head of %s by hand", strings.Join(names, ", "), in.Branch), in.Why); err != nil {
|
||||
return seat.StartAnswer{}, err
|
||||
}
|
||||
// The next n is taken without a bound: each refusal means the key exists (H-A-479 second addendum).
|
||||
for ; ; n++ {
|
||||
key := AgainPipelineKey(in.Branch, half.Revision, n)
|
||||
started, err := v.Starter.Start(Begin{Branch: in.Branch, Source: half.Source, Revision: half.Revision, Entries: half.Entries,
|
||||
Key: key, Movers: movers})
|
||||
if err != nil {
|
||||
return seat.StartAnswer{}, err
|
||||
}
|
||||
if started {
|
||||
v.Starter.logf("%s starts %s again at the head by hand (H-A-479)", key, strings.Join(names, ", "))
|
||||
return seat.StartAnswer{Pipeline: key}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// heldEntries are the movers whose module, at the mover's fingerprint, a delivering pipeline of branch carries and did not
|
||||
// leave: passed, those a passed pipeline holds (a newest entry that passed is not started again, H-A-479); running, those a
|
||||
// pipeline not ended holds, each said "<module>: its pipeline <key> is running", so two pipelines never build one entry side
|
||||
// by side (H-A-479 second addendum).
|
||||
func (v Verbs) heldEntries(branch string, movers []seat.Mover) (passed, running []string, err error) {
|
||||
pkeys, err := branchKeys(v.Hearer.Store, branch)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("the pipelines of %s are not listed, so nothing was started: %w", branch, err)
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, key := range pkeys {
|
||||
p, _, err := v.Hearer.Store.Get(key)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("the pipeline %s is not read, so nothing was started: %w", key, err)
|
||||
}
|
||||
open := p.Ended == nil && (p.Outcome == seat.PipelineOutcomeRunning || p.Outcome == seat.PipelineOutcomeWaiting)
|
||||
if p.Run != "" || (p.Outcome != seat.PipelineOutcomePassed && !open) {
|
||||
continue
|
||||
}
|
||||
for _, m := range movers {
|
||||
if seen[m.Module] || slices.Contains(p.Superseded, m.Module) {
|
||||
continue
|
||||
}
|
||||
if pm, ok := MoverOf(p, m.Module); ok && pm.Fingerprint == m.Fingerprint {
|
||||
seen[m.Module] = true
|
||||
if open {
|
||||
running = append(running, m.Module+": its pipeline "+key+" is running")
|
||||
} else {
|
||||
passed = append(passed, m.Module+" (in "+key+")")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return passed, running, nil
|
||||
}
|
||||
|
||||
// AskAgain asks a declined approval step once more (§306, §36), recorded in the hand-act log first: the step waits again,
|
||||
// marked asked again by the caller the bus proved, and is asked at once when the pipeline's every other required step
|
||||
// passed, under an ask of its own (the earlier ask's decision ended it).
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -423,3 +425,173 @@ func TestAValidateRerunMovesEveryMoversValidateAndReopensItsCompositions(t *test
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-479: start with modules starts a pipeline at the head keyed <branch>.<revision>.again.<n> carrying the named modules
|
||||
// whose newest entry has no passed pipeline, at the take-in's tiers; a module whose newest entry passed is refused by name,
|
||||
// nothing started; exactly one of module or modules is given; a second start takes the next n.
|
||||
func TestStartWithModulesStartsAFailedMoverAgainAtTheHead(t *testing.T) {
|
||||
v, store, _, _, acts, _ := verbsFixture()
|
||||
made := created{}
|
||||
var started []seat.PipelineStarted
|
||||
v.Starter.Pipelines = made
|
||||
v.Starter.Say = func(_ string, body any) error {
|
||||
if ps, ok := body.(seat.PipelineStarted); ok {
|
||||
started = append(started, ps)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
_, entries := placeFixture()
|
||||
app := entries["app"]
|
||||
app.Fp, app.Commit, app.Repository = "src2:aa", "c1", "o/app"
|
||||
entries["app"] = app
|
||||
entries["lib"] = catalog.CatalogEntry{Module: "lib", Fp: "src2:bb", Commit: "c2", Repository: "o/lib"}
|
||||
v.View = func(string) (Half, bool) { return Half{Source: 7, Revision: 9, Entries: entries}, true }
|
||||
// The fixture's main.5 moves app at src2:aa and failed; lib's newest entry passed in main.8.
|
||||
e := store[pkey]
|
||||
e.p.Outcome = seat.PipelineOutcomeFailed
|
||||
store[pkey] = e
|
||||
store["main.8"] = struct {
|
||||
p seat.Pipeline
|
||||
rev uint64
|
||||
}{seat.Pipeline{Pipeline: "main.8", Branch: "main", Source: 6, Revision: 8, Outcome: seat.PipelineOutcomePassed,
|
||||
Movers: []seat.Mover{{Module: "lib", Fingerprint: "src2:bb"}, {Module: "app", Fingerprint: "src2:aa"}}, Superseded: []string{"app"}}, 1}
|
||||
|
||||
if _, err := v.Start("operator", seat.StartInput{Branch: "main", Module: "app", Modules: []string{"app"}, Why: "x"}); err == nil {
|
||||
t.Error("a start naming both module and modules was taken")
|
||||
}
|
||||
// A pipeline still running at app's head entry refuses the start: two pipelines never build one entry side by side.
|
||||
store["main.7"] = struct {
|
||||
p seat.Pipeline
|
||||
rev uint64
|
||||
}{seat.Pipeline{Pipeline: "main.7", Branch: "main", Source: 6, Revision: 7, Outcome: seat.PipelineOutcomeRunning,
|
||||
Movers: []seat.Mover{{Module: "app", Fingerprint: "src2:aa"}}}, 1}
|
||||
if _, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "x"}); err == nil || !strings.Contains(err.Error(), "its pipeline main.7 is running") {
|
||||
t.Errorf("a start of app while main.7 runs it = %v; want refused naming main.7", err)
|
||||
}
|
||||
delete(store, "main.7")
|
||||
if _, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app", "lib"}, Why: "x"}); err == nil || !strings.Contains(err.Error(), "lib") {
|
||||
t.Errorf("a start naming lib, whose newest entry passed, = %v; want refused naming lib", err)
|
||||
}
|
||||
if len(made) != 0 {
|
||||
t.Fatalf("a refused start wrote %d pipelines", len(made))
|
||||
}
|
||||
a, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "its pipeline failed at an unchanged entry"})
|
||||
if err != nil || a.Pipeline != "main.9.again.1" || made["main.9.again.1"] == nil {
|
||||
t.Fatalf("start with modules = %+v, %v; written %v", a, err, len(made))
|
||||
}
|
||||
var p seat.Pipeline
|
||||
if err := json.Unmarshal(made["main.9.again.1"], &p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p.Revision != 9 || p.Source != 7 || len(p.Movers) != 1 || p.Movers[0].Module != "app" || p.Movers[0].Fingerprint != "src2:aa" || p.Movers[0].Tier != 1 {
|
||||
t.Errorf("the pipeline = %+v, want app at src2:aa, tier 1, at revision 9 of source 7", p)
|
||||
}
|
||||
if len(started) != 1 || started[0].Pipeline != "main.9.again.1" || started[0].Revision != 9 {
|
||||
t.Errorf("pipeline-started = %+v, want main.9.again.1 at revision 9 (its revision pinned)", started)
|
||||
}
|
||||
// The next start at the same head, once main.9.again.1 failed, takes the next n.
|
||||
at := time.Unix(3, 0)
|
||||
p.Outcome, p.Ended = seat.PipelineOutcomeFailed, &at
|
||||
store["main.9.again.1"] = struct {
|
||||
p seat.Pipeline
|
||||
rev uint64
|
||||
}{p, 1}
|
||||
if a, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "again"}); err != nil || a.Pipeline != "main.9.again.2" {
|
||||
t.Errorf("a second start with modules = %+v, %v; want main.9.again.2", a, err)
|
||||
}
|
||||
if len(*acts) != 2 {
|
||||
t.Errorf("hand acts %v, want the two starts recorded", *acts)
|
||||
}
|
||||
// main.9.again.1 passed: its version is written into it as into any pipeline of its source, and a further start of app is
|
||||
// refused naming it, read through the branch's key forms.
|
||||
p.Outcome = seat.PipelineOutcomePassed
|
||||
store["main.9.again.1"] = struct {
|
||||
p seat.Pipeline
|
||||
rev uint64
|
||||
}{p, 1}
|
||||
if wrote, err := v.Hearer.Released(catalog.VersionReleasedEvent{Module: "app", Version: "0.1.2", Source: 7}, "main"); err != nil || wrote != 1 ||
|
||||
store["main.9.again.1"].p.Movers[0].Version != "0.1.2" {
|
||||
t.Errorf("the release of app 0.1.2 wrote %d (%v), the again pipeline's mover %+v; want its version written", wrote, err, store["main.9.again.1"].p.Movers)
|
||||
}
|
||||
if _, err := v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "x"}); err == nil || !strings.Contains(err.Error(), "main.9.again.1") {
|
||||
t.Errorf("a start of app after main.9.again.1 passed = %v; want refused naming it", err)
|
||||
}
|
||||
if !IsStepsKey(StepsKey("main.9.again.1", "app")) {
|
||||
t.Error("a mover key of an again pipeline is not read as a mover's steps")
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-479 addendum (2): a rerun of a step in an ended pipeline pins its revision again at the reopening (its pipeline-started
|
||||
// said again), and is refused by name, nothing asked, when the revision is already removed.
|
||||
func TestARerunOfAnEndedPipelinePinsItsRevisionAgainOrIsRefusedWhenItIsGone(t *testing.T) {
|
||||
v, store, _, asks, _, _ := verbsFixture()
|
||||
var started []seat.PipelineStarted
|
||||
v.Starter.Say = func(_ string, body any) error {
|
||||
if ps, ok := body.(seat.PipelineStarted); ok {
|
||||
if len(asks.asks) != 0 {
|
||||
t.Errorf("pipeline-started said after the step was asked again (%d asks): its revision is pinned too late", len(asks.asks))
|
||||
}
|
||||
started = append(started, ps)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
e := store[pkey]
|
||||
at := time.Unix(2, 0)
|
||||
e.p.Revision, e.p.Outcome, e.p.Ended = 5, seat.PipelineOutcomeFailed, &at
|
||||
for i := range e.p.Steps {
|
||||
if e.p.Steps[i].Artifact == "app:program" && e.p.Steps[i].Step == "lint" {
|
||||
e.p.Steps[i].Outcome = seat.StepResultOutcomeFailed
|
||||
}
|
||||
}
|
||||
store[pkey] = e
|
||||
gone := true
|
||||
v.RevisionHeld = func(branch string, revision int64) error {
|
||||
if gone {
|
||||
return fmt.Errorf("revision %s.%d: no such object: %w", branch, revision, ErrRevisionGone)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
in := seat.RerunInput{Pipeline: pkey, Step: "lint", Artifact: "app:program", Why: "retry"}
|
||||
// H-A-479 third addendum: another open pipeline carrying app at the same revision refuses the reopening.
|
||||
store["main.5.again.1"] = struct {
|
||||
p seat.Pipeline
|
||||
rev uint64
|
||||
}{seat.Pipeline{Pipeline: "main.5.again.1", Branch: "main", Source: 5, Revision: 5, Outcome: seat.PipelineOutcomeRunning,
|
||||
Movers: []seat.Mover{{Module: "app", Fingerprint: "src2:aa"}}}, 1}
|
||||
gone = false
|
||||
if _, err := v.Rerun("operator", in); err == nil || !strings.Contains(err.Error(), "its pipeline main.5.again.1 is running") {
|
||||
t.Fatalf("a reopening beside main.5.again.1 = %v; want refused naming it", err)
|
||||
}
|
||||
if len(asks.asks) != 0 || store[pkey].p.Outcome != seat.PipelineOutcomeFailed {
|
||||
t.Fatalf("a refused reopening asked %d, left the pipeline %s", len(asks.asks), store[pkey].p.Outcome)
|
||||
}
|
||||
delete(store, "main.5.again.1")
|
||||
gone = true
|
||||
if _, err := v.Rerun("operator", in); err == nil || !strings.Contains(err.Error(), "its revision 5 is gone; start the mover again at the head") {
|
||||
t.Fatalf("a rerun of an ended pipeline whose revision is gone = %v; want refused by name", err)
|
||||
}
|
||||
if len(asks.asks) != 0 || store[pkey].p.Outcome != seat.PipelineOutcomeFailed || len(started) != 0 {
|
||||
t.Fatalf("a refused rerun asked %d, left the pipeline %s, said %d starts", len(asks.asks), store[pkey].p.Outcome, len(started))
|
||||
}
|
||||
gone = false
|
||||
if _, err := v.Rerun("operator", in); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(started) != 1 || started[0].Pipeline != pkey || started[0].Revision != 5 {
|
||||
t.Errorf("pipeline-started at the reopening = %+v, want %s at revision 5 (its revision pinned again)", started, pkey)
|
||||
}
|
||||
// A rerun of a running pipeline reopens nothing and says no start.
|
||||
e = store[pkey]
|
||||
for i := range e.p.Steps {
|
||||
if e.p.Steps[i].Artifact == "app:program" && e.p.Steps[i].Step == "unit" {
|
||||
e.p.Steps[i].Outcome = seat.StepResultOutcomeFailed
|
||||
}
|
||||
}
|
||||
store[pkey] = e
|
||||
if _, err := v.Rerun("operator", seat.RerunInput{Pipeline: pkey, Step: "unit", Artifact: "app:program", Why: "x"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(started) != 1 {
|
||||
t.Errorf("a rerun of a running pipeline said pipeline-started again: %+v", started)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user