From 7c863e6972c99d25d2413d889bb8574de6314297 Mon Sep 17 00:00:00 2001 From: Chunzhu Li Date: Wed, 2 Aug 2023 14:34:31 +0800 Subject: [PATCH 1/3] fix lightning tls WithHost --- br/pkg/lightning/common/security.go | 8 +++++ br/pkg/lightning/common/security_test.go | 43 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/br/pkg/lightning/common/security.go b/br/pkg/lightning/common/security.go index 46a5ffb821ffc..9932b10c8ed9b 100644 --- a/br/pkg/lightning/common/security.go +++ b/br/pkg/lightning/common/security.go @@ -20,6 +20,7 @@ import ( "net" "net/http" "net/http/httptest" + "strings" "github.com/pingcap/errors" "github.com/pingcap/tidb/br/pkg/httputil" @@ -88,8 +89,15 @@ func NewTLSFromMockServer(server *httptest.Server) *TLS { } } +// GetMockTLSUrl returns tls's host for mock test +func GetMockTLSUrl(tls *TLS) string { + return tls.url +} + // WithHost creates a new TLS instance with the host replaced. func (tc *TLS) WithHost(host string) *TLS { + host = strings.TrimPrefix(host, "http://") + host = strings.TrimPrefix(host, "https://") var url string if tc.inner != nil { url = "https://" + host diff --git a/br/pkg/lightning/common/security_test.go b/br/pkg/lightning/common/security_test.go index e34ef3622500c..4ba9825efc883 100644 --- a/br/pkg/lightning/common/security_test.go +++ b/br/pkg/lightning/common/security_test.go @@ -70,6 +70,49 @@ func TestGetJSONSecure(t *testing.T) { require.Equal(t, "/dddd", result.Path) } +func TestWithHost(t *testing.T) { + mockTLSServer := httptest.NewTLSServer(http.HandlerFunc(respondPathHandler)) + defer mockTLSServer.Close() + mockServer := httptest.NewServer(http.HandlerFunc(respondPathHandler)) + defer mockServer.Close() + + testCases := []struct { + expected string + host string + secure bool + }{ + { + "https://127.0.0.1:2379", + "http://127.0.0.1:2379", + true, + }, + { + "http://127.0.0.1:2379", + "https://127.0.0.1:2379", + false, + }, + { + "http://127.0.0.1:2379/pd/api/v1/stores", + "127.0.0.1:2379/pd/api/v1/stores", + false, + }, + { + "https://127.0.0.1:2379", + "127.0.0.1:2379", + true, + }, + } + + for _, testCase := range testCases { + server := mockServer + if testCase.secure { + server = mockTLSServer + } + tls := common.NewTLSFromMockServer(server) + require.Equal(t, testCase.expected, common.GetMockTLSUrl(tls.WithHost(testCase.host))) + } +} + func TestInvalidTLS(t *testing.T) { tempDir := t.TempDir() caPath := filepath.Join(tempDir, "ca.pem") From 4e5c9aa40700393cf2b65968da7f0ef6c6c2992a Mon Sep 17 00:00:00 2001 From: Chunzhu Li Date: Wed, 2 Aug 2023 15:11:27 +0800 Subject: [PATCH 2/3] fix bazel --- br/pkg/lightning/common/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/br/pkg/lightning/common/BUILD.bazel b/br/pkg/lightning/common/BUILD.bazel index 52ff0a652c9c5..4d6dedbe8e752 100644 --- a/br/pkg/lightning/common/BUILD.bazel +++ b/br/pkg/lightning/common/BUILD.bazel @@ -104,7 +104,7 @@ go_test( ], embed = [":common"], flaky = True, - shard_count = 19, + shard_count = 20, deps = [ "//br/pkg/errors", "//br/pkg/lightning/log", From bb979f25388985a66bb2cd0ea814084e2156050e Mon Sep 17 00:00:00 2001 From: Chunzhu Li Date: Thu, 3 Aug 2023 14:19:12 +0800 Subject: [PATCH 3/3] cherry-pick https://github.com/pingcap/tidb/pull/45742 --- br/tests/lightning_partitioned-table/run.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/br/tests/lightning_partitioned-table/run.sh b/br/tests/lightning_partitioned-table/run.sh index 39ea8a68b0b1c..3dff86f23346b 100755 --- a/br/tests/lightning_partitioned-table/run.sh +++ b/br/tests/lightning_partitioned-table/run.sh @@ -25,8 +25,6 @@ for BACKEND in tidb local; do run_sql 'DROP DATABASE IF EXISTS partitioned;' - # DEFAULT List partitioning needs to be enabled for defaultlist table - run_sql 'set @@global.tidb_enable_default_list_partition=1;' run_lightning --backend $BACKEND run_sql 'SELECT count(1), sum(a) FROM partitioned.a;'