selfcompose: the one place says its source at every caller, reads the have's build, answers HoldsData; the tool composition reads it outside the agent's lock (A-484, A-482)
Builds: design 47 G A-484, A-484a, A-482
This commit is contained in:
@@ -449,6 +449,115 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A-484, A-484a, A-482: the manifest of the build a module runs here is answered in one place, from the entry of the running build,
|
||||
// else the manifest its running statement names, else the module's trunk manifest; the composition says whether it keeps data. It
|
||||
// says its source once per module and source, whoever asks, and where none answers its words name the three.
|
||||
{
|
||||
running := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
|
||||
other := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64)
|
||||
body := `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}`
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
entry string // the entry held, by fingerprint ("running", "other") or none
|
||||
composition string // the composition this node runs: its build ("running", "other") or none
|
||||
data bool
|
||||
trunk bool
|
||||
statement bool // the running event names a manifest this node holds (A-484a)
|
||||
haveOnly bool // heard no running event: only its have names the build it runs (A-482)
|
||||
wantSource string
|
||||
wantKnown bool
|
||||
}{
|
||||
{"its entry answers first", "running", "running", false, true, false, false, SourceEntry, true},
|
||||
{"the entry of the composition's build is the running build's", "other", "other", true, true, false, false, SourceEntry, true},
|
||||
{"a composition with no manifest keeps the trunk's manifest and its data", "", "running", true, true, false, false, SourceTrunk, true},
|
||||
{"a composition and no trunk answer: its build and its data alone", "", "running", true, false, false, false, SourceComposition, false},
|
||||
{"the trunk alone", "", "", false, true, false, false, SourceTrunk, true},
|
||||
{"its running statement's manifest comes before the trunk's", "", "running", true, true, true, false, SourceStatement, true},
|
||||
{"only its have names the build, whose entry is held (A-482)", "running", "", false, false, false, true, SourceEntry, true},
|
||||
{"none answers", "", "", false, false, false, false, "", false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
env := newFakeBus().env()
|
||||
env.Node = "n1"
|
||||
var said []string
|
||||
env.Say = func(s string) { said = append(said, s) }
|
||||
if tc.composition != "" {
|
||||
fp := map[string]string{"running": running, "other": other}[tc.composition]
|
||||
env.Running = func() []compositions.Composed {
|
||||
return []compositions.Composed{{Node: "n1", Module: "xorg", FP: fp, Data: tc.data}}
|
||||
}
|
||||
}
|
||||
c := New(env)
|
||||
c.mu.Lock()
|
||||
c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "xorg"}}}
|
||||
c.heard = map[string]map[string]heardRun{"n1": {"xorg": {fingerprint: running}}}
|
||||
if tc.haveOnly {
|
||||
c.heard = map[string]map[string]heardRun{}
|
||||
c.haveRuns["xorg"], c.haveFp["xorg"] = true, running
|
||||
}
|
||||
if tc.statement {
|
||||
digest := "sha256:" + strings.Repeat("9", 64)
|
||||
c.heard["n1"]["xorg"] = heardRun{fingerprint: running, manifest: digest}
|
||||
c.manifests[digest] = []byte(body)
|
||||
}
|
||||
if tc.trunk {
|
||||
var man map[string]any
|
||||
_ = json.Unmarshal([]byte(body), &man)
|
||||
c.trunkBuilds = map[string]trunkBuild{"xorg": {running: running, fp: other, manifest: man}}
|
||||
}
|
||||
c.mu.Unlock()
|
||||
if tc.entry != "" {
|
||||
c.holdEntry(t, "xorg", map[string]string{"running": running, "other": other}[tc.entry], body)
|
||||
}
|
||||
c.askTrunkBuilds()()
|
||||
c.layModules()
|
||||
a := c.runningManifest("n1", "xorg", "")
|
||||
again := c.runningManifest("n1", "xorg", "")
|
||||
if a.Source != tc.wantSource || a.Known != tc.wantKnown || (a.Known && len(a.Manifest.Provides) != 1) {
|
||||
t.Fatalf("answered %q (known %v, provides %d), want %q (known %v)", a.Source, a.Known, len(a.Manifest.Provides), tc.wantSource, tc.wantKnown)
|
||||
}
|
||||
sources := 0
|
||||
for _, line := range said {
|
||||
if strings.Contains(line, "runs a build whose manifest is read from "+tc.wantSource) {
|
||||
sources++
|
||||
}
|
||||
}
|
||||
if tc.wantSource != "" && (sources != 1 || again.Said != a.Said) {
|
||||
t.Errorf("said %q, want its source once", said)
|
||||
}
|
||||
if tc.composition != "" && a.Data != tc.data && a.Source != SourceEntry && a.Source != SourceStatement {
|
||||
t.Errorf("the composition's data = %v, want %v", a.Data, tc.data)
|
||||
}
|
||||
if !tc.wantKnown && !strings.Contains(a.Why, SourceEntry) || !tc.wantKnown && !strings.Contains(a.Why, SourceStatement) || !tc.wantKnown && !strings.Contains(a.Why, SourceTrunk) {
|
||||
t.Errorf("the words of an answer that reads no manifest are %q, want the three sources named", a.Why)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// A module counted as running here alone answers a held module's offer and what the module keeps (A-482): one wanted here that
|
||||
// runs nothing and whose have names no build answers nothing, and HoldsData reads the manifest the one place read.
|
||||
env := newFakeBus().env()
|
||||
env.Node = "n1"
|
||||
c := New(env)
|
||||
c.holdEntry(t, "xorg", running, body)
|
||||
c.mu.Lock()
|
||||
c.wants["xorg"] = meshwants.WantsByWantNodeModuleValue{Fp: other}
|
||||
c.haveFp["xorg"] = running
|
||||
c.mu.Unlock()
|
||||
if _, ok := c.runningFor("n1")("xorg"); ok {
|
||||
t.Error("a module wanted here that runs nothing answered a manifest as running")
|
||||
}
|
||||
if data, known := c.HoldsData(context.Background(), "xorg"); data || !known {
|
||||
t.Errorf("HoldsData = %v, %v, want a manifest read that declares no data", data, known)
|
||||
}
|
||||
c.mu.Lock()
|
||||
c.haveRuns["xorg"] = true
|
||||
c.mu.Unlock()
|
||||
if man, ok := c.runningFor("n1")("xorg"); !ok || len(man.Provides) != 1 {
|
||||
t.Error("a module its have says runs answered no manifest")
|
||||
}
|
||||
}
|
||||
|
||||
// A-461, A-461a, A-461b: another node's module whose running build has no entry is laid from the entry of the build the assignment
|
||||
// places for it on that node, or, where the placement names none, of its trunk build; with neither entry it stays as its name
|
||||
// alone, and this node's own module is never laid from a placement.
|
||||
|
||||
Reference in New Issue
Block a user