Commit e101cd89 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-e2e: Recover gracefully from log-after-exit panics (#13190)

* op-e2e: Recover gracefully from log-after-exit panics

There are a lot of places where we log after tests exit. This PR recovers from those panics so tests can continue.

* add helper
parent 508ccbe7
...@@ -159,11 +159,22 @@ func (l *logger) flush() { ...@@ -159,11 +159,22 @@ func (l *logger) flush() {
scanner := bufio.NewScanner(l.buf) scanner := bufio.NewScanner(l.buf)
for scanner.Scan() { for scanner.Scan() {
l.t.Logf("%*s%s", padding, "", scanner.Text()) l.internalFlush("%*s%s", padding, "", scanner.Text())
} }
l.buf.Reset() l.buf.Reset()
} }
func (l *logger) internalFlush(format string, args ...any) {
defer func() {
if r := recover(); r != nil {
log.Warn("testlog: panic during flush", "recover", r)
}
}()
l.t.Helper()
l.t.Logf(format, args...)
}
// The Go testing lib uses the runtime package to get info about the calling site, and then decorates the line. // The Go testing lib uses the runtime package to get info about the calling site, and then decorates the line.
// We can't disable this decoration, but we can adjust the contents to align by padding after the info. // We can't disable this decoration, but we can adjust the contents to align by padding after the info.
// To pad the right amount, we estimate how long the info is. // To pad the right amount, we estimate how long the info is.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment