Skip to content

Commit

Permalink
test: add a memory usage test for real-tikv-test (#37911)
Browse files Browse the repository at this point in the history
ref #35983
  • Loading branch information
tangenta authored Sep 19, 2022
1 parent e3a19d8 commit e506a91
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tests/realtikvtest/addindextest/failpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand Down
53 changes: 53 additions & 0 deletions tests/realtikvtest/addindextest/memory_test.go
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit e506a91

Please sign in to comment.