Runner: the test-run test waits on what it causes, never on a clock across a restart (issue 1984)

Test 109 (TestTestRunsAreAskedOncePerLevelAndMoveEveryReader) failed on a loaded build node and passed on the same
commit when it ran again. Test-only; no behaviour of the runner changes.

- The first start has a step bound of a minute, longer than the restart; the setting is rewritten to two seconds between
  stop() and start(), so the clock the first runner armed at the take cannot end the run before the restarted runner
  hears the first progress.
- start() waits for one more "take-ins: heard on the consumer" line than before it (takeInsHeardMore), where it matched
  the first start's line still in the shared buffer.
- An ask is read from the stream, and said taken, only once it is on the stream (askPut, waited for with waitFor): the run
  names its ask before the runner has written the ask key and put the ask, so the one read of the stream failed with
  "message not found", and an ask-taken heard before the ask key is written moves nothing (read at the silent-bound
  wait: the ask key was absent when the take was said), so the clock of the ask never began and the wait ran 60 s.
- The progress wait stops at once, naming the run, when the run has ended.

Builds: design 47 H2 H-A-637
This commit is contained in:
2026-11-24 02:17:55 +01:00
parent b810407f50
commit b71bc6fbaf
2 changed files with 63 additions and 8 deletions
@@ -510,7 +510,20 @@ func findingsStream(t *testing.T, ctx context.Context, js jetstream.JetStream, m
// publish after the bind so that each take-in is heard where the running runner hears it. // publish after the bind so that each take-in is heard where the running runner hears it.
func takeInsHeard(t *testing.T, ctx context.Context, logs *syncBuffer) { func takeInsHeard(t *testing.T, ctx context.Context, logs *syncBuffer) {
t.Helper() t.Helper()
waitFor(t, ctx, logs, func() bool { return strings.Contains(logs.String(), "take-ins: heard on the consumer") }) takeInsHeardMore(t, ctx, logs, 0)
}
// takeInsLines counts the lines in which a runner said its takeins durable is bound.
func takeInsLines(logs *syncBuffer) int {
return strings.Count(logs.String(), "take-ins: heard on the consumer")
}
// takeInsHeardMore waits until the runner started after the count before has said its takeins durable is bound: a runner
// started again in a test that keeps its journal says it once more, and the first start's line is not the new runner's
// (H-A-637).
func takeInsHeardMore(t *testing.T, ctx context.Context, logs *syncBuffer, before int) {
t.Helper()
waitFor(t, ctx, logs, func() bool { return takeInsLines(logs) > before })
} }
func waitFor(t *testing.T, ctx context.Context, logs *syncBuffer, cond func() bool) { func waitFor(t *testing.T, ctx context.Context, logs *syncBuffer, cond func() bool) {
@@ -43,7 +43,10 @@ import (
// other steps not asked (A-470g, A-470h); the process answers test-runs with its fill against the bucket's max bytes and // other steps not asked (A-470g, A-470h); the process answers test-runs with its fill against the bucket's max bytes and
// test-runs-drop deletes the key and its output object (A-470i); at nine tenths of the bucket a step's end ages the oldest // test-runs-drop deletes the key and its output object (A-470i); at nine tenths of the bucket a step's end ages the oldest
// ended runs, said in one journal line (H-A-510). // ended runs, said in one journal line (H-A-510).
// The step bound is two seconds here, as the setting test-step-bound names it, where the mesh's is 30 minutes. // The step bound is two seconds here, as the setting test-step-bound names it, where the mesh's is 30 minutes; the first
// start has a minute, longer than the restart, and the setting is rewritten to the two seconds between the stop and the
// start (H-A-637). The test waits on what it causes: it says an ask taken only once the ask is put, never a clock across
// the restart, and the restarted runner's own take-in line is waited for.
func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) { func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
url := testbus.URL(t) url := testbus.URL(t)
nc, err := nats.Connect(url) nc, err := nats.Connect(url)
@@ -206,10 +209,11 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
return out return out
} }
// The settings, as the manifest's resources write them (A-469x): a step bound of two seconds; the // The settings, as the manifest's resources write them (A-469x): a step bound of a minute, longer than the restart below,
// which the setting is rewritten from to two seconds between the stop and the start (H-A-637); the
// candidates' pipelines run side by side, so pipelines-at-once is its most, 8 (§748). // candidates' pipelines run side by side, so pipelines-at-once is its most, 8 (§748).
dir := t.TempDir() dir := t.TempDir()
files := map[string]string{envStepBound: "2s", envPipelinesAtOnce: "8"} files := map[string]string{envStepBound: "1m", envPipelinesAtOnce: "8"}
env := map[string]string{} env := map[string]string{}
for name, content := range files { for name, content := range files {
path := filepath.Join(dir, name) path := filepath.Join(dir, name)
@@ -228,8 +232,10 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
start := func() func() { start := func() func() {
runCtx, stop := context.WithCancel(ctx) runCtx, stop := context.WithCancel(ctx)
done := make(chan error, 1) done := make(chan error, 1)
// The line of the runner started now is waited for, not the first start's still in the shared buffer (H-A-637).
before := takeInsLines(logs)
go func() { done <- run(runCtx, func(k string) string { return env[k] }, logs) }() go func() { done <- run(runCtx, func(k string) string { return env[k] }, logs) }()
takeInsHeard(t, ctx, logs) takeInsHeardMore(t, ctx, logs, before)
return func() { stop(); <-done } return func() { stop(); <-done }
} }
stop := start() stop := start()
@@ -315,7 +321,29 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
} }
// A run names its ask before the runner has put it (the run, then its ask key, its bound, and last the ask on the
// stream), so an ask is read, and said taken, only once it is on the stream (H-A-637): an ask-taken heard before the
// ask key is written moves nothing, and no clock of the ask would ever begin.
askPut := func(ask string) {
waitFor(t, ctx, logs, func() bool {
info, err := askStream.Info(ctx)
if err != nil {
return false
}
for seq := info.State.FirstSeq; seq <= info.State.LastSeq; seq++ {
m, err := askStream.GetMsg(ctx, seq)
var put struct {
ID string `json:"id"`
}
if err == nil && json.Unmarshal(m.Data, &put) == nil && put.ID == ask {
return true
}
}
return false
})
}
taken := func(ask string) { taken := func(ask string) {
askPut(ask)
publish(nodebuildgo.SubjectAskTaken("n1"), nodebuildgo.AskTaken{Ask: ask, Asker: module, Node: "n1", At: time.Now()}) publish(nodebuildgo.SubjectAskTaken("n1"), nodebuildgo.AskTaken{Ask: ask, Asker: module, Node: "n1", At: time.Now()})
} }
endAsk := func(key, ask, name, outcome string, tests *nodebuildgo.TestCounts) { endAsk := func(key, ask, name, outcome string, tests *nodebuildgo.TestCounts) {
@@ -353,7 +381,10 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
passBuild(p3, "app", "c1", "src2:aa") passBuild(p3, "app", "c1", "src2:aa")
unitRun, unit := runOfStep(p3, "app:program", "unit") unitRun, unit := runOfStep(p3, "app:program", "unit")
integRun, integ := runOfStep(p3, "app:program", "integration") integRun, integ := runOfStep(p3, "app:program", "integration")
// A test ask fetches with the entry's pins, as the builder gives them the build (H-A-203). // A test ask fetches with the entry's pins, as the builder gives them the build (H-A-203); both asks are waited for
// on the stream, the runs naming them before the runner has put them (H-A-637).
askPut(unit.Ask)
askPut(integ.Ask)
last, err := askStream.GetLastMsgForSubject(ctx, "mesh.seat.node-build-go.accept.check.mesh-pipeline-runner") last, err := askStream.GetLastMsgForSubject(ctx, "mesh.seat.node-build-go.accept.check.mesh-pipeline-runner")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -395,9 +426,15 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
return err == nil && strings.Contains(string(e.Value()), `"ask":"`+unit.Ask+`"`) return err == nil && strings.Contains(string(e.Value()), `"ask":"`+unit.Ask+`"`)
}) })
stop() stop()
// The bound is two seconds from the restart on, after the minute the first runner armed the clock with: no clock ends
// the run before the restarted runner hears the first progress (H-A-637).
if err := os.WriteFile(env[envStepBound], []byte("2s"), 0o600); err != nil {
t.Fatal(err)
}
stop = start() stop = start()
// It keeps saying its progress past its bound and is not ended (§725, §720). // It keeps saying its progress past its bound and is not ended (§725, §720).
// Each progress is heard before the next is said: the run's clock is written again (its bound key's revision rises). // Each progress is heard before the next is said: the run's clock is written again (its bound key's revision rises), or
// the wait stops at once, naming the run, when it has ended.
boundRev := func() uint64 { boundRev := func() uint64 {
e, err := runsKV.Get(ctx, pipeline.BoundPrefix+unitRun) e, err := runsKV.Get(ctx, pipeline.BoundPrefix+unitRun)
if err != nil { if err != nil {
@@ -408,7 +445,12 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
for at := time.Now(); time.Since(at) < 3*time.Second; { for at := time.Now(); time.Since(at) < 3*time.Second; {
before := boundRev() before := boundRev()
publish(nodebuildgo.SubjectStepProgress("n1"), nodebuildgo.StepProgress{Ask: unit.Ask, Asker: module, Phase: "run", At: time.Now()}) publish(nodebuildgo.SubjectStepProgress("n1"), nodebuildgo.StepProgress{Ask: unit.Ask, Asker: module, Phase: "run", At: time.Now()})
waitFor(t, ctx, logs, func() bool { return boundRev() > before }) waitFor(t, ctx, logs, func() bool {
if r, _ := runOf(unitRun); r.Ended != nil {
t.Fatalf("the run %s ended while it said its progress, its clock written again no more: %+v; the runner said:\n%s", unitRun, r, logs.String())
}
return boundRev() > before
})
} }
if r, _ := runOf(unitRun); r.Ended != nil { if r, _ := runOf(unitRun); r.Ended != nil {
t.Fatalf("a run saying its progress past its bound ended: %+v", r) t.Fatalf("a run saying its progress past its bound ended: %+v", r)