Builder: the revision wait reads the picture and its setting revision-wait-minutes (H-A-155, H-A-156)
The process gives the builder its picture of each watched branch (the source revision the branch's view holds) and the bound of a step ask's wait for its revision, read from the setting revision-wait-minutes (default 2) carried as a file under the state dir like toolchain-wait-minutes. Builds: design 47 H H-A-155, H-A-156, H-A-141
This commit is contained in:
@@ -132,6 +132,20 @@ func (c *catalogHalf) Changed(ctx context.Context) func(branch, module string, e
|
||||
}
|
||||
}
|
||||
|
||||
// picture is build.Builder.Picture: the source revision the view of branch holds (design 47 H H-A-155), false while the branch
|
||||
// is not followed or its view holds none.
|
||||
func (c *catalogHalf) picture(branch string) (int64, bool) {
|
||||
cat, ok := c.branches.Catalog(branch)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
half, ok := cat.View()
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
return half.Revision.Source, true
|
||||
}
|
||||
|
||||
// namesOf are the package names an entry's artifacts carry, in one line.
|
||||
func namesOf(e meshcatalog.CatalogEntry) string {
|
||||
var names []string
|
||||
|
||||
+7
-2
@@ -33,8 +33,13 @@ type catalogHolder struct {
|
||||
mu sync.Mutex
|
||||
entries map[string]meshcatalog.CatalogEntry
|
||||
revision int64
|
||||
// source is the source revision each trunk revision is taken in from; 0 is 1.
|
||||
source int64
|
||||
}
|
||||
|
||||
// sourceLocked is the source revision of the revisions put now. The caller holds mu.
|
||||
func (h *catalogHolder) sourceLocked() int64 { return max(h.source, 1) }
|
||||
|
||||
func newCatalogHolder(t *testing.T, ctx context.Context, js jetstream.JetStream, nc *nats.Conn) *catalogHolder {
|
||||
t.Helper()
|
||||
h := &catalogHolder{ctx: ctx, js: js, entries: map[string]meshcatalog.CatalogEntry{}}
|
||||
@@ -84,7 +89,7 @@ func (h *catalogHolder) whole() meshcatalog.RevisionAnswer {
|
||||
all = append(all, e)
|
||||
}
|
||||
at := time.Now()
|
||||
return meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Revision: h.revision, Kind: "trunk", Branch: "main", Entries: refs, Source: 1, At: &at}, Entries: all}
|
||||
return meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Revision: h.revision, Kind: "trunk", Branch: "main", Entries: refs, Source: h.sourceLocked(), At: &at}, Entries: all}
|
||||
}
|
||||
|
||||
// put sets one module's entry in a new trunk revision of main and says catalog-revision.
|
||||
@@ -100,7 +105,7 @@ func (h *catalogHolder) putAll(t *testing.T, es ...meshcatalog.CatalogEntry) {
|
||||
h.entries[e.Module] = e
|
||||
changed = append(changed, e.Module)
|
||||
}
|
||||
ev, _ := json.Marshal(meshcatalog.CatalogRevisionEvent{Branch: "main", Kind: "trunk", Revision: h.revision, Source: 1, Entries: int64(len(h.entries)), Changed: changed, V: 1})
|
||||
ev, _ := json.Marshal(meshcatalog.CatalogRevisionEvent{Branch: "main", Kind: "trunk", Revision: h.revision, Source: h.sourceLocked(), Entries: int64(len(h.entries)), Changed: changed, V: 1})
|
||||
h.mu.Unlock()
|
||||
if _, err := h.js.Publish(h.ctx, meshcatalog.SubjectCatalogRevision("main"), ev); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -212,6 +212,13 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// A build step ask waits for the builder's picture of its branch to hold its source revision (design 47 H H-A-155); its
|
||||
// bound is its setting revision-wait-minutes (H-A-156).
|
||||
revisionWait, err := numberFile(getenv("MESH_BUILDER_REVISION_WAIT_FILE"), int(build.DefaultRevisionWait/time.Minute))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.RevisionWait = time.Duration(revisionWait) * time.Minute
|
||||
waitsBucket := process.AwaitBucket(ctx, js, conn, builds.StateBucket(cred.Module, build.WaitsState), "the toolchain waits are kept in memory only, and builder_waits shows none", logger.Printf)
|
||||
b.Waits = newWaitsKept(waitsBucket, func(ctx context.Context, event, id string, body any) error {
|
||||
return emitEvent(context.WithoutCancel(ctx), js, cred, event, id, body)
|
||||
@@ -450,6 +457,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// fingerprint no branch carries is closed (issue 1660) once the first view of every followed branch is in (never at the start:
|
||||
// a holder of the seat that is down holds no other part of it).
|
||||
half.b = b
|
||||
b.Picture = half.picture
|
||||
half.ready = func() {
|
||||
if err := b.Sweep(ctx, half.pictured()...); err != nil {
|
||||
errs <- err
|
||||
|
||||
@@ -4,6 +4,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -49,4 +50,29 @@ func TestTheRunnersBuildStepAskIsAnsweredAsStepEnded(t *testing.T) {
|
||||
case <-time.After(20 * time.Second):
|
||||
t.Fatal("no step-ended within 20 s")
|
||||
}
|
||||
// H-A-155: an ask naming a source revision the builder's picture of main does not hold yet waits for it, said in the
|
||||
// journal, and is answered once a revision taken in from it arrives.
|
||||
run.Pipeline, run.Revision, run.Source = "main.2.netcheck", 2, 2
|
||||
data, _ = json.Marshal(run)
|
||||
msg = nats.NewMsg(meshbuilds.AcceptSubjectStep)
|
||||
msg.Data = data
|
||||
msg.Header.Set("x-event-id", "ask-2")
|
||||
if err := sub.PublishMsg(msg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.awaitSaid(t, "main.2.netcheck: revision 2 of main not in the builder's picture yet")
|
||||
b.catalog.mu.Lock()
|
||||
b.catalog.source = 2
|
||||
b.catalog.mu.Unlock()
|
||||
// Revision 2, taken in from source 2, moves another module: netcheck's entry is the one the picture holds already.
|
||||
b.moduleFP(t, "ca-trust", "catalogue-a67f0196-ca-trust.module.json", "modules/ca-trust", nil, commit, "src2:"+strings.Repeat("4", 64), 0)
|
||||
select {
|
||||
case m := <-ended:
|
||||
var end meshbuilds.StepEnded
|
||||
if err := json.Unmarshal(m.Data, &end); err != nil || end.ID != "ask-2" || end.Outcome != meshbuilds.StepEndedOutcomePassed {
|
||||
t.Fatalf("step-ended = %+v, %v; want the ask ask-2 passed once the picture held source revision 2", end, err)
|
||||
}
|
||||
case <-time.After(20 * time.Second):
|
||||
t.Fatal("no step-ended for ask-2 within 20 s")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,9 +186,9 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
m.Streams[2].Name != "mesh-delivery-builder-findings" || !reflect.DeepEqual(m.Streams[2].Events, []string{"finding-written.*", "finding-cleared.*", "findings-stated.*"}) {
|
||||
t.Errorf("streams = %+v, want waits with wait-held.** and wait-ended.**, 7 days, 16 MiB, the builds' stream (build.ended.**, 7 days, kept last per subject: design 47 G A-181) and the findings' stream", m.Streams)
|
||||
}
|
||||
if c, ok := m.Config["toolchain-wait-minutes"]; !ok || c.Default != float64(60) || len(m.Config) != 5 ||
|
||||
if c, ok := m.Config["toolchain-wait-minutes"]; !ok || c.Default != float64(60) || len(m.Config) != 6 || m.Config["revision-wait-minutes"].Default != float64(2) ||
|
||||
m.Config["publish-pause"].Default != float64(30) || m.Config["publish-pause-max"].Default != float64(30) || m.Config["publish-tries"].Default != float64(8) {
|
||||
t.Errorf("config = %+v, want toolchain-wait-minutes of 60, the publish settings 30 s, 30 min and 8 tries (design 47 G §588, §633, A-457a)", m.Config)
|
||||
t.Errorf("config = %+v, want toolchain-wait-minutes of 60, revision-wait-minutes of 2 (H-A-156), the publish settings 30 s, 30 min and 8 tries (design 47 G §588, §633, A-457a)", m.Config)
|
||||
}
|
||||
// Design 47 G §349: version.numbered is no longer said; old-form-closed on the family version, apart from the builds' ends.
|
||||
if want := []string{"build.asked-again", "version.old-form-closed"}; !reflect.DeepEqual(m.Emits, want) {
|
||||
@@ -241,7 +241,7 @@ func TestManifestProcess(t *testing.T) { // 1607/AC1
|
||||
t.Errorf("process = %v", p)
|
||||
}
|
||||
env, _ := p["env"].(map[string]any)
|
||||
if len(env) != 6 || env["MESH_BUILDER_PUBLISH_TRIES_FILE"] != "${dir:state}/publish-tries" || env["MESH_BROKER_FILE"] != "${dir:state}/broker" || env["MESH_BUILDER_TOOLCHAIN_WAIT_FILE"] != "${dir:state}/toolchain-wait-minutes" {
|
||||
if len(env) != 7 || env["MESH_BUILDER_REVISION_WAIT_FILE"] != "${dir:state}/revision-wait-minutes" || env["MESH_BUILDER_PUBLISH_TRIES_FILE"] != "${dir:state}/publish-tries" || env["MESH_BROKER_FILE"] != "${dir:state}/broker" || env["MESH_BUILDER_TOOLCHAIN_WAIT_FILE"] != "${dir:state}/toolchain-wait-minutes" {
|
||||
t.Errorf("env = %v, want the broker file and the path of the toolchain wait's file, never the setting itself (design 47 G §672, A-71)", p["env"])
|
||||
}
|
||||
for k, v := range env {
|
||||
|
||||
@@ -147,6 +147,14 @@
|
||||
"trusted": false,
|
||||
"default": 60
|
||||
},
|
||||
"revision-wait-minutes": {
|
||||
"type": "number",
|
||||
"description": "minutes a build step ask waits for the builder's picture of its branch to hold its source revision before it fails, building nothing (design 47 H H-A-155, H-A-156).",
|
||||
"minimum": 1,
|
||||
"maximum": 60,
|
||||
"trusted": false,
|
||||
"default": 2
|
||||
},
|
||||
"publish-pause": {
|
||||
"type": "number",
|
||||
"description": "seconds before a version's second publish try, doubled per try up to publish-pause-max (design 47 G A-457a).",
|
||||
@@ -223,6 +231,14 @@
|
||||
"mode": "0600",
|
||||
"content": "${config:toolchain-wait-minutes}"
|
||||
},
|
||||
{
|
||||
"id": "revision-wait",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/revision-wait-minutes",
|
||||
"owner": "mesh-delivery-builder",
|
||||
"mode": "0600",
|
||||
"content": "${config:revision-wait-minutes}"
|
||||
},
|
||||
{
|
||||
"id": "publish-pause",
|
||||
"type": "file",
|
||||
@@ -269,6 +285,7 @@
|
||||
"env": {
|
||||
"MESH_BROKER_FILE": "${dir:state}/broker",
|
||||
"MESH_BUILDER_TOOLCHAIN_WAIT_FILE": "${dir:state}/toolchain-wait-minutes",
|
||||
"MESH_BUILDER_REVISION_WAIT_FILE": "${dir:state}/revision-wait-minutes",
|
||||
"MESH_BUILDER_PUBLISH_PAUSE_FILE": "${dir:state}/publish-pause",
|
||||
"MESH_BUILDER_PUBLISH_PAUSE_MAX_FILE": "${dir:state}/publish-pause-max",
|
||||
"MESH_BUILDER_PUBLISH_TRIES_FILE": "${dir:state}/publish-tries",
|
||||
|
||||
Reference in New Issue
Block a user