carlos / platform Public

tests: tap trace for DBForward and per-line #733 logs (#897)

Diagnostics only. The DBForward e2e tap records how each connection
ended and prints it when the CLI read fails; the departure scan rigs
print the controller log one line per t.Logf so the gate's failure
summary keeps it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from dbforward-tap-trace into main.
claude agent, operated by paul@keymail.dev 3a7654d2fc2a1652c2560e91a463780f0a5d1ef0 parent a178a75
2 files changed, +36 −2
  • dbforward_e2e_test.go +30 −1
  • internal/host/hadepartures_scan_test.go +6 −1

CI failed — run details

diff --git a/dbforward_e2e_test.go b/dbforward_e2e_test.go
index 211a8442a..31a8b6db2 100644
--- a/dbforward_e2e_test.go
+++ b/dbforward_e2e_test.go
@@ -392,6 +392,22 @@ type dbfTap struct {
addr string
mu sync.Mutex
down []time.Time
+ // events says how each tapped connection ended, and when, so a
+ // failure can tell which side closed first (#897: the CLI's read was
+ // admitted and then "client gone" a millisecond later, on CI only).
+ events []string
+}
+
+func (tp *dbfTap) event(f string, args ...any) {
+ tp.mu.Lock()
+ defer tp.mu.Unlock()
+ tp.events = append(tp.events, time.Now().Format("15:04:05.000000 ")+fmt.Sprintf(f, args...))
+}
+
+func (tp *dbfTap) trace() string {
+ tp.mu.Lock()
+ defer tp.mu.Unlock()
+ return strings.Join(tp.events, "\n")
}
func newDBFTap(t *testing.T, target string, connect bool) *dbfTap {
@@ -430,25 +446,33 @@ func (tp *dbfTap) serve(c net.Conn, target string, connect bool) {
}
up, err := net.Dial("tcp", target)
if err != nil {
+ tp.event("%s: dial upstream: %v", c.RemoteAddr(), err)
return
}
defer up.Close()
+ id := c.RemoteAddr().String() + "->" + up.LocalAddr().String()
+ tp.event("%s: open", id)
go func() {
- io.Copy(up, in)
+ n, err := io.Copy(up, in)
+ tp.event("%s: client side ended after %d bytes up: %v", id, n, err)
up.(*net.TCPConn).CloseWrite()
}()
buf := make([]byte, 32<<10)
+ var total int
for {
n, err := up.Read(buf)
if n > 0 {
+ total += n
tp.mu.Lock()
tp.down = append(tp.down, time.Now())
tp.mu.Unlock()
if _, werr := c.Write(buf[:n]); werr != nil {
+ tp.event("%s: write to client after %d bytes down: %v", id, total, werr)
return
}
}
if err != nil {
+ tp.event("%s: upstream side ended after %d bytes down: %v", id, total, err)
return
}
}
@@ -505,6 +529,11 @@ func checkProgressAtTheCLI(t *testing.T, e *dbfE2E, tap *dbfTap, atLeast time.Du
err = cmd.Wait()
end := time.Now()
if err != nil || out.String() != "n\n3\n" {
+ // One t.Logf per line: the CI gate's summary keeps only lines
+ // carrying the test file's prefix.
+ for _, line := range strings.Split(tap.trace(), "\n") {
+ t.Logf("tap: %s", line)
+ }
t.Fatalf("%q %v\n%s", out.String(), err, strings.Join(stderr, "\n"))
}
if reading.IsZero() || reading.Sub(start) > time.Second {
diff --git a/internal/host/hadepartures_scan_test.go b/internal/host/hadepartures_scan_test.go
index a9a003f83..27c4d03d7 100644
--- a/internal/host/hadepartures_scan_test.go
+++ b/internal/host/hadepartures_scan_test.go
@@ -79,7 +79,12 @@ func (l *scanLog) dumpOnFailure(t *testing.T) {
}
l.mu.Lock()
defer l.mu.Unlock()
- t.Logf("controller log (%d lines):\n%s", len(l.lines), strings.Join(l.lines, "\n"))
+ // One t.Logf per line: the CI gate's summary keeps only lines
+ // carrying the test file's prefix.
+ t.Logf("controller log (%d lines):", len(l.lines))
+ for _, line := range l.lines {
+ t.Logf(" %s", line)
+ }
})
}