Skip to content

Commit

Permalink
import into: split real-tikv test (#46299)
Browse files Browse the repository at this point in the history
ref #42930
  • Loading branch information
D3Hunter authored Aug 22, 2023
1 parent 0c3bbc1 commit ec60369
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,27 @@ bazel_importintotest: failpoint-enable bazel_ci_simple_prepare
-- //tests/realtikvtest/importintotest/...
./build/jenkins_collect_coverage.sh

# on timeout, bazel won't print log sometimes, so we use --test_output=all to print log always
bazel_importintotest2: failpoint-enable bazel_ci_simple_prepare
bazel $(BAZEL_GLOBAL_CONFIG) coverage $(BAZEL_CMD_CONFIG) --test_output=all --test_arg=-with-real-tikv --define gotags=deadlock,intest \
--@io_bazel_rules_go//go/config:cover_format=go_cover \
-- //tests/realtikvtest/importintotest2/...
./build/jenkins_collect_coverage.sh

# on timeout, bazel won't print log sometimes, so we use --test_output=all to print log always
bazel_importintotest3: failpoint-enable bazel_ci_simple_prepare
bazel $(BAZEL_GLOBAL_CONFIG) coverage $(BAZEL_CMD_CONFIG) --test_output=all --test_arg=-with-real-tikv --define gotags=deadlock,intest \
--@io_bazel_rules_go//go/config:cover_format=go_cover \
-- //tests/realtikvtest/importintotest3/...
./build/jenkins_collect_coverage.sh

# on timeout, bazel won't print log sometimes, so we use --test_output=all to print log always
bazel_importintotest4: failpoint-enable bazel_ci_simple_prepare
bazel $(BAZEL_GLOBAL_CONFIG) coverage $(BAZEL_CMD_CONFIG) --test_output=all --test_arg=-with-real-tikv --define gotags=deadlock,intest \
--@io_bazel_rules_go//go/config:cover_format=go_cover \
-- //tests/realtikvtest/importintotest4/...
./build/jenkins_collect_coverage.sh

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

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

go_test(
name = "importintotest2_test",
timeout = "moderate",
srcs = [
"dummy_test.go",
"main_test.go",
],
flaky = True,
race = "on",
deps = [
"//config",
"//kv",
"//testkit",
"//tests/realtikvtest",
"@com_github_fsouza_fake_gcs_server//fakestorage",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
"@com_github_stretchr_testify//suite",
],
)
19 changes: 19 additions & 0 deletions tests/realtikvtest/importintotest2/dummy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 importintotest

func (s *mockGCSSuite) TestDummy() {
s.True(true, gcsEndpoint)
}
93 changes: 93 additions & 0 deletions tests/realtikvtest/importintotest2/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// 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 importintotest

import (
"fmt"
"testing"

"github.com/fsouza/fake-gcs-server/fakestorage"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/tests/realtikvtest"
"github.com/stretchr/testify/require"
"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() {
s.Require().True(*realtikvtest.WithRealTiKV)
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()
}

func (s *mockGCSSuite) enableFailpoint(path, term string) {
require.NoError(s.T(), failpoint.Enable(path, term))
s.T().Cleanup(func() {
_ = failpoint.Disable(path)
})
}

func (s *mockGCSSuite) cleanupSysTables() {
s.tk.MustExec("delete from mysql.tidb_import_jobs")
s.tk.MustExec("delete from mysql.tidb_global_task")
s.tk.MustExec("delete from mysql.tidb_background_subtask")
}

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

func TestMain(m *testing.M) {
realtikvtest.RunTestMain(m)
}
22 changes: 22 additions & 0 deletions tests/realtikvtest/importintotest3/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "importintotest3_test",
timeout = "moderate",
srcs = [
"dummy_test.go",
"main_test.go",
],
flaky = True,
race = "on",
deps = [
"//config",
"//kv",
"//testkit",
"//tests/realtikvtest",
"@com_github_fsouza_fake_gcs_server//fakestorage",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
"@com_github_stretchr_testify//suite",
],
)
19 changes: 19 additions & 0 deletions tests/realtikvtest/importintotest3/dummy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 importintotest

func (s *mockGCSSuite) TestDummy() {
s.True(true, gcsEndpoint)
}
93 changes: 93 additions & 0 deletions tests/realtikvtest/importintotest3/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// 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 importintotest

import (
"fmt"
"testing"

"github.com/fsouza/fake-gcs-server/fakestorage"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/tests/realtikvtest"
"github.com/stretchr/testify/require"
"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() {
s.Require().True(*realtikvtest.WithRealTiKV)
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()
}

func (s *mockGCSSuite) enableFailpoint(path, term string) {
require.NoError(s.T(), failpoint.Enable(path, term))
s.T().Cleanup(func() {
_ = failpoint.Disable(path)
})
}

func (s *mockGCSSuite) cleanupSysTables() {
s.tk.MustExec("delete from mysql.tidb_import_jobs")
s.tk.MustExec("delete from mysql.tidb_global_task")
s.tk.MustExec("delete from mysql.tidb_background_subtask")
}

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

func TestMain(m *testing.M) {
realtikvtest.RunTestMain(m)
}
22 changes: 22 additions & 0 deletions tests/realtikvtest/importintotest4/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "importintotest4_test",
timeout = "moderate",
srcs = [
"dummy_test.go",
"main_test.go",
],
flaky = True,
race = "on",
deps = [
"//config",
"//kv",
"//testkit",
"//tests/realtikvtest",
"@com_github_fsouza_fake_gcs_server//fakestorage",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
"@com_github_stretchr_testify//suite",
],
)
19 changes: 19 additions & 0 deletions tests/realtikvtest/importintotest4/dummy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 importintotest

func (s *mockGCSSuite) TestDummy() {
s.True(true, gcsEndpoint)
}
Loading

0 comments on commit ec60369

Please sign in to comment.