Make the equality test fail unless every machine of the facts is sent both ways (issue 1384)

A pass printed no line, so it did not show whether idt and ygcyr were compared on the send side or refused alike. A machine either send refuses now fails, naming the machine and both refusals; refusals alike in the Foreseeing comparison (a) stay, said only; facts with no machine fail. A pass proves that every machine was sent and compared.
This commit is contained in:
2026-10-20 10:53:25 +00:00
parent 11e005fe38
commit fb556d6b74
@@ -49,6 +49,9 @@ func TestEveryMachineComposesAlikeBothWays(t *testing.T) {
started := time.Now() started := time.Now()
phase := func(what string) { t.Logf("[%s] %s", time.Since(started).Round(time.Second), what) } phase := func(what string) { t.Logf("[%s] %s", time.Since(started).Round(time.Second), what) }
f, source := equalityFacts(t) f, source := equalityFacts(t)
if len(f.Machines) < 1 {
t.Fatalf("the facts (%s) hold no machine, so nothing was composed and nothing is proved", source)
}
t.Logf("the facts of %s (%s): %d machine(s)", f.Taken.Format("2006-01-02 15:04:05"), source, len(f.Machines)) t.Logf("the facts of %s (%s): %d machine(s)", f.Taken.Format("2006-01-02 15:04:05"), source, len(f.Machines))
shelf, err := shelfOfFacts(f) shelf, err := shelfOfFacts(f)
if err != nil { if err != nil {
@@ -65,7 +68,7 @@ func TestEveryMachineComposesAlikeBothWays(t *testing.T) {
foreseenPorts = map[string][]string{} foreseenPorts = map[string][]string{}
readOld, readSDK = map[string]composedBoth{}, map[string]composedBoth{} readOld, readSDK = map[string]composedBoth{}, map[string]composedBoth{}
oldMade, sdkMade made oldMade, sdkMade made
oldRefused = map[string]bool{} oldRefused = map[string]string{}
sendRefused = map[string]string{} sendRefused = map[string]string{}
errA, errOld, errSDK error errA, errOld, errSDK error
) )
@@ -128,10 +131,11 @@ func TestEveryMachineComposesAlikeBothWays(t *testing.T) {
oldGens, oldGensErr := generators(ctx, oldStore) oldGens, oldGensErr := generators(ctx, oldStore)
for _, m := range f.Machines { for _, m := range f.Machines {
if oldGensErr != nil { if oldGensErr != nil {
break oldRefused[m.Name] = oldGensErr.Error()
continue
} }
if _, _, err := composedAndValidated(ctx, oldStore, m.Name, oldGens, Allocating); err != nil { if _, _, err := composedAndValidated(ctx, oldStore, m.Name, oldGens, Allocating); err != nil {
oldRefused[m.Name] = true oldRefused[m.Name] = err.Error()
} }
} }
phase("(b) the controller's send of every machine") phase("(b) the controller's send of every machine")
@@ -184,16 +188,20 @@ func TestEveryMachineComposesAlikeBothWays(t *testing.T) {
failures = append(failures, bothWaysDiffer(m.Name, "(a) Foreseeing", oldForeseen[m.Name], sdkForeseen[m.Name], false)...) failures = append(failures, bothWaysDiffer(m.Name, "(a) Foreseeing", oldForeseen[m.Name], sdkForeseen[m.Name], false)...)
failures = append(failures, bothWaysDiffer(m.Name, "(c) Reading after the send", readOld[m.Name], readSDK[m.Name], true)...) failures = append(failures, bothWaysDiffer(m.Name, "(c) Reading after the send", readOld[m.Name], readSDK[m.Name], true)...)
} }
// A machine refused on either side sends nothing, so what the controller made on the way to refusing it is no send's. // **The send must compose every machine both ways.** A machine either send refuses is no proof of anything: what the
// controller made on the way to refusing it is no send's, and a refusal alike says nothing about what a send of it makes.
// So it fails here, naming the machine and both refusals (a refusal alike in (a), the Foreseeing on a store that holds no
// secret a send made, is said and stays). A pass proves that every machine of the facts was sent and compared.
refused := map[string]bool{} refused := map[string]bool{}
for m := range sendRefused { for _, m := range f.Machines {
refused[m] = true why, oldNo := oldRefused[m.Name]
} sdkWhy, sdkNo := sendRefused[m.Name]
for m := range oldRefused { if !oldNo && !sdkNo {
refused[m] = true continue
} }
for m := range refused { refused[m.Name] = true
t.Logf("%s: refused on one side or both, so its ports and secrets are left out of the comparison of the send", m) failures = append(failures, fmt.Sprintf("%s, (b) the send: it is not composed both ways, so nothing of it is compared: "+
"the controller's refusal %s, mesh-sdk's %s", m.Name, quoted(oneLine(why)), quoted(oneLine(sdkWhy))))
} }
failures = append(failures, madeDiffer("(b) the send", oldMade, sdkMade, refused)...) failures = append(failures, madeDiffer("(b) the send", oldMade, sdkMade, refused)...)
@@ -234,7 +242,7 @@ func TestEveryMachineComposesAlikeBothWays(t *testing.T) {
if len(failures) > 0 { if len(failures) > 0 {
t.Fatalf("the two compositions differ on %d point(s):\n %s", len(failures), strings.Join(failures, "\n ")) t.Fatalf("the two compositions differ on %d point(s):\n %s", len(failures), strings.Join(failures, "\n "))
} }
t.Logf("%d machine(s) compose alike both ways", len(f.Machines)) t.Logf("%d machine(s) were sent and compose alike both ways", len(f.Machines))
} }
// equalityFacts is the snapshot the comparison composes: MESH_FACTS, else the one captured in testdata, else the facts of a // equalityFacts is the snapshot the comparison composes: MESH_FACTS, else the one captured in testdata, else the facts of a