Skip to content

Commit 9a3dda7

Browse files
committed
tree: speed up two tests
We just saw a package-level test timeout of 1 minute being hit because `TestRandomInjectHints` took 29s and `TestParseArrayRandomParseArray` took 16s before interruption. This commit reduces the number of iterations by 5x and 10x, respectively. Release note: None
1 parent 3b2811c commit 9a3dda7

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

pkg/sql/sem/tree/inject_hints_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func TestRandomInjectHints(t *testing.T) {
241241
skip.UnderDeadlock(t, "the test is too slow")
242242
skip.UnderRace(t, "the test is too slow")
243243

244-
const numStatements = 500
244+
const numStatements = 100
245245

246246
ctx := context.Background()
247247
rng, seed := randutil.NewTestRand()

pkg/sql/sem/tree/parse_array_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ package tree
88
import (
99
"bytes"
1010
"context"
11-
"math/rand"
1211
"testing"
1312

1413
"github.com/cockroachdb/cockroach/pkg/sql/types"
1514
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
1615
"github.com/cockroachdb/cockroach/pkg/util/log"
16+
"github.com/cockroachdb/cockroach/pkg/util/randutil"
1717
)
1818

1919
var tupleOfTwoInts = types.MakeTuple([]*types.T{types.Int, types.Int})
@@ -144,21 +144,22 @@ type noopUnwrapCompareContext struct {
144144

145145
func (noopUnwrapCompareContext) UnwrapDatum(ctx context.Context, d Datum) Datum { return d }
146146

147-
const randomArrayIterations = 1000
147+
const randomArrayIterations = 100
148148
const randomArrayMaxLength = 10
149149
const randomStringMaxLength = 1000
150150

151151
func TestParseArrayRandomParseArray(t *testing.T) {
152152
defer leaktest.AfterTest(t)()
153153
defer log.Scope(t).Close(t)
154+
rng, _ := randutil.NewTestRand()
154155
for i := 0; i < randomArrayIterations; i++ {
155-
numElems := rand.Intn(randomArrayMaxLength)
156+
numElems := rng.Intn(randomArrayMaxLength)
156157
ary := make([][]byte, numElems)
157158
for aryIdx := range ary {
158-
len := rand.Intn(randomStringMaxLength)
159+
len := rng.Intn(randomStringMaxLength)
159160
str := make([]byte, len)
160161
for strIdx := 0; strIdx < len; strIdx++ {
161-
str[strIdx] = byte(rand.Intn(256))
162+
str[strIdx] = byte(rng.Intn(256))
162163
}
163164
ary[aryIdx] = str
164165
}
@@ -175,7 +176,7 @@ func TestParseArrayRandomParseArray(t *testing.T) {
175176
// means that there's no printable way to encode non-printing characters,
176177
// users must use `e` prefixed strings).
177178
for _, c := range b {
178-
if c == '"' || c == '\\' || rand.Intn(10) == 0 {
179+
if c == '"' || c == '\\' || rng.Intn(10) == 0 {
179180
buf.WriteByte('\\')
180181
}
181182
buf.WriteByte(c)

0 commit comments

Comments
 (0)