diff --git a/internal/stack/stacks_test.go b/internal/stack/stacks_test.go index b1a21d8..6bcf904 100644 --- a/internal/stack/stacks_test.go +++ b/internal/stack/stacks_test.go @@ -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 @@ -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() @@ -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")