Skip to content

Commit

Permalink
test: add realtikvtest for load data (#42762)
Browse files Browse the repository at this point in the history
ref #40499
  • Loading branch information
D3Hunter authored Apr 3, 2023
1 parent fd57e50 commit 193023b
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ bazel_addindextest: failpoint-enable bazel_ci_prepare
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv --define gotags=deadlock,intest \
-- //tests/realtikvtest/addindextest/...

bazel_loaddatatest: failpoint-enable bazel_ci_prepare
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv --define gotags=deadlock,intest \
-- //tests/realtikvtest/loaddatatest/...

bazel_lint: bazel_prepare
bazel build //... --//build:with_nogo_flag=true

Expand Down
21 changes: 21 additions & 0 deletions tests/realtikvtest/loaddatatest/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "loaddatatest_test",
timeout = "short",
srcs = [
"main_test.go",
"util_test.go",
],
flaky = True,
race = "on",
deps = [
"//config",
"//kv",
"//testkit",
"//tests/realtikvtest",
"@com_github_fsouza_fake_gcs_server//fakestorage",
"@com_github_stretchr_testify//suite",
"@org_uber_go_goleak//:goleak",
],
)
38 changes: 38 additions & 0 deletions tests/realtikvtest/loaddatatest/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023 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 loaddatatest

import (
"testing"

"github.com/pingcap/tidb/config"
"go.uber.org/goleak"
)

func init() {
// need a real PD
config.UpdateGlobal(func(conf *config.Config) {
conf.Path = "127.0.0.1:2379"
})
}

func TestMain(m *testing.M) {
opts := []goleak.Option{
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
goleak.IgnoreTopFunction("github.com/golang/glog.(*loggingT).flushDaemon"),
goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"),
}
goleak.VerifyTestMain(m, opts...)
}
65 changes: 65 additions & 0 deletions tests/realtikvtest/loaddatatest/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2023 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 loaddatatest

import (
"fmt"
"testing"

"github.com/fsouza/fake-gcs-server/fakestorage"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/tests/realtikvtest"
"github.com/stretchr/testify/suite"
)

type mockGCSSuite struct {
suite.Suite

server *fakestorage.Server
store kv.Storage
tk *testkit.TestKit
}

var (
gcsHost = "127.0.0.1"
gcsPort = uint16(4443)
// for fake gcs server, we must use this endpoint format
// NOTE: must end with '/'
gcsEndpointFormat = "http://%s:%d/storage/v1/"
gcsEndpoint = fmt.Sprintf(gcsEndpointFormat, gcsHost, gcsPort)
)

func TestLoadRemote(t *testing.T) {
suite.Run(t, &mockGCSSuite{})
}

func (s *mockGCSSuite) SetupSuite() {
var err error
opt := fakestorage.Options{
Scheme: "http",
Host: gcsHost,
Port: gcsPort,
PublicHost: gcsHost,
}
s.server, err = fakestorage.NewServerWithOptions(opt)
s.Require().NoError(err)
s.store = realtikvtest.CreateMockStoreAndSetup(s.T())
s.tk = testkit.NewTestKit(s.T(), s.store)
}

func (s *mockGCSSuite) TearDownSuite() {
s.server.Stop()
}

0 comments on commit 193023b

Please sign in to comment.