Skip to content

Commit

Permalink
log: fix stacktrace test goroutine counts
Browse files Browse the repository at this point in the history
Previously, we would use the count of the string `goroutine ` as a
proxy for the number of goroutines in the stacktrace. This stopped
working in go 1.21 due to this change:
golang/go@51225f6

We should consider using a stacktrace parser in the future.

Supports #112088

Epic: None
Release note: None
  • Loading branch information
dhartunian committed Oct 20, 2023
1 parent 72c01ad commit f4cb9c5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/util/log/clog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,17 +586,23 @@ func TestFatalStacktraceStderr(t *testing.T) {
if !strings.Contains(cont, "clog_test") {
t.Fatalf("stack trace does not contain file name: %s", cont)
}

// NB: the string "!goroutine" is used here in order to match the
// goroutine headers in the formatted output. The stacktrace
// itself can sometimes contain the string `goroutine` if one
// goroutine is spawned from another due to
// https://github.com/golang/go/commit/51225f6fc648ba3e833f3493700c2996a816bdaa
switch traceback {
case tracebackNone:
if strings.Count(cont, "goroutine ") > 0 {
if strings.Count(cont, "!goroutine ") > 0 {
t.Fatalf("unexpected stack trace:\n%s", cont)
}
case tracebackSingle:
if strings.Count(cont, "goroutine ") != 1 {
if strings.Count(cont, "!goroutine ") != 1 {
t.Fatalf("stack trace contains too many goroutines: %s", cont)
}
case tracebackAll:
if strings.Count(cont, "goroutine ") < 2 {
if strings.Count(cont, "!goroutine ") < 2 {
t.Fatalf("stack trace contains less than two goroutines: %s", cont)
}
}
Expand Down

0 comments on commit f4cb9c5

Please sign in to comment.