host: departure scan rigs print the controller's log when a test fails
TestHADepartureProductionWiring/two_fixed_receivers and TestDeparturePoolCoverage (#733) fail on CI with a bare count (0 imports, 0 acks) and never locally, even 30 runs under load. The rig used to drop the controller's log lines. It now keeps them, with each pass's result, and prints them only on failure.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+31
−2
internal/host/hadepartures_scan_test.go+31 −2
CI failed — run details
diff --git a/internal/host/hadepartures_scan_test.go b/internal/host/hadepartures_scan_test.go| index 1db86ebdc..a9a003f83 100644 |
| --- a/internal/host/hadepartures_scan_test.go |
| +++ b/internal/host/hadepartures_scan_test.go |
| @@ -15,6 +15,7 @@ import ( |
| "github.com/carlosframework/platform/internal/termfence" |
| "path/filepath" |
| "strings" |
| + "sync" |
| "sync/atomic" |
| "testing" |
| "time" |
| @@ -54,6 +55,32 @@ type scanRig struct { |
| d registry.HADeparture |
| store *release.DirStore |
| imports int |
| + log scanLog |
| +} |
| + |
| +// scanLog keeps the controller's log lines and prints them only when the |
| +// test fails, so a CI failure says why a pass did not adopt (#733). It is |
| +// written from the consumer's goroutine too, hence the lock. |
| +type scanLog struct { |
| + mu sync.Mutex |
| + lines []string |
| +} |
| + |
| +func (l *scanLog) logf(f string, args ...any) { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + l.lines = append(l.lines, time.Now().Format("15:04:05.000 ")+fmt.Sprintf(f, args...)) |
| +} |
| + |
| +func (l *scanLog) dumpOnFailure(t *testing.T) { |
| + t.Cleanup(func() { |
| + if !t.Failed() { |
| + return |
| + } |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + t.Logf("controller log (%d lines):\n%s", len(l.lines), strings.Join(l.lines, "\n")) |
| + }) |
| } |
| func newScanRig(t *testing.T, n int) *scanRig { |
| @@ -69,6 +96,7 @@ func newScanRigRef(t *testing.T, n int, ref string) *scanRig { |
| } |
| t.Cleanup(func() { r.Close() }) |
| x := &scanRig{r: r, now: time.Now(), locks: &scanReader{views: map[string]hafresh.View{}}, store: release.NewDirStore(t.TempDir())} |
| + x.log.dumpOnFailure(t) |
| scope := hadeparture.Scope{CloudRegion: "eu-west-1", DataBucket: "data", SecretsKeyFP: "fp"} |
| x.d = registry.HADeparture{Departure: hadeparture.Departure{ID: "dead", Box: hadeparture.Box{Ref: ref, InstanceID: "i-1123456789abcdef0", Account: "111122223333", Scope: scope}, ObservedAt: x.now.Add(-time.Hour), EdgesKey: "control/edges/" + ref + ".json"}, ProofKey: "proof", ProofDigest: "digest"} |
| edgeBody, _ := json.Marshal(map[string]string{"box": ref}) |
| @@ -86,7 +114,7 @@ func newScanRigRef(t *testing.T, n int, ref string) *scanRig { |
| marker := hafresh.Marker{V: 1, Box: ref, IID: x.d.Box.InstanceID, Lifetime: "life"} |
| x.locks.views[h.Host] = hafresh.View{ETag: "old", Lock: hafresh.Lock{Generation: 1, ExpiresAt: time.Unix(0, 0), Owner: hafresh.MarkerOwner(marker), Release: &marker}} |
| } |
| - x.c = &Controller{cfg: DepartureConfig{Registry: r, Self: hadeparture.Box{Ref: "self", InstanceID: "i-0123456789abcdef0", Account: "111122223333", Scope: scope}, Inventory: func() provision.InventorySnapshot { return x.inv }, Policy: func() LocalPolicy { return LocalPolicy{Scope: scope} }, Now: func() time.Time { return x.now }, Logf: func(string, ...any) {}, OpenStore: func(context.Context) (release.Store, error) { return x.store, nil }, NewReader: func(context.Context, string) (DepartureLockReader, error) { return x.locks, nil }, Prefix: func(h string) string { return h }, ValidateSuccessor: func(context.Context, string, string) (bool, error) { return true, nil }}, evidence: map[string]bool{"dead": true}} |
| + x.c = &Controller{cfg: DepartureConfig{Registry: r, Self: hadeparture.Box{Ref: "self", InstanceID: "i-0123456789abcdef0", Account: "111122223333", Scope: scope}, Inventory: func() provision.InventorySnapshot { return x.inv }, Policy: func() LocalPolicy { return LocalPolicy{Scope: scope} }, Now: func() time.Time { return x.now }, Logf: x.log.logf, OpenStore: func(context.Context) (release.Store, error) { return x.store, nil }, NewReader: func(context.Context, string) (DepartureLockReader, error) { return x.locks, nil }, Prefix: func(h string) string { return h }, ValidateSuccessor: func(context.Context, string, string) (bool, error) { return true, nil }}, evidence: map[string]bool{"dead": true}} |
| x.c.cfg.Adopt = func(ctx context.Context, h provision.DepartureHost, d registry.HADeparture, v hafresh.View) (activator.AdoptResult, error) { |
| x.imports++ |
| v.ETag = "new" |
| @@ -105,7 +133,8 @@ func newScanRigRef(t *testing.T, n int, ref string) *scanRig { |
| } |
| func (x *scanRig) pass(t *testing.T) { |
| t.Helper() |
| - _, err := x.c.ScanPass(t.Context()) |
| + worked, err := x.c.ScanPass(t.Context()) |
| + x.log.logf("test: %s ScanPass at %s: worked=%v err=%v", x.c.cfg.Self.Ref, x.now.Format(time.RFC3339), worked, err) |
| if err != nil { |
| t.Fatal(err) |
| } |