Skip to content

Commit

Permalink
opt: make max-stack opt tester option more reliable
Browse files Browse the repository at this point in the history
The `max-stack` opt tester option now runs the test command in a
separate goroutine. A fresh stack makes tests using this setting more
reliable.

It also decreases the `max-stack` of the original test that motivated
the `max-stack` option (see #132701) to 100KB, between 65KB in which the
test fails after the fix in #132701 and 135KB in which the test fails
before the fix.

Finally, the test has been disabled under `race` builds which increase
the size of stack frames and would cause this test to fail.

Release note: None
  • Loading branch information
mgartner committed Nov 5, 2024
1 parent 74372bc commit 535ad0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pkg/sql/opt/testutils/opttester/opt_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"testing"
"text/tabwriter"
"time"
Expand Down Expand Up @@ -588,8 +589,23 @@ func (ot *OptTester) RunCommand(tb testing.TB, d *datadriven.TestData) string {
if ot.Flags.MaxStackBytes > 0 {
originalMaxStack := debug.SetMaxStack(ot.Flags.MaxStackBytes)
defer debug.SetMaxStack(originalMaxStack)
// Spawn a separate goroutine. A fresh stack makes tests using this
// setting more reliable.
var wg sync.WaitGroup
wg.Add(1)
var res string
go func() {
defer wg.Done()
res = ot.runCommandInternal(tb, d)
}()
wg.Wait()
return res
} else {
return ot.runCommandInternal(tb, d)
}
}

func (ot *OptTester) runCommandInternal(tb testing.TB, d *datadriven.TestData) string {
switch d.Cmd {
case "exec-ddl":
testCatalog, ok := ot.catalog.(*testcat.Catalog)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/xform/testdata/rules/select
Original file line number Diff line number Diff line change
Expand Up @@ -2661,7 +2661,7 @@ CREATE TABLE t132669 (
# unnecessary recursion to trigger a stack overflow without having to make the
# `IN` list below huge - triggering a stack overflow with Go's default max stack
# size requires a list of ~1.6 million elements.
opt max-stack=125KB format=hide-all
opt max-stack=100kB skip-race format=hide-all
SELECT * FROM t132669
WHERE a IN (
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
Expand Down

0 comments on commit 535ad0e

Please sign in to comment.