Merge pull request 'Design 47 H1: a done build whose series moved says stale, not 'no version is reserved' (H-A-244)' (#307) from fix/47-H1-builder-stale-and-tag into main
This commit was merged in pull request #307.
This commit is contained in:
@@ -117,6 +117,11 @@ func (rv *reservations) ReservedFor(ctx context.Context, module, fingerprint str
|
|||||||
return versions.ReservedVersion{}, false, nil
|
return versions.ReservedVersion{}, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TakenOver is the reservation that took module's series over from the build of fingerprint (H-A-244).
|
||||||
|
func (rv *reservations) TakenOver(ctx context.Context, module, fingerprint string) (versions.ReservedVersion, bool, error) {
|
||||||
|
return rv.r.TakenOver(ctx, module, fingerprint)
|
||||||
|
}
|
||||||
|
|
||||||
func (rv *reservations) Filled() bool { return rv.filled.Load() }
|
func (rv *reservations) Filled() bool { return rv.filled.Load() }
|
||||||
|
|
||||||
func (rv *reservations) Reserve(ctx context.Context, module, series string, artifacts []string, src versions.Source) (versions.ReservedVersion, error) {
|
func (rv *reservations) Reserve(ctx context.Context, module, series string, artifacts []string, src versions.Source) (versions.ReservedVersion, error) {
|
||||||
|
|||||||
@@ -149,6 +149,9 @@ type Reservations interface {
|
|||||||
ReservedFor(ctx context.Context, module, fingerprint string) (versions.ReservedVersion, bool, error)
|
ReservedFor(ctx context.Context, module, fingerprint string) (versions.ReservedVersion, bool, error)
|
||||||
// ReleasedFor says whether a version was released for the build of fingerprint, read from the builder's own record (A-456a).
|
// ReleasedFor says whether a version was released for the build of fingerprint, read from the builder's own record (A-456a).
|
||||||
ReleasedFor(ctx context.Context, module, fingerprint string) (bool, error)
|
ReleasedFor(ctx context.Context, module, fingerprint string) (bool, error)
|
||||||
|
// TakenOver is the reservation of module's series that took the series over from the build of fingerprint, whose number
|
||||||
|
// it keeps withdrawn (design 47 H H-A-226), and whether one does (H-A-244).
|
||||||
|
TakenOver(ctx context.Context, module, fingerprint string) (versions.ReservedVersion, bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// reserves says whether a look at a trunk build is one that reserves: the build has a series of the form MAJOR.MINOR
|
// reserves says whether a look at a trunk build is one that reserves: the build has a series of the form MAJOR.MINOR
|
||||||
|
|||||||
@@ -29,8 +29,14 @@ type fakeReservations struct {
|
|||||||
built map[string]string
|
built map[string]string
|
||||||
sources []versions.Source
|
sources []versions.Source
|
||||||
deps map[string][]meshbuilds.Dependency
|
deps map[string][]meshbuilds.Dependency
|
||||||
next string // the version Reserve answers when set, else the series' .5
|
next string // the version Reserve answers when set, else the series' .5
|
||||||
fail error // the reservation cannot be made (the catalog's versions cannot be read)
|
fail error // the reservation cannot be made (the catalog's versions cannot be read)
|
||||||
|
tookBy map[string]versions.ReservedVersion // by fingerprint, the reservation that took its series over (H-A-244)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *fakeReservations) TakenOver(_ context.Context, _, fp string) (versions.ReservedVersion, bool, error) {
|
||||||
|
v, ok := f.tookBy[fp]
|
||||||
|
return v, ok, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fakeReservations) ReleasedFor(_ context.Context, _, fp string) (bool, error) {
|
func (f *fakeReservations) ReleasedFor(_ context.Context, _, fp string) (bool, error) {
|
||||||
|
|||||||
@@ -136,7 +136,8 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry, pins
|
|||||||
// passedWithItsVersion is the verdict of a build that ended done (design 47 G A-456): a build that reserves a version (a build
|
// passedWithItsVersion is the verdict of a build that ended done (design 47 G A-456): a build that reserves a version (a build
|
||||||
// of the first watched branch's trunk, with a MAJOR.MINOR series and artifacts) passes only when a version is reserved for its
|
// of the first watched branch's trunk, with a MAJOR.MINOR series and artifacts) passes only when a version is reserved for its
|
||||||
// fingerprint; one that ended done with none fails loudly, naming builder_reserve_done, so no pipeline says passed for a build
|
// fingerprint; one that ended done with none fails loudly, naming builder_reserve_done, so no pipeline says passed for a build
|
||||||
// that can never be released. A build that reserves none (a candidate's, a series of before G) passes as it did.
|
// that can never be released, and one whose series another fingerprint took over fails saying it is stale, naming that
|
||||||
|
// fingerprint and its version (design 47 H H-A-244). A build that reserves none (a candidate's, a series of before G) passes as it did.
|
||||||
func (b *Builder) passedWithItsVersion(ctx context.Context, entry meshcatalog.CatalogEntry) (outcome, said string) {
|
func (b *Builder) passedWithItsVersion(ctx context.Context, entry meshcatalog.CatalogEntry) (outcome, said string) {
|
||||||
if b.Reserved == nil {
|
if b.Reserved == nil {
|
||||||
return meshbuilds.StepEndedOutcomePassed, ""
|
return meshbuilds.StepEndedOutcomePassed, ""
|
||||||
@@ -168,6 +169,12 @@ func (b *Builder) passedWithItsVersion(ctx context.Context, entry meshcatalog.Ca
|
|||||||
} else if released {
|
} else if released {
|
||||||
return meshbuilds.StepEndedOutcomePassed, "" // a released build counts as reserved (A-456a)
|
return meshbuilds.StepEndedOutcomePassed, "" // a released build counts as reserved (A-456a)
|
||||||
}
|
}
|
||||||
|
if by, took, err := b.Reserved.TakenOver(ctx, entry.Module, entry.Fp); err != nil {
|
||||||
|
return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("%s at %s: the reservations cannot be read: %v", entry.Module, entry.Fp, err)
|
||||||
|
} else if took {
|
||||||
|
// H-A-244 (2): the series was taken over by a newer fingerprint, whose number it carries now: the build is stale.
|
||||||
|
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s: built at %s but its series moved to %s %s: stale", entry.Module, entry.Fp, by.Fingerprint, by.Version)
|
||||||
|
}
|
||||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s: built at %s, but no version is reserved for it; builder_reserve_done reserves one for the done build", entry.Module, entry.Fp)
|
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s: built at %s, but no version is reserved for it; builder_reserve_done reserves one for the done build", entry.Module, entry.Fp)
|
||||||
}
|
}
|
||||||
return meshbuilds.StepEndedOutcomePassed, ""
|
return meshbuilds.StepEndedOutcomePassed, ""
|
||||||
|
|||||||
@@ -89,18 +89,23 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
|||||||
for _, c := range []struct {
|
for _, c := range []struct {
|
||||||
name, version string
|
name, version string
|
||||||
reserve, released, unreadable bool
|
reserve, released, unreadable bool
|
||||||
|
takenOver bool
|
||||||
want, said string
|
want, said string
|
||||||
}{
|
}{
|
||||||
{"no version reserved", "0.1", false, false, false, meshbuilds.StepEndedOutcomeFailed, "built at " + fp1 + ", but no version is reserved for it"},
|
{"no version reserved", "0.1", false, 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, ""},
|
{"H-A-244: its series was taken over by a newer fingerprint", "0.1", false, false, false, true, meshbuilds.StepEndedOutcomeFailed, "m: built at " + fp1 + " but its series moved to " + fp2 + " 0.1.7: stale"},
|
||||||
{"a released build whose reservation is gone", "0.1", false, true, false, meshbuilds.StepEndedOutcomePassed, ""},
|
{"a version reserved", "0.1", true, false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||||
{"the plan cannot be read", "0.1", false, false, true, meshbuilds.StepEndedOutcomeCouldNotRun, "plan cannot be read"},
|
{"a released build whose reservation is gone", "0.1", false, true, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||||
{"a series of before G", "1", false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
{"the plan cannot be read", "0.1", false, false, true, false, meshbuilds.StepEndedOutcomeCouldNotRun, "plan cannot be read"},
|
||||||
|
{"a series of before G", "1", false, false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||||
} {
|
} {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
r := newRig(t, goBundle)
|
r := newRig(t, goBundle)
|
||||||
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: c.version, Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
|
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: c.version, Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
|
||||||
res := &fakeReservations{filled: true, released: map[string]bool{fp1: c.released}}
|
res := &fakeReservations{filled: true, released: map[string]bool{fp1: c.released}}
|
||||||
|
if c.takenOver {
|
||||||
|
res.tookBy = map[string]versions.ReservedVersion{fp1: {Module: "m", Series: "0.1", Version: "0.1.7", Fingerprint: fp2}}
|
||||||
|
}
|
||||||
if v := r.consider(t, "modules/m"); v.State != builds.BuildDone { // built while the builder reserved nothing, as the live key was
|
if v := r.consider(t, "modules/m"); v.State != builds.BuildDone { // built while the builder reserved nothing, as the live key was
|
||||||
t.Fatalf("build = %+v, want done", v)
|
t.Fatalf("build = %+v, want done", v)
|
||||||
}
|
}
|
||||||
@@ -112,7 +117,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
|||||||
return meshcatalog.CatalogEntry{Module: "m", Repository: "novox/m", Commit: "c1", Fp: fp1, ManifestDigest: digestOf(c.unreadable), 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}}})
|
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")) {
|
if end.Outcome != c.want || !strings.Contains(end.Said, c.said) || (c.want == meshbuilds.StepEndedOutcomeFailed && strings.Contains(end.Said, "builder_reserve_done") == c.takenOver) {
|
||||||
t.Errorf("end = %+v, want %s saying %q", end, c.want, c.said)
|
t.Errorf("end = %+v, want %s saying %q", end, c.want, c.said)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -460,6 +460,26 @@ func (r *Reserver) All(ctx context.Context) ([]ReservedVersion, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TakenOver is the reservation of module's series whose withdrawn numbers hold one of the build of fingerprint (design 47 H
|
||||||
|
// H-A-226), and whether there is one: the series moved to that reservation's fingerprint and version (H-A-244).
|
||||||
|
func (r *Reserver) TakenOver(ctx context.Context, module, fingerprint string) (ReservedVersion, bool, error) {
|
||||||
|
all, err := r.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return ReservedVersion{}, false, err
|
||||||
|
}
|
||||||
|
for _, v := range all {
|
||||||
|
if v.Module != module || v.Fingerprint == fingerprint {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, fp := range v.Withdrawn {
|
||||||
|
if fp == fingerprint {
|
||||||
|
return v, true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ReservedVersion{}, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Drop deletes module's reservation of series on a person's word (builder_reserved_drop); the caller writes the hand-act
|
// Drop deletes module's reservation of series on a person's word (builder_reserved_drop); the caller writes the hand-act
|
||||||
// log. It answers whether there was one.
|
// log. It answers whether there was one.
|
||||||
func (r *Reserver) Drop(ctx context.Context, module, series string) (bool, error) {
|
func (r *Reserver) Drop(ctx context.Context, module, series string) (bool, error) {
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ func TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestTheWithdrawnVersionsAreDroppedOnceReleasedPast: design 47 H H-A-225, H-A-226 — a dropped number stays a gap, kept in
|
// TestTheWithdrawnVersionsAreDroppedOnceReleasedPast: design 47 H H-A-225, H-A-226, H-A-244 — a dropped number stays a gap, kept in
|
||||||
// the series key's Withdrawn while it is above the catalog's highest released; at each write those at or below it go, so the
|
// the series key's Withdrawn while it is above the catalog's highest released; at each write those at or below it go, so the
|
||||||
// map never grows without end.
|
// map never grows without end.
|
||||||
func TestTheWithdrawnVersionsAreDroppedOnceReleasedPast(t *testing.T) {
|
func TestTheWithdrawnVersionsAreDroppedOnceReleasedPast(t *testing.T) {
|
||||||
@@ -239,6 +239,13 @@ func TestTheWithdrawnVersionsAreDroppedOnceReleasedPast(t *testing.T) {
|
|||||||
if cur.Version != "0.1.6" || len(cur.Withdrawn) != 2 || cur.Withdrawn["0.1.4"] != "src2:a" || cur.Withdrawn["0.1.5"] != "src2:b" {
|
if cur.Version != "0.1.6" || len(cur.Withdrawn) != 2 || cur.Withdrawn["0.1.4"] != "src2:a" || cur.Withdrawn["0.1.5"] != "src2:b" {
|
||||||
t.Fatalf("reservation %+v; want 0.1.6 with 0.1.4 and 0.1.5 withdrawn", cur)
|
t.Fatalf("reservation %+v; want 0.1.6 with 0.1.4 and 0.1.5 withdrawn", cur)
|
||||||
}
|
}
|
||||||
|
// H-A-244: the build whose number was withdrawn finds the reservation its series moved to; the one standing finds none.
|
||||||
|
if by, took, err := r.TakenOver(ctx, "m", "src2:a"); err != nil || !took || by.Fingerprint != "src2:c" || by.Version != "0.1.6" {
|
||||||
|
t.Errorf("taken over from src2:a by %+v (%v, %v); want src2:c 0.1.6", by, took, err)
|
||||||
|
}
|
||||||
|
if _, took, err := r.TakenOver(ctx, "m", "src2:c"); err != nil || took {
|
||||||
|
t.Errorf("the standing build src2:c is said taken over (%v, %v)", took, err)
|
||||||
|
}
|
||||||
highest = "0.1.5" // the catalog released past both withdrawn numbers but the newest
|
highest = "0.1.5" // the catalog released past both withdrawn numbers but the newest
|
||||||
got, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: "src2:d"})
|
got, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: "src2:d"})
|
||||||
if err != nil || got.Version != "0.1.7" || len(got.Withdrawn) != 1 || got.Withdrawn["0.1.6"] != "src2:c" {
|
if err != nil || got.Version != "0.1.7" || len(got.Withdrawn) != 1 || got.Withdrawn["0.1.6"] != "src2:c" {
|
||||||
|
|||||||
Reference in New Issue
Block a user