Skip to content

Commit

Permalink
Merge pull request #95185 from yuzefovich/fix-invalid-count
Browse files Browse the repository at this point in the history
randgen: enforce at least 1 count element for generate_test_objects
  • Loading branch information
yuzefovich authored Jan 13, 2023
2 parents a3d5366 + c526b5a commit 5ab50d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/sql/catalog/randgen/randgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (g *testSchemaGenerator) prepareCounts(
const reasonableMaxCount = 10000000
for _, sz := range counts {
// We cap the individual count to a maximum number for two purposes.
// One is that abnormally large values are likely indicative of
// One is that abnormally large values are likely indicative
// of a user mistake; in which case we want an informative error message
// instead of something related to memory usage.
// The second is that we want to avoid an overflow in the computation
Expand All @@ -328,8 +328,8 @@ func (g *testSchemaGenerator) prepareCounts(
g.gencfg.createDatabases = false
g.gencfg.createSchemas = false
g.gencfg.useGeneratedPublicSchema = false
if len(counts) > 3 {
panic(genError{errors.WithHint(pgerror.Newf(pgcode.Syntax, "too many counts"),
if len(counts) < 1 || len(counts) > 3 {
panic(genError{errors.WithHint(pgerror.Newf(pgcode.Syntax, "invalid count"),
"Must specify between 1 and 3 counts.")})
}
numNewDatabases := 0
Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/gen_test_objects
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ SELECT crdb_internal.generate_test_objects('{"names":"a.b.c","counts":[0,0,10000
query error too many objects generated
SELECT crdb_internal.generate_test_objects('{"names":"a.b.c","counts":[10000000,10000000,10000000]}'::jsonb)

subtest invalid_count

query error invalid count
SELECT crdb_internal.generate_test_objects('foo', ARRAY[]::INT8[])

query error invalid count
SELECT crdb_internal.generate_test_objects('foo', ARRAY[1, 2, 3, 4, 5]::INT8[])

subtest temp_schema

# Force create the temp schema.
Expand Down

0 comments on commit 5ab50d3

Please sign in to comment.