carlos / platform Public

activator: tee tests wait for the writer, fix the clock, drain the journal

The stalled test waits (bounded) for the journal writer to reach its
stalled write instead of checking once. The cap test fixes the per-child
cap's clock (execTeeNow), waits for the journal queue to be written out
rather than for the first drop notice, and checks exactly the burst and
that the notices count every byte the cap dropped. (Astra R1 P2.)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1992d4e298fcc5d1a1f9bf4a7f5af7eb67c0827c parent 9f0ddbf
2 files changed, +40 −12
  • internal/activator/exectee.go +4 −1
  • internal/activator/exectee_test.go +36 −11
diff --git a/internal/activator/exectee.go b/internal/activator/exectee.go
index 6b94fa543..fcfdca0da 100644
--- a/internal/activator/exectee.go
+++ b/internal/activator/exectee.go
@@ -75,8 +75,11 @@ type execJournalCopy struct {
cap lineCap
}
+// execTeeNow is the clock of each child's journal line cap; tests fix it.
+var execTeeNow = time.Now
+
func newExecJournalCopy(label string) *execJournalCopy {
- return &execJournalCopy{journal: agentJournal(), label: label, cap: newLineCap(logJournalLinesPerMin, logJournalLineBurst, time.Now)}
+ return &execJournalCopy{journal: agentJournal(), label: label, cap: newLineCap(logJournalLinesPerMin, logJournalLineBurst, execTeeNow)}
}
func (c *execJournalCopy) line(line string) {
diff --git a/internal/activator/exectee_test.go b/internal/activator/exectee_test.go
index 8b45961fd..9f8b96b9e 100644
--- a/internal/activator/exectee_test.go
+++ b/internal/activator/exectee_test.go
@@ -2,6 +2,7 @@ package activator
import (
"bufio"
+ "fmt"
"io"
"os"
"os/exec"
@@ -120,9 +121,11 @@ func TestExecTeeStalledJournalBlocksNoDrainNoTenantNoWait(t *testing.T) {
if err := <-waited; err != nil {
t.Fatalf("flooding child: %v", err)
}
+ // The journal's writer runs on its own: give it a bounded time to
+ // reach the stalled write, which holds it from then on.
select {
case <-journal.entered:
- default:
+ case <-time.After(5 * time.Second):
t.Fatal("nothing reached the journal: the stall was never in the way")
}
@@ -152,10 +155,13 @@ func TestExecTeeStalledJournalBlocksNoDrainNoTenantNoWait(t *testing.T) {
func TestExecTeeJournalCopyIsCappedLinesPerChild(t *testing.T) {
out := &stallWriter{release: make(chan struct{}), entered: make(chan struct{}, 1)}
out.unstall()
- agent := agentJournal
+ agent, now := agentJournal, execTeeNow
j := newLogJournal(out, 64<<20)
agentJournal = func() *logJournal { return j }
- t.Cleanup(func() { agentJournal = agent; j.stop() })
+ // A fixed clock: each child's cap gets its burst and no refill.
+ fixed := time.Unix(1_700_000_000, 0)
+ execTeeNow = func() time.Time { return fixed }
+ t.Cleanup(func() { agentJournal, execTeeNow = agent, now; j.stop() })
sink := &teeSink{}
b := &ExecBackend{Logs: sink}
@@ -166,22 +172,41 @@ func TestExecTeeJournalCopyIsCappedLinesPerChild(t *testing.T) {
t.Fatalf("%s child: %v", mode, err)
}
}
- waitFor(t, "the journal copy", func() bool {
- return strings.Contains(out.String(), "no newline at exit\n") && strings.Contains(out.String(), "flood.example.com: dropped")
+ // Run returns once both streams are copied, so every line and notice
+ // is queued; the journal is drained once its writer has written them
+ // all out (logJournal.size counts what it has not finished writing).
+ waitFor(t, "the journal drained", func() bool {
+ j.mu.Lock()
+ defer j.mu.Unlock()
+ return j.head == nil && j.size == 0
})
lines := strings.Split(strings.TrimSuffix(out.String(), "\n"), "\n")
- floods := 0
+ // The flooding child's lines (stdout's and its one stderr line share
+ // the cap) that reached the journal, and their bytes.
+ floods, kept := 0, 0
for _, line := range lines {
if strings.HasPrefix(line, "flood") && !strings.Contains(line, "dropped") {
floods++
+ kept += len(line) + 1
}
}
- // The burst, and what the cap refilled while the flood ran.
- if floods < logJournalLineBurst || floods >= execTeeFloodLines/2 {
- t.Errorf("journal got %d flood lines, want the per-child burst %d and little more", floods, logJournalLineBurst)
+ if floods != logJournalLineBurst {
+ t.Errorf("journal got %d flood lines, want the per-child burst %d", floods, logJournalLineBurst)
}
- if !strings.Contains(out.String(), "flood.example.com: dropped ") || !strings.Contains(out.String(), " byte(s) of app output (journal line cap)\n") {
- t.Errorf("no journal line cap notice for the flooding child in %d lines", len(lines))
+ if !strings.Contains(out.String(), "no newline at exit\n") {
+ t.Error("the journal copy's last line, with no newline, was not flushed at the stream's end")
+ }
+ // The two streams share the cap; each reports what it took from it at
+ // its end, so the notices add up to every flood line the cap dropped.
+ var dropped int
+ for _, line := range lines {
+ var n int
+ if _, err := fmt.Sscanf(line, "flood.example.com: dropped %d byte(s) of app output (journal line cap)", &n); err == nil {
+ dropped += n
+ }
+ }
+ if want := execTeeFloodLines*1024 + len("flood-err\n") - kept; dropped != want {
+ t.Errorf("journal line cap notices count %d bytes, want %d (all the child wrote less what the journal kept)", dropped, want)
}
if got := sink.of("partial.example.com"); len(got) != 1 || got[0] != "whole" {
t.Errorf("tenant lines %q: the tenant sink keeps only complete lines, as before", got)