Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add realtikvtest for load data #42762

Merged
merged 6 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need change to another port to reduce conflict, maybe we can use freeport in future.

And seems this test suite is very common, we can provide a constructor for it in future

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, when running the run-real-tikv, we only run with a simple goroutine in the container. It is not a severe problem.

// 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()
}