carlos / platform Public

activator: listener line-start test waits for the burst's lines

TestLogListenerCapRecoversLineStartPerConnection failed on hosted CI at
242055c52 ("timed out waiting for b-line"). It is a flake from main
(F9), not this branch: with main's activator it failed 3 of 400 runs
under -race -cpu 1,2. logBudget.pass counts a read's dropped bytes
before the tee writes out that read's kept ones, so capDropped could
return while the burst's last lines were still on their way and b-line
landed among them. Both subtests now wait for every burst line before
the other connection writes; 0 of 400 after.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1e609dcfb6f2e220af8d08bf96021110c29ddb13 parent 242055c
1 file changed, +10 −0
  • internal/activator/loglistener_bounds_test.go +10 −0
diff --git a/internal/activator/loglistener_bounds_test.go b/internal/activator/loglistener_bounds_test.go
index 49b716369..663bf266b 100644
--- a/internal/activator/loglistener_bounds_test.go
+++ b/internal/activator/loglistener_bounds_test.go
@@ -114,6 +114,14 @@ func TestLogListenerCapRecoversLineStartPerConnection(t *testing.T) {
_, lines, _ := got.snapshot()
return lines[min(len(lines), len(burst)/1024):]
}
+ // The budget counts a read's dropped bytes before the tee writes out
+ // the same read's kept ones, so capDropped can return while the
+ // burst's last lines are still on their way to the sink. Wait for
+ // all of them, or another connection's line can land among them.
+ burstIn := func(t *testing.T, got *capCapture) {
+ t.Helper()
+ waitFor(t, "the burst's lines", func() bool { _, lines, _ := got.snapshot(); return len(lines) == len(burst)/1024 })
+ }
t.Run("another connection's newline does not end a partial line", func(t *testing.T) {
t.Parallel()
l, path, got, clock := capListener(t, true)
@@ -129,6 +137,7 @@ func TestLogListenerCapRecoversLineStartPerConnection(t *testing.T) {
defer cb.Close()
writeAll(t, ca, append(append([]byte(nil), burst...), "a-partial-"...))
capDropped(t, l, int64(len("a-partial-")))
+ burstIn(t, got)
writeAll(t, cb, []byte("b-dropped\n"))
capDropped(t, l, int64(len("a-partial-")+len("b-dropped\n")))
clock.add(61 * time.Second)
@@ -153,6 +162,7 @@ func TestLogListenerCapRecoversLineStartPerConnection(t *testing.T) {
defer cb.Close()
writeAll(t, ca, append(append([]byte(nil), burst...), "a-partial-"...))
capDropped(t, l, int64(len("a-partial-")))
+ burstIn(t, got)
clock.add(61 * time.Second)
writeAll(t, cb, []byte("b-line\n"))
waitFor(t, "b-line", func() bool { tl := tail(got); return len(tl) == 1 && tl[0] == "b-line" })