Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type commit struct {
merges int // the pull request it merges, by its last line
trailer bool // an older release wrote the number as a Banyan-Merges trailer instead
trailers map[string]string
probes []string // the contexts its Banyan-Probe-Failed trailers name, in order
}

func (r *Repo) git(args ...string) (string, error) { return r.run("", "", args...) }
Expand Down Expand Up @@ -152,6 +153,9 @@ func (r *Repo) read(sha string) (commit, error) {
for _, l := range own {
if k, v, ok := strings.Cut(l, ": "); ok && strings.HasPrefix(k, "Banyan-") {
c.trailers[k] = v
if k == "Banyan-Probe-Failed" {
c.probes = append(c.probes, v)
}
}
}
if n, err := strconv.Atoi(c.trailers["Banyan-Merges"]); err == nil && c.merges == 0 {
Expand Down Expand Up @@ -294,7 +298,7 @@ func (r *Repo) build(sha, trunk queue.SHA) (queue.Build, error) {
at := sha
switch {
case top.trailers["Banyan-Probe-Of"] != "":
b.Kind, at = queue.Probe, top.parents[0]
b.Kind, b.Runs, at = queue.Probe, append([]string{}, top.probes...), top.parents[0]
case top.trailers["Banyan-Check"] != "":
b.Kind, at = queue.Check, top.parents[0]
case top.trailers["Banyan-Try"] != "" && top.merges > 0 && len(top.parents) == 2:
Expand Down
93 changes: 93 additions & 0 deletions internal/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,99 @@ func TestBuildsAreReadBackAsPushed(t *testing.T) {
}
}

// A probe reads back the contexts it was asked to run, each of its trailers in order, and one
// that names none reads back as asked to run none: an empty list, not a missing one.
func TestAProbeReadsBackEveryContextItWasAskedToRun(t *testing.T) {
o := newOrigin(t)
a := o.pr(1, "a", "a\n")
trunk := o.fetch()
one, _ := o.Repo.Merge(trunk, a, "")
note := "Banyan-Try: 1\nBanyan-Round: 1\nBanyan-Of: " + one + "\nBanyan-Probe-Of: " + one
two := o.Repo.Mark(one, note+"\nBanyan-Probe-Failed: linux (ci)\nBanyan-Probe-Failed: build: mac")
none := o.Repo.Mark(trunk, note)
for _, sha := range []queue.SHA{two, none} {
if err := o.Repo.Push(sha); err != nil {
t.Fatal(err)
}
}
o.fetch()
builds, err := o.Repo.Builds(trunk)
if err != nil {
t.Fatal(err)
}
runs := map[queue.SHA][]string{}
for _, b := range builds {
if b.Kind != queue.Probe {
t.Errorf("%.12s read back as kind %d, where it is a probe", b.SHA, b.Kind)
}
runs[b.SHA] = b.Runs
}
if want := []string{"linux (ci)", "build: mac"}; !slices.Equal(runs[two], want) {
t.Errorf("a probe of two contexts reads back as running %q, want %q", runs[two], want)
}
if runs[none] == nil || len(runs[none]) != 0 {
t.Errorf("a probe that names no context reads back as running %#v, want an empty list", runs[none])
}
}

// The candidate of #1 failed on contexts whose names end in a space, or hold nothing else, or
// a line break. The probe a tick pushes for it reads back as asked to run them as its trailers
// can say them, wherever they stand, and while CI has not begun it, a tick on the unchanged
// world pushes nothing more.
func TestAProbeOfContextsWhoseNamesEndInASpaceReadsBackAsAskedToRunThem(t *testing.T) {
for _, tc := range []struct{ failed, want []string }{
{[]string{"linux "}, []string{"linux"}},
{[]string{"mac ", "linux "}, []string{"mac", "linux"}},
{[]string{" "}, []string{}},
{[]string{"build\nlinux"}, []string{"build"}},
} {
failed, want := tc.failed, tc.want
t.Run(fmt.Sprintf("%q", failed), func(t *testing.T) {
o := newOrigin(t)
a := o.pr(1, "a", "a\n")
trunk := o.fetch()
one, _ := o.Repo.Merge(trunk, a, "")
if err := o.Repo.Push(one); err != nil {
t.Fatal(err)
}
c := queue.Config{Slots: 2, MaxBatch: 3, Probes: true}
tick := func() (pushed []queue.Build) {
o.fetch()
builds, err := o.Repo.Builds(trunk)
if err != nil {
t.Fatal(err)
}
for i, b := range builds {
if b.SHA == one {
builds[i].Verdict, builds[i].Failed = queue.Failure, failed
}
}
for _, act := range queue.Plan(queue.World{Trunk: trunk, PRs: []queue.PR{a}, Builds: builds, Repo: o.Repo}, c) {
if act.Do == "push" {
if err := o.Repo.Push(act.Build.SHA); err != nil {
t.Fatal(err)
}
pushed = append(pushed, act.Build)
}
}
return pushed
}
if first := tick(); len(first) != 1 || first[0].Kind != queue.Probe {
t.Fatalf("the first tick pushed %+v, want one probe", first)
}
if again := tick(); len(again) > 0 {
t.Errorf("a tick on the unchanged world pushed %d more builds", len(again))
}
builds, _ := o.Repo.Builds(trunk)
for _, b := range builds {
if b.Kind == queue.Probe && !slices.Equal(b.Runs, want) {
t.Errorf("the probe reads back as asked to run %q, want %q", b.Runs, want)
}
}
})
}
}

func TestLandingMovesTheTrunkAndTakesTheBranch(t *testing.T) {
o := newOrigin(t)
a, b := o.pr(1, "a", "a\n"), o.pr(2, "b", "b\n")
Expand Down
27 changes: 18 additions & 9 deletions internal/queue/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ func (p *plan) weigh(r *red) {
if b.Round == 0 && b.Verdict == Failure {
r.sha, r.failed = b.SHA, b.Failed
}
}
for _, b := range r.builds {
// A probe asked to run other jobs than the red's says nothing of it, and the next
// round, pushed with the jobs as they now stand, is what the red is judged on.
if !b.counts(r.failed) {
b.Verdict = Error
}
if b.Round > 0 && b.Pushed.After(r.pushed) {
r.pushed = b.Pushed
}
Expand All @@ -332,7 +339,7 @@ func (p *plan) weigh(r *red) {
r.running = true
return
case b.Verdict == Error:
r.void = true
r.void = r.void || b.counts(r.failed)
case b.Verdict == Success:
g = max(g, j)
}
Expand Down Expand Up @@ -368,11 +375,11 @@ func (p *plan) weigh(r *red) {
// test is how far the fair test of the pull request that prefix s adds has got: the builds,
// in order, of its prefix that failed, of the prefix below that passed in the next round, and
// of its own that failed in the round after that. A round is pushed only once CI has begun
// every build of the round before, so each began after the last, and a trunk or a CI that
// was broken for a while and failed both would have failed the pass between them. A test
// that is not whole counts only if it ends at the newest round, where it can still go on.
// No test reaches back past the round at which the rounds started over, nor across a round
// number that was skipped.
// every build of the round before, whether that build counts or not, so each began after the
// last, and a trunk or a CI that was broken for a while and failed both would have failed the
// pass between them. A test that is not whole counts only if it ends at the newest round,
// where it can still go on. No test reaches back past the round at which the rounds started
// over, nor across a round number that was skipped.
// With hope, a build still running counts as the verdict the test wants of it.
func (r *red) test(s int, hope bool) (t []Build) {
for n := r.over + 1; n <= r.last && len(t) < 3; n++ {
Expand Down Expand Up @@ -539,10 +546,10 @@ func (p *plan) rounds() {
// three rounds, so no more than three are begun past the last round read: until
// that one has reported whole, what its half says restarts no test.
test := span == 1 || (whole && span <= max(p.c.Slots, 2))
begun := !slices.ContainsFunc(r.rounds[r.last], func(b Build) bool { return !b.begun() })
begun := !slices.ContainsFunc(r.builds, func(b Build) bool { return b.Round > 0 && b.Round == r.last && !b.begun() })
var points []int
switch {
case r.passed, (r.tip || r.void) && p.w.Now.Sub(r.pushed) < p.c.Recheck, r.running && (r.flake || r.tip || !test || !begun || r.last >= r.read+3):
case r.passed, !begun, (r.tip || r.void) && p.w.Now.Sub(r.pushed) < p.c.Recheck, r.running && (r.flake || r.tip || !test || r.last >= r.read+3):
continue
case r.flake:
// The probes passed on the red tree itself, so a whole build of it decides.
Expand Down Expand Up @@ -593,6 +600,8 @@ func (p *plan) evidence(r *red, j int, whole bool) Build {
}
if whole {
b.Kind, red = Check, ""
} else {
b.Runs = append([]string{}, named(r.failed)...)
}
b.SHA = p.fresh(func(n int) SHA { return p.w.Repo.Mark(parent, note(b.Kind, b.Round, r.of, red, r.failed, n)) })
return b
Expand Down Expand Up @@ -682,7 +691,7 @@ func note(kind Kind, round int, of, red SHA, failed []string, try int) string {
s += "\nBanyan-Check: whole"
case Probe:
s += "\nBanyan-Probe-Of: " + red
for _, context := range failed {
for _, context := range named(failed) {
s += "\nBanyan-Probe-Failed: " + context
}
}
Expand Down
Loading