Builder: tests that fail without the round-2 changes (publish item kept with its artifacts published, asked at the build's end and at the start, unreadable plan)
Builds: design 47 G A-456b, A-457a
This commit is contained in:
@@ -257,13 +257,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
republish: republish.Republish, endedWith: reserved.unreleased,
|
||||
allDone: func(ctx context.Context) ([]versions.ReservedVersion, error) {
|
||||
all, err := reserved.r.All(ctx)
|
||||
var out []versions.ReservedVersion
|
||||
for _, v := range all {
|
||||
if !v.BuiltAt.IsZero() {
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
return out, err
|
||||
return builtOf(all), err
|
||||
}}
|
||||
reasksKV.Ready(func(jetstream.KeyValue) { items.AskAllDone(ctx) })
|
||||
wirePublishItems(reserved, items, awaitedReserved{awaitedVersions{b: actedKV, bucket: own.acted}}, releasedKept)
|
||||
|
||||
@@ -202,3 +202,15 @@ func wirePublishItems(rv *reservations, items *publishItems, releases versions.R
|
||||
rv.built, rv.released = items.Ask, items.Done
|
||||
rv.r.ReleasedKept, rv.r.Releases = kept, releases
|
||||
}
|
||||
|
||||
// builtOf are the reservations whose build is done, whatever their artifacts' state: each is asked its publish item at the start
|
||||
// (design 47 G A-456b), which goes only with its release.
|
||||
func builtOf(all []versions.ReservedVersion) []versions.ReservedVersion {
|
||||
var out []versions.ReservedVersion
|
||||
for _, v := range all {
|
||||
if !v.BuiltAt.IsZero() {
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -98,7 +98,12 @@ func TestAPublishItemIsTriedWithAGrowingPauseAndEndsLoudly(t *testing.T) {
|
||||
c <- now
|
||||
return c
|
||||
},
|
||||
reserved: func(context.Context, string, string) (versions.ReservedVersion, bool, error) { return v, reserved, nil },
|
||||
reserved: func(_ context.Context, _, ver string) (versions.ReservedVersion, bool, error) {
|
||||
if ver == "0.3.0" { // every artifact published, its release not written yet
|
||||
return versions.ReservedVersion{Module: "m", Version: ver, Artifacts: map[string]string{"m:a": "sha256:a"}, Published: map[string]bool{"m:a": true}, BuiltAt: now}, true, nil
|
||||
}
|
||||
return v, reserved, nil
|
||||
},
|
||||
republish: func(_ context.Context, m, ver string) ([]string, error) {
|
||||
queued = append(queued, m+" "+ver)
|
||||
return nil, errors.New("no holder")
|
||||
@@ -121,10 +126,21 @@ func TestAPublishItemIsTriedWithAGrowingPauseAndEndsLoudly(t *testing.T) {
|
||||
if want := []time.Duration{30 * time.Second, time.Minute, 2 * time.Minute, 2 * time.Minute}; len(waited) != len(want) || waited[0] != want[0] || waited[1] != want[1] || waited[2] != want[2] || waited[3] != want[3] {
|
||||
t.Errorf("pauses before the tries and the end = %v, want %v (doubled, capped)", waited, want)
|
||||
}
|
||||
// An item whose artifacts are all published stays until its release is written, and is tried (A-456b).
|
||||
queued = nil
|
||||
_ = p.Ask(ctx, "m", "0.3.0")
|
||||
pk := versions.PublishItemKey("m", "0.3.0")
|
||||
pe, _ := kv.Get(ctx, pk)
|
||||
p.Try(ctx, kv, pe, decodeItem(t, pe.Value()))
|
||||
if _, ok := kv.vals[pk]; !ok || len(queued) != 1 || decodeItem(t, kv.vals[pk]).Tries != 1 {
|
||||
t.Errorf("an item whose artifacts are published was deleted or not tried: %v, queued %v", kv.vals, queued)
|
||||
}
|
||||
kv.vals, kv.revs = map[string][]byte{}, map[string]uint64{}
|
||||
// At the start every reservation of a done build with no release is asked, one item each.
|
||||
kv.vals, kv.revs = map[string][]byte{}, map[string]uint64{}
|
||||
p.allDone = func(context.Context) ([]versions.ReservedVersion, error) {
|
||||
return []versions.ReservedVersion{v, {Module: "n", Version: "0.2.0"}}, nil
|
||||
published := versions.ReservedVersion{Module: "n", Version: "0.2.0", Artifacts: map[string]string{"n:a": "sha256:a"}, Published: map[string]bool{"n:a": true}, BuiltAt: now}
|
||||
return builtOf([]versions.ReservedVersion{v, published, {Module: "o", Version: "0.1.0"}}), nil // the last build has not ended
|
||||
}
|
||||
p.AskAllDone(ctx)
|
||||
if len(kv.vals) != 2 {
|
||||
@@ -207,6 +223,17 @@ func TestThePublishItemsAreWiredToTheReservationsAndTheReAskWatch(t *testing.T)
|
||||
if _, ok := kv.vals[key]; !ok {
|
||||
t.Fatalf("a done build has no publish item: %v", kv.vals)
|
||||
}
|
||||
// A build whose artifacts are all published still gets its item, until its release is written (A-456b).
|
||||
if _, _, err := rv.r.Published(ctx, versions.NameOf("m", "a"), first.Version, "sha256:a"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
items.Done(ctx, "m", first.Version)
|
||||
if err := rv.Built(ctx, "m", first.Version, map[string]string{"m:a": "sha256:a"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := kv.vals[key]; !ok {
|
||||
t.Fatalf("a build with every artifact published has no item: %v", kv.vals)
|
||||
}
|
||||
// The watch hands the item to its try, which queues the publish.
|
||||
e, _ := kv.Get(ctx, key)
|
||||
reAsked(ctx, nil, versions.Acts{}, items, kv, e, t.Logf)
|
||||
|
||||
@@ -82,14 +82,15 @@ func TestAStepAskIsWokenByItsBuildsEnd(t *testing.T) {
|
||||
// that reserves none (a manifest of before G, version "1") passes as it did.
|
||||
func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name, version string
|
||||
reserve, released bool
|
||||
want, said string
|
||||
name, version string
|
||||
reserve, released, unreadable bool
|
||||
want, said string
|
||||
}{
|
||||
{"no version reserved", "0.1", false, false, meshbuilds.StepEndedOutcomeFailed, "built at " + fp1 + ", but no version is reserved for it"},
|
||||
{"a version reserved", "0.1", true, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"a released build whose reservation is gone", "0.1", false, true, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"a series of before G", "1", false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"no version reserved", "0.1", false, false, false, meshbuilds.StepEndedOutcomeFailed, "built at " + fp1 + ", but no version is reserved for it"},
|
||||
{"a version reserved", "0.1", true, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"a released build whose reservation is gone", "0.1", false, true, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"the plan cannot be read", "0.1", false, false, true, meshbuilds.StepEndedOutcomeCouldNotRun, "plan cannot be read"},
|
||||
{"a series of before G", "1", false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
r := newRig(t, goBundle)
|
||||
@@ -103,7 +104,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
res.sources = append(res.sources, versions.Source{Fingerprint: fp1})
|
||||
}
|
||||
r.b.StepEntry = func(context.Context, string) (meshcatalog.CatalogEntry, error) {
|
||||
return meshcatalog.CatalogEntry{Module: "m", Repository: "novox/m", Commit: "c1", Fp: fp1, ManifestDigest: mdigest('a'), Path: "modules/m"}, nil
|
||||
return meshcatalog.CatalogEntry{Module: "m", Repository: "novox/m", Commit: "c1", Fp: fp1, ManifestDigest: digestOf(c.unreadable), Path: "modules/m"}, nil
|
||||
}
|
||||
end := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
if end.Outcome != c.want || !strings.Contains(end.Said, c.said) || (c.want == meshbuilds.StepEndedOutcomeFailed && !strings.Contains(end.Said, "builder_reserve_done")) {
|
||||
@@ -112,3 +113,11 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// digestOf is the manifest digest a step's entry names: the rig's manifest, or one no store holds, whose plan cannot be read.
|
||||
func digestOf(unreadable bool) string {
|
||||
if unreadable {
|
||||
return mdigest('z')
|
||||
}
|
||||
return mdigest('a')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user