Skip to content

Commit

Permalink
Fix large stack test for elided frames in 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv committed Apr 13, 2024
1 parent b62053b commit 91a08b9
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions internal/stack/stacks_test.go
Expand Up @@ -135,6 +135,16 @@ func TestCurrentCreatedBy(t *testing.T) {
"TestCurrentCreatedBy.func1 is not in stack:\n%s", stack.Full())
}

//go:noinline // disable inlining for stack frame ellision in 1.20
func recurse(n int, endFn func()) {
if n <= 0 {
endFn()
return
}

recurse(n-1, endFn)
}

func TestAllLargeStack(t *testing.T) {
const (
stackDepth = 101
Expand All @@ -145,17 +155,11 @@ func TestAllLargeStack(t *testing.T) {

done := make(chan struct{})
for i := 0; i < numGoroutines; i++ {
var f func(int)
f = func(count int) {
if count == 0 {
started.Done()
<-done
return
}
f(count - 1)
}
started.Add(1)
go f(stackDepth)
go recurse(stackDepth, func() {
started.Done()
<-done
})
}

started.Wait()
Expand All @@ -168,7 +172,7 @@ func TestAllLargeStack(t *testing.T) {
// We want to check this here, so that if the format of the "elided frames" message changes, we catch it.
// At the time of writing this test, with a stack depth of 101, we get 2 elided frames:
// "...2 frames elided...".
assert.Contains(t, string(buf), "frames elided...")
assert.Contains(t, string(buf), "frames elided...", "stack doesn't contain elided frames")
stacks, err := newStackParser(bytes.NewReader(buf)).Parse()
require.NoError(t, err)
assert.Greater(t, len(stacks), numGoroutines, "expect more parsed stacks than goroutines")
Expand Down

0 comments on commit 91a08b9

Please sign in to comment.