Merge pull request 'Pipeline runner: the test-run test waits on what it causes, never on a clock across a restart (issue 1984)' (#363) from fix/1984-testruns-flake into main

This commit was merged in pull request #363.
This commit is contained in:
2026-11-24 01:36:59 +00:00
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.
func takeInsHeard(t *testing.T, ctx context.Context, logs *syncBuffer) {
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) {
@@ -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
// 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).
// 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) {
url := testbus.URL(t)
nc, err := nats.Connect(url)
@@ -206,10 +209,11 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
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).
dir := t.TempDir()
files := map[string]string{envStepBound: "2s", envPipelinesAtOnce: "8"}
files := map[string]string{envStepBound: "1m", envPipelinesAtOnce: "8"}
env := map[string]string{}
for name, content := range files {
path := filepath.Join(dir, name)
@@ -228,8 +232,10 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
start := func() func() {
runCtx, stop := context.WithCancel(ctx)
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) }()
takeInsHeard(t, ctx, logs)
takeInsHeardMore(t, ctx, logs, before)
return func() { stop(); <-done }
}
stop := start()
@@ -315,7 +321,29 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
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) {
askPut(ask)
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) {
@@ -353,7 +381,10 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
passBuild(p3, "app", "c1", "src2:aa")
unitRun, unit := runOfStep(p3, "app:program", "unit")
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")
if err != nil {
t.Fatal(err)
@@ -395,9 +426,15 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
return err == nil && strings.Contains(string(e.Value()), `"ask":"`+unit.Ask+`"`)
})
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()
// 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 {
e, err := runsKV.Get(ctx, pipeline.BoundPrefix+unitRun)
if err != nil {
@@ -408,7 +445,12 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
for at := time.Now(); time.Since(at) < 3*time.Second; {
before := boundRev()
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 {
t.Fatalf("a run saying its progress past its bound ended: %+v", r)