Merge pull request 'The runner and the builder write a journal line per step end, ask placed and ask answered (H-A-320, H-A-333)' (#320) from fix/47-H2-journal-lines into main
This commit was merged in pull request #320.
This commit is contained in:
@@ -24,9 +24,24 @@ func (b *Builder) BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbui
|
||||
b.init()
|
||||
started := b.now()
|
||||
end := meshbuilds.StepEnded{V: 1, Pipeline: run.Pipeline, Step: meshbuilds.StepEndedStepBuild, Rerun: run.Rerun, By: run.By, Entries: run.Entries, Node: b.Node, Started: &started}
|
||||
// finish is the one place the ask is answered: its line names the pipeline, the movers, the step and the outcome, with
|
||||
// the words of an end that did not pass (H-A-320 (1), H-A-333).
|
||||
finish := func(outcome, said string) meshbuilds.StepEnded {
|
||||
at := b.now()
|
||||
end.Ended, end.Outcome, end.Said = &at, outcome, said
|
||||
movers := make([]string, 0, len(run.Entries))
|
||||
for _, e := range run.Entries {
|
||||
movers = append(movers, e.Module)
|
||||
}
|
||||
mv := strings.Join(movers, ",")
|
||||
if mv == "" {
|
||||
mv = "-"
|
||||
}
|
||||
if said != "" {
|
||||
b.logf("%s %s %s step answered %s: %s", run.Pipeline, mv, end.Step, outcome, said)
|
||||
} else {
|
||||
b.logf("%s %s %s step answered %s", run.Pipeline, mv, end.Step, outcome)
|
||||
}
|
||||
return end
|
||||
}
|
||||
if len(run.Entries) == 0 {
|
||||
@@ -43,7 +58,7 @@ func (b *Builder) BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbui
|
||||
var failed []string
|
||||
for _, e := range run.Entries {
|
||||
var pins map[string]string
|
||||
outcome, said := b.buildEntry(ctx, e, &pins)
|
||||
outcome, said := b.buildEntry(ctx, run.Pipeline, e, &pins)
|
||||
// The end reports the pins each entry was built with, so the runner asks its held test steps with them (H-A-207).
|
||||
for path, version := range pins {
|
||||
if version == "" {
|
||||
@@ -88,9 +103,10 @@ func (b *Builder) askedRevision(run meshbuilds.StepRun) {
|
||||
}
|
||||
}
|
||||
|
||||
// buildEntry builds one entry at its fingerprint and waits for its end; pins is set, when it is done, to the pins its
|
||||
// done key keeps it was built with, the registry's included (H-A-207).
|
||||
func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry, pins *map[string]string) (outcome, said string) {
|
||||
// buildEntry builds one entry at its fingerprint for pipeline and waits for its end; pins is set, when it is done, to the pins
|
||||
// its done key keeps it was built with, the registry's included (H-A-207). The answer from a build is one journal line,
|
||||
// naming the entry, its outcome, the pipeline and whether the build existed or was built now (H-A-320 (1)).
|
||||
func (b *Builder) buildEntry(ctx context.Context, pipeline string, e meshbuilds.BuildEntry, pins *map[string]string) (outcome, said string) {
|
||||
entry, err := b.StepEntry(ctx, e.Fingerprint)
|
||||
if err != nil {
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("the entry %s at %s cannot be read: %v", e.Module, e.Fingerprint, err)
|
||||
@@ -110,13 +126,18 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry, pins
|
||||
}
|
||||
ended := b.awaitEnd(key)
|
||||
defer b.dropEnd(key, ended)
|
||||
answered := func(outcome, said, how string) (string, string) {
|
||||
b.logf("%s@%s build step answered %s for %s (%s)", entry.Module, entry.Fp, outcome, pipeline, how)
|
||||
return outcome, said
|
||||
}
|
||||
if done, failedWords, found := b.keyEnd(ctx, key); found {
|
||||
if done {
|
||||
// A key done before reports the pins it was built with, kept with it, never the ones a publish gives now.
|
||||
*pins = b.keptPins(ctx, key)
|
||||
return b.passedWithItsVersion(ctx, entry)
|
||||
outcome, said := b.passedWithItsVersion(ctx, entry)
|
||||
return answered(outcome, said, "existing build")
|
||||
}
|
||||
return meshbuilds.StepEndedOutcomeFailed, failedWords
|
||||
return answered(meshbuilds.StepEndedOutcomeFailed, failedWords, "existing build")
|
||||
}
|
||||
m := meshcatalog.ModulesByModuleValue{Repository: entry.Repository, Commit: entry.Commit, Fp2: entry.Fp, Manifest: meshcatalogclient.BareManifestDigest(entry.ManifestDigest), Path: entry.Path,
|
||||
Toolchains: CatalogToolchains(b.agreedFor(ctx, meshcatalogclient.BareManifestDigest(entry.ManifestDigest))), Packages: entry.Packages}
|
||||
@@ -125,9 +146,10 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry, pins
|
||||
case log := <-ended:
|
||||
if log.Outcome == builds.BuildDone {
|
||||
*pins = b.keptPins(ctx, key)
|
||||
return b.passedWithItsVersion(ctx, entry)
|
||||
outcome, said := b.passedWithItsVersion(ctx, entry)
|
||||
return answered(outcome, said, "built now")
|
||||
}
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s at %s: %s %s", log.Module, log.FP, log.Outcome, log.Error)
|
||||
return answered(meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s at %s: %s %s", log.Module, log.FP, log.Outcome, log.Error), "built now")
|
||||
case <-ctx.Done():
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("%s at %s: the builder stopped before its build ended", entry.Module, entry.Fp)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -36,12 +37,23 @@ func TestABuildStepAnswersItsEnd(t *testing.T) {
|
||||
ask := func(entries ...meshbuilds.BuildEntry) meshbuilds.StepEnded {
|
||||
return r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: entries})
|
||||
}
|
||||
// Every answer is one journal line naming the pipeline, the movers, the step and the outcome (H-A-320 (1), H-A-333).
|
||||
var answers []string
|
||||
r.b.Logf = func(f string, a ...any) {
|
||||
if l := fmt.Sprintf(f, a...); strings.Contains(l, " step answered ") {
|
||||
answers = append(answers, l)
|
||||
}
|
||||
}
|
||||
if end := ask(); end.Outcome != meshbuilds.StepEndedOutcomeNothingToRun {
|
||||
t.Errorf("an ask naming no entry: %+v", end)
|
||||
}
|
||||
if end := ask(meshbuilds.BuildEntry{Module: "m", Fingerprint: "src2:" + strings.Repeat("2", 64)}); end.Outcome != meshbuilds.StepEndedOutcomeCouldNotRun || !strings.Contains(end.Said, "cannot be read") {
|
||||
t.Errorf("an entry the seat does not hold: %+v", end)
|
||||
}
|
||||
if len(answers) != 2 || answers[0] != "main.1.m - build step answered nothing to run: the ask names no entry" ||
|
||||
!strings.HasPrefix(answers[1], "main.1.m m build step answered could not run: the entry m at ") {
|
||||
t.Errorf("the answers journaled %q, want one line per answer", answers)
|
||||
}
|
||||
if end := ask(meshbuilds.BuildEntry{Module: "m", Fingerprint: fp1, Commit: "other"}); end.Outcome != meshbuilds.StepEndedOutcomeCouldNotRun {
|
||||
t.Errorf("an entry at another commit: %+v", end)
|
||||
}
|
||||
@@ -171,6 +183,18 @@ func awaitWaiting[T any](t *testing.T, waiting <-chan struct{}, ended <-chan T)
|
||||
// another series and the module's release number pin nothing.
|
||||
func aPackageWithNoPinWaitsForItsRelease(t *testing.T) {
|
||||
r, _, waiting := unpinnedRig(t)
|
||||
// Each entry's answer from a build is one journal line, built now or existing, beside the ask's answer (H-A-320 (1), H-A-333).
|
||||
var mu sync.Mutex
|
||||
var answers []string
|
||||
logf := r.b.Logf
|
||||
r.b.Logf = func(format string, args ...any) {
|
||||
logf(format, args...)
|
||||
if l := fmt.Sprintf(format, args...); strings.HasPrefix(l, "m@") && strings.Contains(l, "build step answered") {
|
||||
mu.Lock()
|
||||
answers = append(answers, l)
|
||||
mu.Unlock()
|
||||
}
|
||||
}
|
||||
r.b.PackagePublished(unpinnedX, "v0.2.9") // another series than the 0.1 the module accepts: no pin
|
||||
r.b.PackagePublished(unpinnedX, "0.1.4-feat-x.2") // a group's tagged version: no pin
|
||||
ended := make(chan meshbuilds.StepEnded, 1)
|
||||
@@ -206,6 +230,12 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) {
|
||||
if again.Outcome != meshbuilds.StepEndedOutcomePassed || again.Packages[unpinnedX] != "v0.1.3" {
|
||||
t.Errorf("the done key's end = %+v; want passed reporting x at v0.1.3, as built", again)
|
||||
}
|
||||
mu.Lock()
|
||||
want := []string{"m@" + fp1 + " build step answered passed for main.9.m (built now)", "m@" + fp1 + " build step answered passed for main.9.m (existing build)"}
|
||||
if !reflect.DeepEqual(answers, want) {
|
||||
t.Errorf("the answers journaled %q, want %q", answers, want)
|
||||
}
|
||||
mu.Unlock()
|
||||
// A done key that keeps no pins reports none, so the runner ends the waiting steps loud.
|
||||
v, err := builds.DecodeBuilderBuild(r.st.vals[r.key])
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user