From 8ef61da86f181a86acd8716335ef3a6ef807c53e Mon Sep 17 00:00:00 2001 From: tangenta Date: Sun, 18 Sep 2022 18:23:36 +0800 Subject: [PATCH] test: add a memory usage test for real-tikv-test --- .../addindextest/failpoints_test.go | 20 +++++-- .../realtikvtest/addindextest/memory_test.go | 53 +++++++++++++++++++ 2 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 tests/realtikvtest/addindextest/memory_test.go diff --git a/tests/realtikvtest/addindextest/failpoints_test.go b/tests/realtikvtest/addindextest/failpoints_test.go index 96d90231284f2..98a0f8e50ff53 100644 --- a/tests/realtikvtest/addindextest/failpoints_test.go +++ b/tests/realtikvtest/addindextest/failpoints_test.go @@ -25,7 +25,9 @@ func initTestFailpoint(t *testing.T) *suiteContext { } func TestFailpointsCreateNonUniqueIndex(t *testing.T) { - t.Skip() + if !*FullMode { + t.Skip() + } var colIDs = [][]int{ {1, 4, 7, 10, 13, 16, 19, 22, 25}, {2, 5, 8, 11, 14, 17, 20, 23, 26}, @@ -36,7 +38,9 @@ func TestFailpointsCreateNonUniqueIndex(t *testing.T) { } func TestFailpointsCreateUniqueIndex(t *testing.T) { - t.Skip() + if !*FullMode { + t.Skip() + } var colIDs = [][]int{ {1, 6, 7, 8, 11, 13, 15, 16, 18, 19, 22, 26}, {2, 9, 11, 17}, @@ -47,19 +51,25 @@ func TestFailpointsCreateUniqueIndex(t *testing.T) { } func TestFailpointsCreatePrimaryKeyFailpoints(t *testing.T) { - t.Skip() + if !*FullMode { + t.Skip() + } ctx := initTest(t) testOneIndexFrame(ctx, 0, addIndexPK) } func TestFailpointsCreateGenColIndex(t *testing.T) { - t.Skip() + if !*FullMode { + t.Skip() + } ctx := initTestFailpoint(t) testOneIndexFrame(ctx, 29, addIndexGenCol) } func TestFailpointsCreateMultiColsIndex(t *testing.T) { - t.Skip() + if !*FullMode { + t.Skip() + } var coliIDs = [][]int{ {1, 4, 7}, {2, 5, 8}, diff --git a/tests/realtikvtest/addindextest/memory_test.go b/tests/realtikvtest/addindextest/memory_test.go new file mode 100644 index 0000000000000..8e482458d4955 --- /dev/null +++ b/tests/realtikvtest/addindextest/memory_test.go @@ -0,0 +1,53 @@ +// Copyright 2022 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package addindextest + +import ( + "fmt" + "strings" + "testing" + + "github.com/pingcap/tidb/ddl/ingest" + "github.com/pingcap/tidb/testkit" + "github.com/pingcap/tidb/tests/realtikvtest" + "github.com/stretchr/testify/require" +) + +func TestLitAddIndexMemoryUsage(t *testing.T) { + store := realtikvtest.CreateMockStoreAndSetup(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("drop database if exists addindexlit;") + tk.MustExec("create database addindexlit;") + tk.MustExec("use addindexlit;") + tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`) + + tk.MustExec("create table t (a int, b int, c int);") + var sb strings.Builder + sb.WriteString("insert into t values ") + size := 100 + for i := 0; i < size; i++ { + sb.WriteString(fmt.Sprintf("(%d, %d, %d)", i, i, i)) + if i != size-1 { + sb.WriteString(",") + } + } + sb.WriteString(";") + tk.MustExec(sb.String()) + require.Equal(t, int64(0), ingest.LitMemRoot.CurrentUsage()) + tk.MustExec("alter table t add index idx(a);") + tk.MustExec("alter table t add unique index idx1(b);") + tk.MustExec("admin check table t;") + require.Equal(t, int64(0), ingest.LitMemRoot.CurrentUsage()) +}