Skip to content

Commit

Permalink
op-e2e: Recover gracefully from log-after-exit panics (ethereum-optim…
Browse files Browse the repository at this point in the history
…ism#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
  • Loading branch information
mslipper authored Dec 3, 2024
1 parent 508ccbe commit e101cd8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion op-service/testlog/testlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,22 @@ func (l *logger) flush() {

scanner := bufio.NewScanner(l.buf)
for scanner.Scan() {
l.t.Logf("%*s%s", padding, "", scanner.Text())
l.internalFlush("%*s%s", padding, "", scanner.Text())
}
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.
// 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.
Expand Down

0 comments on commit e101cd8

Please sign in to comment.