builder: hold the after-the-wait superseded judgement with a withdrawn build
Review round 2: the subtest's build ended done, so the check after the wait was not held. The build in flight is now withdrawn by the newer entry (the key ends "withdrawn: … superseded by …", main.327's gate build), and the step still ends superseded; without the check it ends failed. Builds: design 47 H2 H-A-508 (and its addendum)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
@@ -592,32 +594,53 @@ func digestOf(unreadable bool) string {
|
||||
return mdigest('a')
|
||||
}
|
||||
|
||||
// H-A-508 (review round 1): a newer entry of the branch heard while the step's build runs ends the step superseded, naming the
|
||||
// newer fingerprint, whatever the build's end (done, or withdrawn as superseded), never failed nor passed.
|
||||
// H-A-508 (review rounds 1, 2): a newer entry of the branch heard while the step's build runs withdraws that build (the key
|
||||
// ends "withdrawn: … superseded by …", as main.327's mesh-delivery-gate build did); the step waiting on it ends superseded,
|
||||
// naming the newer fingerprint, judged before the build's failed end, never failed.
|
||||
func aNewerEntryWhileTheBuildRunsSupersedesTheStep(t *testing.T) {
|
||||
r := newRig(t, goBundle)
|
||||
var asked int32
|
||||
running := make(chan struct{})
|
||||
r.asks.Answer = func(a buildstep.StepAsk) buildstep.Step {
|
||||
if atomic.AddInt32(&asked, 1) == 1 { // fp1's ask runs until it is withdrawn
|
||||
defer close(running)
|
||||
return buildstep.Step{ID: a.ID, Node: "ace", State: buildstep.StepRunning, Started: time.Now()}
|
||||
}
|
||||
return r.answer(a)
|
||||
}
|
||||
r.b.Asks = buildrun.Asker{Seats: testSeats(), Publisher: r.asks, Waiter: r.asks, Bound: 2 * time.Second, Dropper: &seatDrops{}}
|
||||
r.b.StepEntry = func(context.Context, string) (meshcatalog.CatalogEntry, error) {
|
||||
return meshcatalog.CatalogEntry{Module: "m", Repository: "novox/mesh-catalog", Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20", Fp: fp1, ManifestDigest: mdigest('a'), Path: "modules/m"}, nil
|
||||
}
|
||||
r.bm.hold, r.bm.entered = make(chan struct{}), make(chan struct{}, 8)
|
||||
r.b.Module(t.Context(), "m", moduleValue(t, "modules/m")) // fp1, the newest entry heard, is built
|
||||
<-running
|
||||
ended := make(chan meshbuilds.StepEnded, 1)
|
||||
go func() {
|
||||
ended <- r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
}()
|
||||
select {
|
||||
case <-r.bm.entered: // fp1's build is under way
|
||||
case end := <-ended:
|
||||
t.Fatalf("the step ended before its build ran: %+v", end)
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the step's build never started")
|
||||
// The step waits on the end of fp1's build in flight before the newer entry is heard.
|
||||
for deadline := time.Now().Add(5 * time.Second); ; runtime.Gosched() {
|
||||
r.b.mu.Lock()
|
||||
n := len(r.b.stepWaits[r.key])
|
||||
r.b.mu.Unlock()
|
||||
if n > 0 {
|
||||
break
|
||||
}
|
||||
select {
|
||||
case end := <-ended:
|
||||
t.Fatalf("the step ended before it waited on the build in flight: %+v", end)
|
||||
default:
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("the step never waited on the build in flight")
|
||||
}
|
||||
}
|
||||
newer, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-catalog", Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20",
|
||||
Fp2: fp2, Manifest: mdigest('a'), Path: "modules/m", Toolchains: CatalogToolchains(agreedToolchains)})
|
||||
Fp: "src1:" + hex64('f'), Fp2: fp2, Manifest: mdigest('a'), Path: "modules/m", Toolchains: CatalogToolchains(agreedToolchains)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.b.Module(t.Context(), "m", newer)
|
||||
close(r.bm.hold)
|
||||
var end meshbuilds.StepEnded
|
||||
select {
|
||||
case end = <-ended:
|
||||
@@ -625,6 +648,9 @@ func aNewerEntryWhileTheBuildRunsSupersedesTheStep(t *testing.T) {
|
||||
t.Fatal("the step never ended")
|
||||
}
|
||||
r.b.Wait()
|
||||
if v := valueOf(t, r.st, r.key); v.State != builds.BuildFailed || !strings.HasPrefix(v.Error, withdrawnPrefix) || !strings.Contains(v.Error, "superseded by the fingerprint "+fp2) {
|
||||
t.Fatalf("fp1's key = %+v, want its build withdrawn, superseded by %s", v, fp2)
|
||||
}
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomeSuperseded || !strings.Contains(end.Said, "m at "+fp1+" is superseded by "+fp2) {
|
||||
t.Errorf("end = %+v, want superseded by %s", end, fp2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user