A1 tier-goes-on: a delivery whose tier passed tier-bound goes on once the tier runs; lateness is written before it is said
Builds: design 47 H2b §824 1., 2., 3., 4. (H-A-828, H-A-839, H-A-858)
This commit is contained in:
@@ -8,6 +8,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
@@ -324,6 +325,17 @@ func findingsOf(ctx context.Context, account process.Account, conn *nats.Conn, j
|
||||
return w.Clear(ctx, scope, rest[:i], rest[i+1:], "the assigner no longer observes it")
|
||||
}
|
||||
f.Keys = state.Keys
|
||||
f.Get = func(key string) (mcseat.Finding, bool, error) {
|
||||
entry, err := state.Get(key)
|
||||
if err != nil || entry == nil {
|
||||
return mcseat.Finding{}, false, err
|
||||
}
|
||||
var found mcseat.Finding
|
||||
if err := json.Unmarshal(entry.Value, &found); err != nil {
|
||||
return mcseat.Finding{}, false, fmt.Errorf("the finding %s does not read: %w", key, err)
|
||||
}
|
||||
return found, true, nil
|
||||
}
|
||||
return f, w
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,11 @@ type tierProgress struct {
|
||||
// PausedFrom is the time the standing pause began: a key of the state asks names a mover of the tier that is not running,
|
||||
// and the count stands still. Absent while the bound counts (H-A-627).
|
||||
PausedFrom time.Time `json:"paused-from,omitzero"`
|
||||
// TierLateAt is the time any tier of the pipeline was first found past tier-bound, written before the finding is raised and
|
||||
// `pipeline-wanted` `tier-late` said; TierLateSaid the time the bus took that event. A key with the first and not the second
|
||||
// holds a `tier-late` still to be said. Both go into every later tier's progress (design 47 H2b §824 2.).
|
||||
TierLateAt time.Time `json:"tier-late-at,omitzero"`
|
||||
TierLateSaid time.Time `json:"tier-late-said,omitzero"`
|
||||
}
|
||||
|
||||
// clockFrom is the time tier-bound counts from; Since in a progress kept before the field.
|
||||
@@ -194,6 +199,7 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
}
|
||||
}
|
||||
defer p.clearTierLate(followed)
|
||||
have, readable := p.findingKeys("the finding tier-late")
|
||||
for _, key := range ks {
|
||||
if !isTierKey(key) {
|
||||
continue
|
||||
@@ -204,17 +210,29 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
continue
|
||||
}
|
||||
branch, number := pk.Branch, strconv.FormatInt(pk.Revision, 10)
|
||||
findingKey := views.FindingKey(mcc.ScopeDelivery, assign.KeyID(pipeline), kindTierLate)
|
||||
for {
|
||||
t, rev, ok := p.ends.tiersOf(pipeline)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
// A key the earlier rule left holds neither field: it counts as said when the findings bucket holds a tier-late of its
|
||||
// pipeline, and both fields are written from that finding's time (H-A-722, H-A-828).
|
||||
if t.TierLateAt.IsZero() && readable && have[findingKey] {
|
||||
at := p.tierLateSince(findingKey, now)
|
||||
t.TierLateAt, t.TierLateSaid = at, at
|
||||
err := p.writeTier(key, t, rev, "tier-late-at")
|
||||
if err == nil || errors.Is(err, errSwapped) {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
notRunning := p.notRunning(n, placedOn, pipeline, branch, t, t.Tier)
|
||||
// The count stands still while an ask of the operator names a mover of the tier that is not running (H-A-627): the first
|
||||
// pass that finds one writes paused-from, the first that finds none moves clock-from later by the time it stood still.
|
||||
clock := t.clockFrom()
|
||||
paused := pausedBy(standing, t, notRunning)
|
||||
if paused && t.PausedFrom.IsZero() && now.Before(clock.Add(bound)) {
|
||||
if paused && t.PausedFrom.IsZero() && now.Before(clock.Add(bound)) && len(notRunning) > 0 {
|
||||
t.PausedFrom = now
|
||||
if now.Before(t.Since) {
|
||||
t.PausedFrom = t.Since // never earlier than the progress's own start
|
||||
@@ -240,21 +258,45 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
}
|
||||
break
|
||||
}
|
||||
if !t.PausedFrom.IsZero() {
|
||||
runs := len(notRunning) == 0
|
||||
late := !runs && t.PausedFrom.IsZero() && !now.Before(clock.Add(bound))
|
||||
if !runs && !t.PausedFrom.IsZero() {
|
||||
break // paused: no lateness, and no timer armed
|
||||
}
|
||||
late := !now.Before(clock.Add(bound))
|
||||
if late {
|
||||
p.tierLate(pipeline, branch, number, t, notRunning)
|
||||
// Lateness is written before it is said: the field, the finding, the event (§824 2.).
|
||||
if t.TierLateAt.IsZero() {
|
||||
t.TierLateAt = now
|
||||
if err := p.writeTier(key, t, rev, "tier-late-at"); err == nil || errors.Is(err, errSwapped) {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
p.raiseTierLate(pipeline, t, notRunning, have, readable)
|
||||
if t.TierLateSaid.IsZero() {
|
||||
p.sayTierLate(key, pipeline, branch, number, t, notRunning)
|
||||
}
|
||||
break
|
||||
}
|
||||
if len(notRunning) > 0 {
|
||||
if !t.TierLateAt.IsZero() && t.TierLateSaid.IsZero() {
|
||||
p.sayTierLate(key, pipeline, branch, number, t, notRunning) // owed still: said before any running of this pipeline
|
||||
}
|
||||
if !runs {
|
||||
if d := clock.Add(bound); next.IsZero() || d.Before(next) {
|
||||
next = d
|
||||
}
|
||||
break
|
||||
}
|
||||
// The tier runs: the next tier's wants are written, or every tier ran.
|
||||
// The tier runs, whether or not it was found late: the finding is cleared, and the next tier's wants are written, or
|
||||
// every tier ran.
|
||||
if readable && have[findingKey] {
|
||||
if err := p.findings.Delete(findingKey); err != nil {
|
||||
p.logf("the finding %s is not cleared, so the next tier of %s is not written yet: %v", findingKey, pipeline, err)
|
||||
break
|
||||
}
|
||||
delete(have, findingKey)
|
||||
p.logf("the finding %s is cleared: tier %d runs", findingKey, t.Tier)
|
||||
}
|
||||
later := int64(0)
|
||||
for _, m := range t.Movers {
|
||||
if m.Tier > t.Tier && (later == 0 || m.Tier < later) {
|
||||
@@ -262,14 +304,17 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
}
|
||||
}
|
||||
if later == 0 {
|
||||
if err := p.ends.st.drop(key); err != nil {
|
||||
p.logf("the tier progress %s is not deleted: %v", key, err)
|
||||
break
|
||||
}
|
||||
p.sayPipelineWanted(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeRunning, nil)
|
||||
// The last tier runs: `running` is said, and the key goes once the bus has taken it, never before (§824 1.).
|
||||
p.sayPipelineWantedTaken(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeRunning, nil, func() {
|
||||
if err := p.ends.st.drop(key); err != nil {
|
||||
p.logf("the tier progress %s is not deleted: %v", key, err)
|
||||
}
|
||||
})
|
||||
break
|
||||
}
|
||||
value, err := json.Marshal(tierProgress{Tier: later, Since: now, ClockFrom: now, Movers: t.Movers, Source: t.Source})
|
||||
moved := t
|
||||
moved.Tier, moved.Since, moved.ClockFrom, moved.PausedFrom = later, now, now, time.Time{}
|
||||
value, err := json.Marshal(moved)
|
||||
if err == nil {
|
||||
err = p.ends.st.swap(key, value, rev)
|
||||
}
|
||||
@@ -327,75 +372,90 @@ func (p *passer) notRunning(n assign.Nodes, placedOn func(module, branch string)
|
||||
return out
|
||||
}
|
||||
|
||||
// tierLate ends a pipeline's delivery at a tier past tier-bound: the finding tier-late is raised and pipeline-wanted says tier-late,
|
||||
// once each; the finding clears once the late movers run or a later pipeline moved them. The progress stays, so no later tier is
|
||||
// written, until no later tier's mover is kept at this pipeline any more.
|
||||
func (p *passer) tierLate(pipeline, branch, number string, t tierProgress, notRunning []meshwants.NotRunning) {
|
||||
o := tierLateFinding(pipeline, t.Tier, notRunning)
|
||||
// raiseTierLate raises the finding tier-late of pipeline naming the late tier, when the findings bucket holds none of the pipeline
|
||||
// (read from the bucket, never from what the process said, H-A-722); a bucket not read raises nothing.
|
||||
func (p *passer) raiseTierLate(pipeline string, t tierProgress, notRunning []meshwants.NotRunning, have map[string]bool, readable bool) {
|
||||
o := tierLateFinding(pipeline, t, notRunning)
|
||||
key := views.FindingKey(o.Scope, assign.KeyID(o.ID), o.Kind)
|
||||
if len(notRunning) > 0 {
|
||||
if !p.said[key+".raised"] {
|
||||
if p.findings.Put != nil {
|
||||
if err := p.findings.Put(o.Finding(p.clock())); err != nil {
|
||||
p.logf("the finding %s is not written: %v", key, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
p.said[key+".raised"] = true
|
||||
delete(p.said, key+".cleared")
|
||||
p.logf("pipeline %s: tier %d is late (tier-bound %s): %s; no later tier is written", pipeline, t.Tier, p.tierBoundOf(), o.Summary)
|
||||
p.sayPipelineWanted(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeTierLate, notRunning)
|
||||
}
|
||||
} else if !p.said[key+".cleared"] {
|
||||
if p.findings.Delete != nil {
|
||||
if err := p.findings.Delete(key); err != nil {
|
||||
p.logf("the finding %s is not deleted: %v", key, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
p.said[key+".cleared"] = true
|
||||
delete(p.said, key+".raised")
|
||||
if !readable || have[key] {
|
||||
return
|
||||
}
|
||||
for _, m := range t.Movers {
|
||||
if m.Tier <= t.Tier {
|
||||
continue
|
||||
}
|
||||
if end, ok := p.ends.endOf(m.Module, branch); ok && end.Pipeline == pipeline {
|
||||
return // a later tier's mover still kept at this pipeline: its want stays unwritten
|
||||
}
|
||||
if err := p.findings.Put(o.Finding(p.clock())); err != nil {
|
||||
p.logf("the finding %s is not written: %v", key, err)
|
||||
return
|
||||
}
|
||||
if len(notRunning) == 0 {
|
||||
if err := p.ends.st.drop(tierKey(pipeline)); err != nil {
|
||||
p.logf("the tier progress of %s is not deleted: %v", pipeline, err)
|
||||
have[key] = true
|
||||
p.logf("pipeline %s: tier %d is late (tier-bound %s): %s; the next tier is written once it runs", pipeline, t.Tier, p.tierBoundOf(), o.Summary)
|
||||
}
|
||||
|
||||
// sayTierLate owes `pipeline-wanted` `tier-late` of pipeline once, under its id; once the bus has taken it, the progress's
|
||||
// `tier-late-said` is written (§824 2.). A refused say is owed and said again (§832).
|
||||
func (p *passer) sayTierLate(key, pipeline, branch, number string, t tierProgress, notRunning []meshwants.NotRunning) {
|
||||
p.sayPipelineWantedTaken(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeTierLate, notRunning, func() { p.markTierLateSaid(key, pipeline) })
|
||||
}
|
||||
|
||||
// markTierLateSaid writes `tier-late-said`, the time the bus took the event, by compare-and-set on the key.
|
||||
func (p *passer) markTierLateSaid(key, pipeline string) {
|
||||
for {
|
||||
t, rev, ok := p.ends.tiersOf(pipeline)
|
||||
if !ok || !t.TierLateSaid.IsZero() {
|
||||
return
|
||||
}
|
||||
t.TierLateSaid = p.clock().UTC()
|
||||
if err := p.writeTier(key, t, rev, "tier-late-said"); !errors.Is(err, errSwapped) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tierLateFinding is the finding tier-late of pipeline's tier, naming the movers and machines not running (design 47 H §751).
|
||||
func tierLateFinding(pipeline string, tier int64, notRunning []meshwants.NotRunning) assign.Observed {
|
||||
// tierLateSince is the time of the finding tier-late a key of the earlier rule stands with, as the findings bucket holds it; now
|
||||
// when it cannot be read (H-A-828).
|
||||
func (p *passer) tierLateSince(findingKey string, now time.Time) time.Time {
|
||||
if p.findings.Get != nil {
|
||||
if f, ok, err := p.findings.Get(findingKey); err == nil && ok && !f.Since.IsZero() {
|
||||
return f.Since.UTC()
|
||||
}
|
||||
}
|
||||
return now
|
||||
}
|
||||
|
||||
// tierLateFinding is the finding tier-late of pipeline's tier, naming the movers and machines not running (design 47 H §751, §824
|
||||
// 3.); a mover with no version is named in §826's words.
|
||||
func tierLateFinding(pipeline string, t tierProgress, notRunning []meshwants.NotRunning) assign.Observed {
|
||||
var named []string
|
||||
for _, nr := range notRunning {
|
||||
if i := slices.IndexFunc(t.Movers, func(m tierMover) bool { return m.Module == nr.Module && m.NoVersion }); i >= 0 {
|
||||
named = append(named, fmt.Sprintf("%s: no version released at %s", nr.Module, t.Movers[i].Fp))
|
||||
continue
|
||||
}
|
||||
named = append(named, fmt.Sprintf("%s on %s", nr.Module, strings.Join(nr.Machines, ", ")))
|
||||
}
|
||||
summary := fmt.Sprintf("pipeline %s: tier %d does not run within tier-bound: %s", pipeline, tier, strings.Join(named, "; "))
|
||||
summary := fmt.Sprintf("pipeline %s: tier %d does not run within tier-bound: %s", pipeline, t.Tier, strings.Join(named, "; "))
|
||||
return assign.Observed{Scope: mcc.ScopeDelivery, ID: pipeline, Kind: kindTierLate, Severity: mcseat.FindingSeverityWarning,
|
||||
Summary: summary, Headline: "A delivery's tier does not run in time",
|
||||
Explanation: summary + ". The assigner writes no later tier of this pipeline; the delivery ends here.",
|
||||
Explanation: summary + ". The delivery record ends failed. The assigner writes the next tier once this tier runs on every present placing machine.",
|
||||
Source: "assigner." + kindTierLate}
|
||||
}
|
||||
|
||||
// sayPipelineWanted says the seat mesh-wants' pipeline-wanted of pipeline, once (its id the pipeline and the outcome): its
|
||||
// revision the number of the pipeline's key `<branch>.<revision>`, its source the one the pipeline-ended named (design 47
|
||||
// H-A-214, H-A-216), the key's number for a progress kept before it held one.
|
||||
// sayPipelineWanted says the seat mesh-wants' pipeline-wanted of pipeline (see sayPipelineWantedTaken), with nothing to do once the
|
||||
// bus has taken it.
|
||||
func (p *passer) sayPipelineWanted(pipeline, branch, number string, source int64, outcome string, notRunning []meshwants.NotRunning) {
|
||||
p.sayPipelineWantedTaken(pipeline, branch, number, source, outcome, notRunning, nil)
|
||||
}
|
||||
|
||||
// sayPipelineWantedTaken owes the seat mesh-wants' pipeline-wanted of pipeline once (its id the pipeline and the outcome): its
|
||||
// revision the number of the pipeline's key `<branch>.<revision>`, its source the one the pipeline-ended named (design 47
|
||||
// H-A-214, H-A-216), the key's number for a progress kept before it held one. It is said on the subject of its branch and revision
|
||||
// whatever the pipeline's form, its body naming the pipeline whole (H-A-839); taken runs once the bus has taken it.
|
||||
func (p *passer) sayPipelineWantedTaken(pipeline, branch, number string, source int64, outcome string, notRunning []meshwants.NotRunning, taken func()) {
|
||||
var revision int64
|
||||
_, _ = fmt.Sscan(number, &revision)
|
||||
if source <= 0 {
|
||||
source = revision
|
||||
}
|
||||
body := meshwants.PipelineWantedEvent{V: keys.Version, Pipeline: pipeline, Branch: branch, Source: source, Revision: revision, Outcome: outcome, NotRunning: notRunning}
|
||||
event := meshwants.EventPipelineWanted + "." + pipeline
|
||||
p.wantsOwe("pipeline."+pipeline, event, body, "pipeline-wanted."+pipeline+"."+outcome, nil)
|
||||
event := meshwants.EventPipelineWanted + "." + keys.EscapeName(branch) + "." + number
|
||||
p.wantsOwe("pipeline."+pipeline, event, body, "pipeline-wanted."+pipeline+"."+outcome, taken)
|
||||
}
|
||||
|
||||
// tierDeadline sets the earliest tier's deadline the one timer wakes the pass at (H-A-56, H-A-846); zero for none.
|
||||
|
||||
@@ -56,7 +56,7 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
var said []meshwants.PipelineWanted
|
||||
p.publishWants = func(event string, body any, _ string) error {
|
||||
if b, ok := body.(meshwants.PipelineWantedEvent); ok {
|
||||
if event != "pipeline-wanted."+pipeline {
|
||||
if event != "pipeline-wanted."+trunkBranch+".5" { // H-A-839: the subject of its branch and revision, an again pipeline's too
|
||||
t.Errorf("pipeline-wanted said as %s", event)
|
||||
}
|
||||
said = append(said, b)
|
||||
@@ -186,6 +186,105 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
t.Error("a consumer's want is written after its provider's tier was late")
|
||||
}
|
||||
}
|
||||
// Design 47 H2b §824 (H-A-828, H-A-858): a delivery whose tier passed tier-bound goes on once that tier runs.
|
||||
t.Run("a late tier goes on once it runs", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
wanted := func(module string) bool {
|
||||
key, _ := mwc.WantKey("g14", module)
|
||||
_, ok := r.wantsKV.values[key]
|
||||
return ok
|
||||
}
|
||||
run := func(module, fp string) {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: module, Fingerprint: fp})
|
||||
if err := r.p.w.hearRunning("running.g14."+module, raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
r.pass(30 * time.Minute)
|
||||
prog, _, _ := r.p.ends.tiersOf(pipeline)
|
||||
if len(r.said) != 1 || r.said[0].Outcome != meshwants.PipelineWantedOutcomeTierLate || len(r.findings) != 1 || prog.TierLateAt.IsZero() || prog.TierLateSaid.IsZero() {
|
||||
t.Fatalf("AC-824a: at minute 30 said %+v findings %v progress %+v", r.said, r.findings, prog)
|
||||
}
|
||||
// AC-824c: a restart between the two keeps both fields
|
||||
r.restart()
|
||||
if prog, _, _ := r.p.ends.tiersOf(pipeline); prog.TierLateAt.IsZero() || prog.TierLateSaid.IsZero() {
|
||||
t.Fatalf("AC-824c: a restart lost the fields: %+v", prog)
|
||||
}
|
||||
run("db", db)
|
||||
r.pass(45 * time.Minute)
|
||||
if !wanted("web") || len(r.findings) != 0 {
|
||||
t.Fatalf("AC-824a: at minute 45 the consumer's want is %v, findings %v", wanted("web"), r.findings)
|
||||
}
|
||||
// AC-824b: a second tier found late raises the finding naming it and says no second pipeline-wanted
|
||||
r.pass(76 * time.Minute)
|
||||
f := r.findings["delivery."+assign.KeyID(pipeline)+".tier-late"]
|
||||
if len(r.said) != 1 || !strings.Contains(f.Summary, "tier 2 does not run") {
|
||||
t.Errorf("AC-824b: said %+v, finding %+v", r.said, f)
|
||||
}
|
||||
run("web", web)
|
||||
r.pass(77 * time.Minute)
|
||||
if len(r.said) != 2 || r.said[1].Outcome != meshwants.PipelineWantedOutcomeRunning || len(r.findings) != 0 {
|
||||
t.Errorf("AC-824a: running said %+v, findings %v", r.said, r.findings)
|
||||
}
|
||||
if _, _, ok := r.p.ends.tiersOf(pipeline); ok {
|
||||
t.Error("the key stands after running was taken")
|
||||
}
|
||||
})
|
||||
t.Run("a tier-late the bus refuses is said again after a restart, before running, and the key stands until running is taken", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
r.refuse = true
|
||||
r.pass(30 * time.Minute)
|
||||
prog, _, _ := r.p.ends.tiersOf(pipeline)
|
||||
if len(r.said) != 0 || prog.TierLateAt.IsZero() || !prog.TierLateSaid.IsZero() {
|
||||
t.Fatalf("AC-824d: a refused say was taken: said %+v progress %+v", r.said, prog)
|
||||
}
|
||||
r.restart()
|
||||
r.refuse = false
|
||||
for _, m := range []struct{ module, fp string }{{"db", db}, {"web", web}} {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: m.module, Fingerprint: m.fp})
|
||||
_ = r.p.w.hearRunning("running.g14."+m.module, raw)
|
||||
}
|
||||
r.pass(31 * time.Minute)
|
||||
r.pass(32 * time.Minute)
|
||||
if len(r.said) != 2 || r.said[0].Outcome != meshwants.PipelineWantedOutcomeTierLate || r.said[1].Outcome != meshwants.PipelineWantedOutcomeRunning {
|
||||
t.Errorf("AC-824d: said %+v, want tier-late then running", r.said)
|
||||
}
|
||||
})
|
||||
t.Run("a key of the earlier rule with a tier-late in the bucket says no second one; a tier past its bound pauses for no later ask; a refused clear holds the next tier", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
since := r.start.Add(-time.Hour)
|
||||
r.findings["delivery."+assign.KeyID(pipeline)+".tier-late"] = mcseat.Finding{Scope: "delivery", ID: pipeline, Kind: kindTierLate, Since: since}
|
||||
r.pass(31 * time.Minute)
|
||||
prog, _, _ := r.p.ends.tiersOf(pipeline)
|
||||
if len(r.said) != 0 || !prog.TierLateAt.Equal(since) || !prog.TierLateSaid.Equal(since) {
|
||||
t.Fatalf("AC-824e: said %+v progress %+v, want both fields at the finding's since", r.said, prog)
|
||||
}
|
||||
// AC-824h: the tier is past its bound, so a later ask pauses nothing
|
||||
akey, _ := asks.RecordAskKey("g14", "db", "sha256:"+strings.Repeat("a", 64))
|
||||
r.p.w.put(buckets.Asks(), akey, []byte(`{}`))
|
||||
r.pass(32 * time.Minute)
|
||||
if prog, _, _ := r.p.ends.tiersOf(pipeline); !prog.PausedFrom.IsZero() {
|
||||
t.Errorf("AC-824h: a paused-from after the bound: %+v", prog)
|
||||
}
|
||||
// AC-824n: the clear refused once holds the next tier's progress
|
||||
r.deleteRefused = 1
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: "db", Fingerprint: db})
|
||||
_ = r.p.w.hearRunning("running.g14.db", raw)
|
||||
r.pass(33 * time.Minute)
|
||||
if prog, _, _ := r.p.ends.tiersOf(pipeline); prog.Tier != 1 {
|
||||
t.Fatalf("AC-824n: tier 2's progress is written while the clear is refused: %+v", prog)
|
||||
}
|
||||
r.pass(34 * time.Minute)
|
||||
if prog, _, _ := r.p.ends.tiersOf(pipeline); prog.Tier != 2 || prog.TierLateAt.IsZero() {
|
||||
t.Errorf("AC-824n: the next pass, with the clear taken, writes tier 2 and carries the fields: %+v", prog)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// H-A-270, H-A-273, H-A-277 (1): a pipeline's tier progress holds every passed mover, versioned or not, and a tier with a mover
|
||||
@@ -310,3 +409,82 @@ func (r *refusingEnds) swap(string, []byte, uint64) error {
|
||||
}
|
||||
return errors.New("the bucket is full")
|
||||
}
|
||||
|
||||
// tierRig is one pass loop of a pipeline of db (tier 1) and web (tier 2) on g14 with the findings of a bucket the test reads, and a
|
||||
// restart that makes a new passer on the same kept progress (the process's memory gone).
|
||||
type tierRig struct {
|
||||
t *testing.T
|
||||
p *passer
|
||||
start time.Time
|
||||
now time.Time
|
||||
wantsKV *memKV
|
||||
findings map[string]mcseat.Finding
|
||||
said []meshwants.PipelineWanted
|
||||
refuse bool
|
||||
deleteRefused int
|
||||
ends *memEnds
|
||||
db, web string
|
||||
}
|
||||
|
||||
func newTierRig(t *testing.T, db, web, pipeline string) *tierRig {
|
||||
r := &tierRig{t: t, start: time.Date(2026, 11, 27, 4, 0, 0, 0, time.UTC), findings: map[string]mcseat.Finding{}, ends: newMemEnds(), db: db, web: web}
|
||||
r.now = r.start
|
||||
r.build()
|
||||
e := ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("db", db, "0.2.0", 1, mpr.StepResultOutcomePassed), mover("web", web, "0.1.2", 2, mpr.StepResultOutcomePassed))
|
||||
e.Source, e.Pipeline = 4, pipeline
|
||||
if _, err := r.p.ends.take(e); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.pass(0)
|
||||
return r
|
||||
}
|
||||
|
||||
// build makes the passer over the kept state: a start of the process.
|
||||
func (r *tierRig) build() {
|
||||
t := r.t
|
||||
r.wantsKV = &memKV{values: map[string][]byte{}}
|
||||
p := newPasser(kvSet{buckets.Wants(): r.wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, r.start)
|
||||
p.now = func() time.Time { return r.now }
|
||||
p.say = func(oc.Condition) error { return nil }
|
||||
p.findings = assign.Findings{Put: func(f mcseat.Finding) error { r.findings[views.FindingKey(f.Scope, f.ID, f.Kind)] = f; return nil },
|
||||
Keys: func() ([]string, error) { return slices.Collect(maps.Keys(r.findings)), nil },
|
||||
Get: func(key string) (mcseat.Finding, bool, error) { f, ok := r.findings[key]; return f, ok, nil },
|
||||
Delete: func(key string) error {
|
||||
if r.deleteRefused > 0 {
|
||||
r.deleteRefused--
|
||||
return errors.New("the bucket is full")
|
||||
}
|
||||
delete(r.findings, key)
|
||||
return nil
|
||||
}}
|
||||
p.publishWants = func(event string, body any, _ string) error {
|
||||
if r.refuse {
|
||||
return errors.New("the bus refuses")
|
||||
}
|
||||
if b, ok := body.(meshwants.PipelineWantedEvent); ok {
|
||||
r.said = append(r.said, b)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
for i, m := range []struct{ name, fp string }{{"db", r.db}, {"web", r.web}} {
|
||||
digest := strings.Repeat(string(rune('e'+i)), 64)
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: m.fp, Manifest: digest, Repository: "novox/" + m.name, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||
putModuleRaw(p.w, trunkBranch, m.name, mod)
|
||||
p.w.manifests[digest] = parsed{module: m.name, manifest: catalogue.Manifest{Module: m.name}}
|
||||
}
|
||||
placeOn(t, p.w, "g14", "db", "web")
|
||||
p.w.mu.Lock()
|
||||
p.w.runningHeard = true
|
||||
p.w.mu.Unlock()
|
||||
p.ends = newPipelineEnds(r.ends, func() {}, t.Logf)
|
||||
p.ends.trunk, p.ends.now = p.w.trunkName, func() time.Time { return r.now }
|
||||
r.p = p
|
||||
}
|
||||
|
||||
func (r *tierRig) restart() { r.build() }
|
||||
|
||||
// pass makes one pass at minutes after the start.
|
||||
func (r *tierRig) pass(minutes time.Duration) {
|
||||
r.now = r.start.Add(minutes)
|
||||
r.p.wants(context.Background())
|
||||
}
|
||||
|
||||
@@ -136,7 +136,9 @@ type Findings struct {
|
||||
Put func(f mcseat.Finding) error
|
||||
Delete func(key string) error
|
||||
Keys func() ([]string, error)
|
||||
Now func() time.Time
|
||||
// Get reads one finding's value by its key, false when none stands (design 47 H2b H-A-828); nil reads none.
|
||||
Get func(key string) (mcseat.Finding, bool, error)
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
// Say is say with each condition written as a finding (or its finding deleted), which the condition keeper carries, the
|
||||
|
||||
Reference in New Issue
Block a user