assigner: a reader that leaves a run not yet taken, or whose place a rerun takes, has its wait ended superseded at once (A-470u)

Builds: design 47 G §727, §723; A-469y, A-470u.
This commit is contained in:
2026-11-17 13:09:18 +01:00
parent 21bef6c044
commit 20d6a68bfb
2 changed files with 45 additions and 11 deletions
@@ -751,12 +751,14 @@ func (r *compositionRuns) leave(pipeline string, stop func(ids []string)) ([]str
continue
}
var left []string
var leaving []meshwants.CompositionReader
run, ok, err := r.change(key, func(c *meshwants.CompositionRun) bool {
left = nil
left, leaving = nil, nil
keep := c.Readers[:0:0]
for _, reader := range c.Readers {
if reader.Pipeline == pipeline && reader.Step == meshwants.CompositionReaderStepComposition {
left = append(left, reader.ID)
leaving = append(leaving, reader)
continue
}
keep = append(keep, reader)
@@ -772,6 +774,9 @@ func (r *compositionRuns) leave(pipeline string, stop func(ids []string)) ([]str
continue
}
ids = append(ids, left...)
if run.Ended == nil && r.untaken(key, run.Ask) { // a reader leaving a run not yet taken: its wait ends at once (A-470u)
r.sayWaits(run, leaving, "superseded")
}
if stop != nil {
stop(left) // the steps that left say no end, the run's included
}
@@ -827,7 +832,9 @@ func (r *compositionRuns) rejoin(reader meshwants.CompositionReader, candidate,
if at >= 0 && run.Readers[at].ID == reader.ID {
return joined{key: key, run: run}, nil
}
var former []meshwants.CompositionReader
if at >= 0 {
former = []meshwants.CompositionReader{run.Readers[at]}
run.Readers[at] = reader
} else {
run.Readers = append(run.Readers, reader)
@@ -838,6 +845,7 @@ func (r *compositionRuns) rejoin(reader meshwants.CompositionReader, candidate,
return joined{}, err
}
if run.Ended == nil && r.untaken(key, run.Ask) { // as join: a reader of a run not yet taken waits for a build node (A-469y)
r.sayWaits(run, former, "superseded") // the place it takes: that wait ends at once (A-470u)
r.sayWaits(run, []meshwants.CompositionReader{reader}, "")
}
return joined{key: key, run: run}, nil
@@ -532,21 +532,47 @@ func TestACompositionRunsBoundTimesOwedProgress(t *testing.T) {
}
})
}
// A-469y: a step asked again that joins a running run not yet taken, beside a reader or in its pipeline's former reader's
// place, says its own wait held, as join does.
for _, c := range []struct{ name, id, pipeline string }{{"a rerun joins", "b", "main.3.b"}, {"a rerun takes its former place", "a2", "main.3.a"}} {
// A-469y, A-470u: a step asked again that joins a running run not yet taken, beside a reader or in its pipeline's former
// reader's place, says its own wait held, as join does; the former reader's wait, and that of a reader leaving, ends at once
// superseded.
held := func(m string) said { return said{meshwants.EventWaitHeld, "", m} }
gone := func(m string) said { return said{meshwants.EventWaitEnded, "superseded", m} }
for _, c := range []struct {
name string
act func(t *testing.T, r *compositionRuns)
want []said
}{
{"a rerun joins", func(t *testing.T, r *compositionRuns) {
again := reader("b")
again.Rerun = true
if _, err := r.rejoin(again, "main.3", "n1", "run-2"); err != nil {
t.Fatal(err)
}
}, []said{held("a"), held("b")}},
{"a rerun takes its former place", func(t *testing.T, r *compositionRuns) {
again := reader("a2")
again.Pipeline, again.Module, again.Rerun = "main.3.a", "a2", true
if _, err := r.rejoin(again, "main.3", "n1", "run-2"); err != nil {
t.Fatal(err)
}
}, []said{held("a"), gone("a"), held("a2")}},
{"a reader leaves", func(t *testing.T, r *compositionRuns) {
if _, err := r.join(reader("b"), "main.3", "n1", "run-2"); err != nil {
t.Fatal(err)
}
if _, err := r.leave("main.3.a", nil); err != nil {
t.Fatal(err)
}
}, []said{held("a"), held("b"), gone("a")}},
} {
t.Run(c.name, func(t *testing.T) {
_, r, saids, _, _ := setup(t)
if _, err := r.join(reader("a"), "main.3", "n1", "run-1"); err != nil {
t.Fatal(err)
}
again := reader(c.id)
again.Pipeline, again.Rerun = c.pipeline, true
if _, err := r.rejoin(again, "main.3", "n1", "run-2"); err != nil {
t.Fatal(err)
}
if want := []said{{meshwants.EventWaitHeld, "", "a"}, {meshwants.EventWaitHeld, "", c.id}}; !slices.Equal(*saids, want) {
t.Errorf("said %v, want %v", *saids, want)
c.act(t, r)
if !slices.Equal(*saids, c.want) {
t.Errorf("said %v, want %v", *saids, c.want)
}
})
}