Skip to content

Commit fbe67ce

Browse files
committed
sql: speed up recently added TestTruncateLarge
We just saw a timeout in tests where 15m limit was exceeded because more than 11m were consumed by TestTruncateLarge. In order to speed up the test, this commit reduces the number of tables affected as well as splits up two sub-tests into separate tests (hoping that they will end up in different shards). Release note: None
1 parent cddd383 commit fbe67ce

File tree

1 file changed

+42
-32
lines changed

1 file changed

+42
-32
lines changed

pkg/sql/drop_test.go

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,42 +1557,52 @@ func TestDropLargeDatabaseWithDeclarativeSchemaChanger(t *testing.T) {
15571557
func TestTruncateLarge(t *testing.T) {
15581558
defer leaktest.AfterTest(t)()
15591559
defer log.Scope(t).Close(t)
1560-
skip.UnderDuress(t, "truncating a large number of tables")
1560+
testTruncateLarge(t, true /* batchLimitSet */)
1561+
}
15611562

1562-
testutils.RunTrueAndFalse(t, "batch limit set", func(t *testing.T, batchLimitSet bool) {
1563-
ctx := context.Background()
1564-
srv, conn, _ := serverutils.StartServer(t, base.TestServerArgs{})
1565-
defer srv.Stopper().Stop(ctx)
1566-
sqlDB := sqlutils.MakeSQLRunner(conn)
1567-
createCommand := strings.Builder{}
1568-
truncateCommand := strings.Builder{}
1569-
systemDB := sqlutils.MakeSQLRunner(srv.SystemLayer().SQLConn(t))
1570-
systemDB.Exec(t, "SET CLUSTER SETTING kv.raft.command.max_size='5m'")
1571-
if batchLimitSet {
1572-
sqlDB.Exec(t, "SET CLUSTER SETTING sql.schema_changer.batch_flush_threshold_size='2m'")
1573-
}
1574-
// Generate the truncate and create table commands.
1575-
const numTables = 500
1576-
truncateCommand.WriteString("TRUNCATE TABLE ")
1577-
for i := range numTables {
1578-
createCommand.WriteString(fmt.Sprintf("CREATE TABLE t%d (a INT PRIMARY KEY, j INT, k INT, INDEX (j), INDEX (k), UNIQUE (j, k));\n", i))
1579-
truncateCommand.WriteString(fmt.Sprintf("t%d", i))
1580-
if i != numTables-1 {
1581-
truncateCommand.WriteString(", ")
1582-
}
1583-
}
1584-
// Execute the create commands first.
1585-
sqlDB.Exec(t, createCommand.String())
1563+
// TestTruncateLargeErr verifies that an error is returned if the batch limit is
1564+
// effectively not set.
1565+
func TestTruncateLargeErr(t *testing.T) {
1566+
defer leaktest.AfterTest(t)()
1567+
defer log.Scope(t).Close(t)
1568+
testTruncateLarge(t, false /* batchLimitSet */)
1569+
}
15861570

1587-
// The default limit is larger than our reduced raft command size, so if the
1588-
// limit is not modified, the truncate command will fail.
1589-
if batchLimitSet {
1590-
sqlDB.Exec(t, truncateCommand.String())
1591-
} else {
1592-
sqlDB.ExpectErr(t, "command is too large", truncateCommand.String())
1593-
}
1571+
func testTruncateLarge(t *testing.T, batchLimitSet bool) {
1572+
skip.UnderDuress(t, "truncating a large number of tables")
1573+
1574+
srv, conn, _ := serverutils.StartServer(t, base.TestServerArgs{
1575+
SQLMemoryPoolSize: 1 << 30, /* 1 GiB */
15941576
})
1577+
defer srv.Stopper().Stop(context.Background())
1578+
sqlDB := sqlutils.MakeSQLRunner(conn)
1579+
createCommand := strings.Builder{}
1580+
truncateCommand := strings.Builder{}
1581+
systemDB := sqlutils.MakeSQLRunner(srv.SystemLayer().SQLConn(t))
1582+
systemDB.Exec(t, "SET CLUSTER SETTING kv.raft.command.max_size='4.1MiB'")
1583+
if batchLimitSet {
1584+
sqlDB.Exec(t, "SET CLUSTER SETTING sql.schema_changer.batch_flush_threshold_size='1.8MiB'")
1585+
}
1586+
// Generate the truncate and create table commands.
1587+
const numTables = 340
1588+
truncateCommand.WriteString("TRUNCATE TABLE ")
1589+
for i := range numTables {
1590+
createCommand.WriteString(fmt.Sprintf("CREATE TABLE t%d (a INT PRIMARY KEY, j INT, k INT, INDEX (j), INDEX (k), UNIQUE (j, k));\n", i))
1591+
truncateCommand.WriteString(fmt.Sprintf("t%d", i))
1592+
if i != numTables-1 {
1593+
truncateCommand.WriteString(", ")
1594+
}
1595+
}
1596+
// Execute the create commands first.
1597+
sqlDB.Exec(t, createCommand.String())
15951598

1599+
// The default limit is larger than our reduced raft command size, so if the
1600+
// limit is not modified, the truncate command will fail.
1601+
if batchLimitSet {
1602+
sqlDB.Exec(t, truncateCommand.String())
1603+
} else {
1604+
sqlDB.ExpectErr(t, "command is too large", truncateCommand.String())
1605+
}
15961606
}
15971607

15981608
func BenchmarkDropLargeDatabaseWithGenerateTestObjects(b *testing.B) {

0 commit comments

Comments
 (0)