The watchman keeps each started step under <pipeline>/<step>/<artifact>, begins its clock at step-started and at each mesh-wants step-progress, build seat step-progress or step-ended of the step's ask or an ask its shared names, raises pipeline-stands past five minutes, clears it at the step's step-ended, owes none to a step on a person or queued for a build node, and seeds from stands at start. Builds: design 47 G-24 §731, §732, §733 (watchman case); A-468j, A-469, A-469o, A-469p, A-469t, A-469r
131 lines
6.3 KiB
Go
131 lines
6.3 KiB
Go
package watch
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
|
)
|
|
|
|
func stepBody(pipeline, step, artifact, ask, outcome string, at time.Time, shared ...string) []byte {
|
|
var sh []meshpipelinerunner.Shared
|
|
for _, a := range shared {
|
|
sh = append(sh, meshpipelinerunner.Shared{Run: "r", Ask: a})
|
|
}
|
|
b, _ := json.Marshal(meshpipelinerunner.StepEvent{Pipeline: pipeline, Branch: "main", Module: "m", Commit: "c", At: &at,
|
|
Result: meshpipelinerunner.StepResult{Step: step, Artifact: artifact, Ask: ask, Outcome: outcome, Shared: sh}})
|
|
return b
|
|
}
|
|
|
|
func wantsProgress(ask string, at time.Time, shared ...string) []byte {
|
|
var sh []meshwants.Shared
|
|
for _, a := range shared {
|
|
sh = append(sh, meshwants.Shared{Machine: "n1", Run: "r", Ask: a})
|
|
}
|
|
b, _ := json.Marshal(meshwants.StepProgressEvent{Ask: ask, Asker: "a", At: at, Phase: "run", Shared: sh})
|
|
return b
|
|
}
|
|
|
|
// design 47 G §731, §732, A-468j, A-469, A-469o, A-469p (test 108's and 109's watchman case): a step started and not ended is
|
|
// timed from its `step-started` and from every sign of life of its own ask or an ask its `shared` names, raises `pipeline-stands`
|
|
// at the five-minute bound and clears at its `step-ended`; a step on a person or queued for a build node is owed none; the open
|
|
// steps are seeded from `stands`.
|
|
func TestAStepThatReadsARunIsTimed(t *testing.T) {
|
|
run := meshpipelinerunner.StepResultOutcomeRunning
|
|
key := func(pipeline, step, artifact string) string {
|
|
return signalKey(stepRow, StepFindingID(stepKey(pipeline, step, artifact)))
|
|
}
|
|
finding := func(pipeline, step, artifact string) string {
|
|
return FindingKey(ScopeDelivery, StepFindingID(stepKey(pipeline, step, artifact)), KindPipelineStands)
|
|
}
|
|
cases := []struct {
|
|
name string
|
|
run func(w *Watchman, o *fakeOut, c *clock)
|
|
// stands are the finding keys that stand at the end.
|
|
stands []string
|
|
}{
|
|
{"no progress for five minutes", func(w *Watchman, o *fakeOut, c *clock) {
|
|
w.StepStarted(stepBody("p", "composition", "", "a1", run, c.t))
|
|
if o.ttls[key("p", "composition", "")] != ProgressBound || len(o.findings) != 0 {
|
|
t.Fatalf("within the bound: %v %v", o.ttls, o.findings)
|
|
}
|
|
expire(w, c, key("p", "composition", ""), ProgressBound)
|
|
}, []string{finding("p", "composition", "")}},
|
|
{"the assigner's progress of its ask begins the clock again, and names the runs", func(w *Watchman, o *fakeOut, c *clock) {
|
|
w.StepStarted(stepBody("p", "composition", "", "a1", run, c.t))
|
|
c.t = c.t.Add(4 * time.Minute)
|
|
w.WantsStepProgress(wantsProgress("a1", c.t, "run1"))
|
|
if o.ttls[key("p", "composition", "")] != ProgressBound {
|
|
t.Fatalf("clock not begun again: %v", o.ttls)
|
|
}
|
|
c.t = c.t.Add(4 * time.Minute)
|
|
w.StepProgress("node-build-go", "n1", askBody("run1", c.t)) // an ask the progress named
|
|
if o.ttls[key("p", "composition", "")] != ProgressBound {
|
|
t.Fatalf("a named run's progress is the step's: %v", o.ttls)
|
|
}
|
|
w.WantsStepProgress(wantsProgress("other", c.t))
|
|
}, nil},
|
|
{"the progress of a shared run's ask, and its end, begin a test step's clock again", func(w *Watchman, o *fakeOut, c *clock) {
|
|
w.StepStarted(stepBody("p", "unit", "m:program", "a2", run, c.t, "run-ask"))
|
|
c.t = c.t.Add(4 * time.Minute)
|
|
w.StepProgress("node-build-go", "n1", askBody("run-ask", c.t))
|
|
c.t = c.t.Add(4 * time.Minute)
|
|
w.AskEnded("node-build-go", askBody("run-ask", c.t))
|
|
expire(w, c, key("p", "unit", "m:program"), ProgressBound)
|
|
}, []string{finding("p", "unit", "m:program")}},
|
|
{"the artifact keys the step: the other artifact's end clears only its own", func(w *Watchman, o *fakeOut, c *clock) {
|
|
w.StepStarted(stepBody("p", "unit", "m:program", "a2", run, c.t))
|
|
w.StepStarted(stepBody("p", "unit", "m:tools", "a3", run, c.t))
|
|
c.t = c.t.Add(ProgressBound)
|
|
w.Pulse(key("p", "unit", "m:program"), Expired, c.t)
|
|
w.Pulse(key("p", "unit", "m:tools"), Expired, c.t)
|
|
w.StepEnded(stepBody("p", "unit", "m:tools", "a3", meshpipelinerunner.StepResultOutcomePassed, c.t))
|
|
}, []string{finding("p", "unit", "m:program")}},
|
|
{"its step-ended clears the finding", func(w *Watchman, o *fakeOut, c *clock) {
|
|
w.StepStarted(stepBody("p", "composition", "", "a1", run, c.t))
|
|
expire(w, c, key("p", "composition", ""), ProgressBound)
|
|
w.StepEnded(stepBody("p", "composition", "", "a1", meshpipelinerunner.StepResultOutcomeFailed, c.t))
|
|
}, nil},
|
|
{"a step on a person or queued for a build node is owed none", func(w *Watchman, o *fakeOut, c *clock) {
|
|
w.StepStarted(stepBody("p", "approval", "", "", meshpipelinerunner.StepResultOutcomeWaiting, c.t))
|
|
w.StepStarted(stepBody("p", "unit", "m:program", "a2", meshpipelinerunner.StepResultOutcomeWaitingForABuildNode, c.t))
|
|
c.t = c.t.Add(time.Hour)
|
|
if len(o.pulses) != 0 || len(o.findings) != 0 {
|
|
t.Fatalf("owed none: %v %v", o.pulses, o.findings)
|
|
}
|
|
w.StepStarted(stepBody("p", "unit", "m:program", "a2", run, c.t)) // taken: now owed
|
|
expire(w, c, key("p", "unit", "m:program"), ProgressBound)
|
|
}, []string{finding("p", "unit", "m:program")}},
|
|
{"seeded from stands: each clock begins at the start, a step on a person is owed none", func(w *Watchman, o *fakeOut, c *clock) {
|
|
w.SeedSteps([]meshpipelinerunner.Wait{
|
|
{Pipeline: "p", Step: "composition", Ask: "a1", On: ""},
|
|
{Pipeline: "p", Step: "unit", Artifact: "m:program", Shared: []meshpipelinerunner.Shared{{Run: "r", Ask: "run-ask"}}},
|
|
{Pipeline: "p", Step: "approval", On: meshpipelinerunner.WaitOnPerson},
|
|
})
|
|
if len(o.findings) != 0 || o.ttls[key("p", "composition", "")] != ProgressBound || len(o.pulses) != 2 {
|
|
t.Fatalf("seeded at the start: %v %v", o.ttls, o.findings)
|
|
}
|
|
c.t = c.t.Add(4 * time.Minute)
|
|
w.WantsStepProgress(wantsProgress("a1", c.t)) // the composition step lives
|
|
expire(w, c, key("p", "unit", "m:program"), time.Minute)
|
|
}, []string{finding("p", "unit", "m:program")}},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
w, o, c := setup()
|
|
w.SetStepBound(ProgressBound) // setup shortens it for the older tests
|
|
tc.run(w, o, c)
|
|
if len(o.findings) != len(tc.stands) {
|
|
t.Fatalf("findings %v, want %v", o.findings, tc.stands)
|
|
}
|
|
for _, k := range tc.stands {
|
|
if _, ok := o.findings[k]; !ok {
|
|
t.Fatalf("findings %v, want %s", o.findings, k)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|