", `changes?pipeline=main.12\u0026since=`}},
{"a stage's worst outcome follows the runner's step words, an unknown one counting as failed", func() string {
at := func(o ...string) string {
var ss []seat.StepResult
for _, x := range o {
ss = append(ss, seat.StepResult{Step: "unit", Outcome: x})
}
return stageCell(ss, t0).Text()
}
return strings.Join([]string{at("passed", "running", "waiting for a build node", "not asked", "running"), at("cancelled", "could not run"),
at("frobbed", "passed"), at("running", "running"), at("nothing to run"), at("failed", "passed", "carried"), at()}, "|")
}, []string{"not asked 1/5|could not run 1/2|frobbed 1/2|running|nothing to run|failed 1/3|"}},
{"a mover's page is its steps, each asked, taken and ended, how long it waited and how long it ran", func() string {
return web("/pipelines/show?pipeline=main.12&mover=beta")
}, []string{"
ASKED
TAKEN
ENDED
WAITED
RAN
",
"
unit beta:program
node-build-go
n1
could not run
" + since(started) + "
" + since(taken) + "
" + since(ended) + "
2m40s
20s
no build node
",
"
lint beta:program
node-build-go
could not run
" + since(started) + "
" + since(ended) + "
3m0s
"}},
{"the terminal view's mover splits each step's waiting from its running", func() string {
a, err := p.Show("main.12", "beta", "")
if err != nil {
return err.Error()
}
return text(func(b *bytes.Buffer) { PipelineTable(b, PipelineAnswer{ShowAnswer: a}, "beta") })
}, []string{"STEPS OF beta", "OUTCOME ASKED TAKEN ENDED WAITED RAN WHY", "could not run " + since(started) + " " + since(taken) + " " + since(ended) + " 2m40s 20s no build node"}},
{"a step still waiting counts its wait to now, one running its run", func() string {
now := t0.Add(400e9)
w1, r1 := waitedRan(seat.StepResult{AskedAt: &started}, now)
w2, r2 := waitedRan(seat.StepResult{AskedAt: &started, TakenAt: &taken}, now)
w3, r3 := waitedRan(seat.StepResult{Ended: &ended}, now)
return fmt.Sprintf("waiting %s/%s; running %s/%s; never asked %q/%q", w1, r1, w2, r2, w3, r3)
}, []string{`waiting 6m40s/; running 2m40s/4m0s; never asked ""/""`}},
{"the terminal view's pipeline is its header and a block per tier, as the page's", func() string {
path, sm := served(t)
fill(sm, delivery...)
sm.SetPipelines(p)
var got *PipelineAnswer
if err := AskPipelines(path, "", 0, "main.12", "", "", false, func(_ PipelinesPage, a *PipelineAnswer) bool { got = a; return true }); err != nil {
return err.Error()
}
return text(func(b *bytes.Buffer) { PipelineTable(b, *got, "") })
}, []string{"PIPELINE main.12: failed; first failure: unit beta:program: could not run: no build node; 1 of 4 movers",
"TIER 1 MOVER OUTCOME BUILD LINT UNIT INTEGRATION VALIDATE COMPOSITION CODE REVIEW APPROVAL N1 N2 N3",
"alpha passed passed - - - - - passed - running the pipeline's build running the pipeline's build -",
"delta passed - - - - - - - - - - -", "TIER 2",
"beta failed - - could not run 1/2 - - - - waiting wanted applying no want written",
"gamma passed - - - - - - - - held: connection refused held: health failed on n1 -"}},
{"the web list asks the newest limit of every branch", func() string { return web("/pipelines?limit=1") }, []string{
"main.12", `name="limit" value="1"`}},
{"the web list is every branch's newest 20 by default, the branch a column", func() string { return web("/pipelines") }, []string{
"
PIPELINES
", `module `, "
BRANCH
", "main.12
main
",
"release.8
release
", "release.7", `name="limit" value="20"`}},
{"the only filter is a module: the pipelines that carry it", func() string {
got := web("/pipelines?module=beta")
if strings.Contains(got, "release.8") {
return "release.8 does not carry beta: " + got
}
return got
}, []string{"
PIPELINES CARRYING beta
", "main.12
main
"}},
{"a delivery of a branch the view reads no list of links through every branch's list", func() string {
q := NewPipelines(runner.call, nil, 0, nil)
q.Refresh()
return q.Of(testBranch, 4) + " " + q.Of("main", 4)
}, []string{"release.8 "}},
{"a pipeline the runner does not hold says so", func() string { return web("/pipelines/show?pipeline=main.99") }, []string{"unreadable: ", "no pipeline main.99"}},
{"a delivery links to the newest pipeline of its source revision", func() string {
return text(func(b *bytes.Buffer) { Table(b, m.Snapshot()) }) + web("/")
}, []string{testBranch + ": source revision 4: delivered (pipeline release.8)", `(pipeline)`, `Pipelines`}},
}
for _, r := range rows {
t.Run(r.name, func(t *testing.T) {
got := r.got()
for _, w := range r.want {
if !strings.Contains(got, w) {
t.Errorf("got %s\nwant it to hold %q", got, w)
}
}
})
}
if got := web("/pipelines?limit=1"); strings.Contains(got, "release.8") {
t.Errorf("the newest 1 shows release.8: %s", got)
}
for _, l := range []string{"0", "x"} {
rec := httptest.NewRecorder()
Web(m).ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/pipelines?limit="+l, nil))
if rec.Code != http.StatusBadRequest {
t.Errorf("limit %s = %d, want 400", l, rec.Code)
}
}
if strings.Contains(web("/pipelines"), "http-equiv=\"refresh\"") || strings.Contains(web("/pipelines/show?pipeline=main.12"), "http-equiv=\"refresh\"") {
t.Error("a pipelines page reloads on a timer")
}
t.Run("an event of the runner reads the lists again and tells the pages", func(t *testing.T) {
srv := httptest.NewServer(Web(m))
defer srv.Close()
v := p.Version()
res, err := http.Get(srv.URL + "/pipelines/changes?since=" + fmt.Sprint(v))
if err != nil {
t.Fatal(err)
}
defer res.Body.Close()
stream := bufio.NewReader(res.Body)
if line, _ := stream.ReadString('\n'); !strings.HasPrefix(line, ":") {
t.Fatalf("the stream starts %q", line)
}
shown := make(chan bool, 1)
go func() { shown <- changedWithin(ctx, p, "main.13", v) }()
runner.mu.Lock()
before := runner.lists
runner.mu.Unlock()
runner.setRows("main", seat.PipelineRow{Pipeline: "main.13", Source: 10, Revision: 13, Outcome: seat.PipelineOutcomeRunning, MoverCount: 1})
if err := p.Hear([]byte(`{"pipeline":"main.13","branch":"main","source":10}`)); err != nil {
t.Fatal(err)
}
if !<-shown {
t.Fatal("the page of the pipeline heard is not told")
}
for {
line, err := stream.ReadString('\n')
if err != nil {
t.Fatalf("the stream ended before the change: %v", err)
}
if line == "data: changed\n" {
break
}
}
runner.mu.Lock()
after := runner.lists
runner.mu.Unlock()
if !strings.Contains(web("/pipelines"), "main.13") || after <= before {
t.Errorf("the list was not read again (%d lists, %d before): %s", after, before, web("/pipelines"))
}
if err := p.Hear([]byte(`{"step":"unit"}`)); err == nil {
t.Error("an event naming no pipeline is taken")
}
})
t.Run("a want or a have heard tells every pipeline's page, never the lists", func(t *testing.T) {
v := p.Version()
fill(m, haveFP(t, "n2", "gamma", fpNew, nodeengineclient.HealthOK))
if !changedWithin(ctx, p, "main.12", v) {
t.Fatal("the page of main.12 is not told of the have")
}
p.mu.Lock()
lists := p.changedSince("", v)
p.mu.Unlock()
if lists {
t.Error("a have tells the lists")
}
if got := web("/pipelines/show?pipeline=main.12"); !strings.Contains(got, `
held: connection refused
running the pipeline's build
`) {
t.Errorf("the page does not show gamma running on n2: %s", got)
}
})
t.Run("the terminal view follows the list on the socket, again at each event", func(t *testing.T) {
path, sm := served(t)
sm.SetPipelines(p)
var seen []string
heard := false
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *PipelineAnswer) bool {
seen = append(seen, page.Rows[0].Pipeline)
if !heard {
heard = true
runner.setRows("main", seat.PipelineRow{Pipeline: "main.14", Source: 11, Revision: 14, Outcome: seat.PipelineOutcomeRunning, MoverCount: 1})
if err := p.Hear([]byte(`{"pipeline":"main.14","mover":"alpha","revision":14}`)); err != nil { // a re-pinned names no branch
t.Error(err)
}
return true
}
return len(seen) < 2 || seen[len(seen)-1] != "main.14"
})
if err != nil || seen[len(seen)-1] != "main.14" {
t.Fatalf("followed %v, %v", seen, err)
}
var show *PipelineAnswer
if err := AskPipelines(path, "", 0, "main.12", "beta", "", false, func(_ PipelinesPage, a *PipelineAnswer) bool { show = a; return true }); err != nil {
t.Fatal(err)
}
if len(show.Pipeline.Steps) != 2 || show.Pipeline.Steps[0].Node != "n1" {
t.Fatalf("the mover's steps on the socket = %+v", show)
}
if err := AskPipelines(path, "", 0, "main.99", "", "", false, func(PipelinesPage, *PipelineAnswer) bool { return true }); err == nil || !strings.Contains(err.Error(), "no pipeline main.99") {
t.Fatalf("a pipeline the runner does not hold = %v", err)
}
})
t.Run("the pipelines heard are kept up to the setting pipelines-heard", func(t *testing.T) {
few := NewPipelines(runner.call, nil, 2, nil)
for _, k := range []string{"main.1", "main.2", "main.2", "main.3"} {
few.notify(k)
}
few.mu.Lock()
n, last := len(few.heard), few.heard["main.3"]
few.mu.Unlock()
if n > 2 || last == 0 {
t.Errorf("heard holds %d pipelines (main.3 at %d), want at most the setting's 2, the newest kept", n, last)
}
if d := NewPipelines(runner.call, nil, 0, nil); d.most != DefaultPipelinesHeard {
t.Errorf("the default keeps %d, want %d", d.most, DefaultPipelinesHeard)
}
})
t.Run("a list not read is shown unreadable and followed on, read again at the next event", func(t *testing.T) {
var mu sync.Mutex
away := true // the runner not answering yet, as the bus says when no holder listens
call := func(key string, body any) (json.RawMessage, error) {
mu.Lock()
defer mu.Unlock()
if away {
return nil, fmt.Errorf("nats: no responders available for request")
}
return runner.call(key, body)
}
up := NewPipelines(call, nil, 0, nil)
upCtx, upCancel := context.WithCancel(ctx)
defer upCancel()
go up.Run(upCtx)
if !changedWithin(upCtx, up, "", 0) {
t.Fatal("the lists were never read")
}
path, sm := served(t)
sm.SetPipelines(up)
var seen []PipelinesPage
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *PipelineAnswer) bool {
seen = append(seen, page)
if len(seen) == 1 {
mu.Lock()
away = false
mu.Unlock()
if err := up.Hear([]byte(`{"pipeline":"main.14"}`)); err != nil {
t.Error(err)
}
}
return page.Error != "" || len(page.Rows) == 0
})
if err != nil || len(seen) < 2 || !strings.Contains(seen[0].Error, "no responders") || seen[len(seen)-1].Rows[0].Pipeline != "main.14" {
t.Fatalf("followed %+v, %v; want the unreadable list, then main.14 after the event", seen, err)
}
var b bytes.Buffer
PipelinesTable(&b, seen[0])
if !strings.Contains(b.String(), "unreadable: ") {
t.Errorf("the terminal view of an unreadable list = %q", b.String())
}
})
}