Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Nov 3, 2023
1 parent 689fcbe commit c544fc5
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 12 deletions.
16 changes: 10 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
require (
github.com/AlekSi/gocov-xml v1.0.0
github.com/BurntSushi/toml v0.3.1
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/aws/aws-sdk-go-v2/config v1.18.19
github.com/aws/aws-sdk-go-v2/credentials v1.13.18
github.com/aws/aws-sdk-go-v2/service/kms v1.20.8
Expand Down Expand Up @@ -49,20 +50,23 @@ require (
github.com/swaggo/http-swagger v1.2.6
github.com/swaggo/swag v1.8.3
github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965
github.com/tikv/pd/client v0.0.0-20231101084237-a1a1eea8dafd
github.com/unrolled/render v1.0.1
github.com/urfave/negroni v0.3.0
go.etcd.io/etcd v0.5.0-alpha.5.0.20220915004622-85b640cee793
go.uber.org/atomic v1.10.0
go.uber.org/goleak v1.1.12
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230108222341-4b8118a2686a
golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4
golang.org/x/text v0.13.0
golang.org/x/time v0.1.0
golang.org/x/tools v0.6.0
google.golang.org/grpc v1.54.0
gotest.tools/gotestsum v1.7.0
)

require github.com/opentracing/opentracing-go v1.2.0 // indirect

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
Expand Down Expand Up @@ -107,7 +111,7 @@ require (
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/go-resty/resty/v2 v2.6.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/go-sql-driver/mysql v1.7.0
github.com/goccy/go-graphviz v0.0.9 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
Expand Down Expand Up @@ -179,7 +183,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/image v0.5.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sync v0.1.0 // indirect
Expand All @@ -192,10 +196,10 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/datatypes v1.1.0 // indirect
gorm.io/driver/mysql v1.4.5 // indirect
gorm.io/driver/mysql v1.4.5
gorm.io/driver/sqlite v1.4.3 // indirect
gorm.io/gorm v1.24.3 // indirect
moul.io/zapgorm2 v1.1.0 // indirect
gorm.io/gorm v1.24.3
moul.io/zapgorm2 v1.1.0
sigs.k8s.io/yaml v1.2.0 // indirect
)

Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/AlekSi/gocov-xml v1.0.0 h1:4QctJBgXEkbzeKz6PJy6bt3JSPNSN4I2mITYW+eKUo
github.com/AlekSi/gocov-xml v1.0.0/go.mod h1:J0qYeZ6tDg4oZubW9mAAgxlqw39PDfoEkzB3HXSbEuA=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
Expand Down Expand Up @@ -414,6 +416,8 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q=
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
Expand Down Expand Up @@ -568,6 +572,8 @@ github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JT
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tikv/pd/client v0.0.0-20231101084237-a1a1eea8dafd h1:1m+3EAxPNQ3A6LzUqVI7u/vLoQcCJ0Z+y7rFgtjkUII=
github.com/tikv/pd/client v0.0.0-20231101084237-a1a1eea8dafd/go.mod h1:cd6zBqRM9aogxf26K8NnFRPVtq9BnRE59tKEpX8IaWQ=
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM=
github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
Expand Down Expand Up @@ -657,6 +663,7 @@ golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20230108222341-4b8118a2686a h1:tlXy25amD5A7gOfbXdqCGN5k8ESEed/Ee1E5RcrYnqU=
golang.org/x/exp v0.0.0-20230108222341-4b8118a2686a/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
Expand All @@ -674,6 +681,7 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
4 changes: 2 additions & 2 deletions pkg/member/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type EmbeddedEtcdMember struct {
id uint64 // etcd server id.
member *pdpb.Member // current PD's info.
rootPath string
// memberValue is the serialized string of `member`. It will be save in
// memberValue is the serialized string of `member`. It will be saved in
// etcd leader key when the PD node is successfully elected as the PD leader
// of the cluster. Every write will use it to check PD leadership.
memberValue string
Expand Down Expand Up @@ -186,7 +186,7 @@ func (m *EmbeddedEtcdMember) KeepLeader(ctx context.Context) {
m.leadership.Keep(ctx)
}

// PreCheckLeader does some pre-check before checking whether or not it's the leader.
// PreCheckLeader does some pre-check before checking whether it's the leader.
func (m *EmbeddedEtcdMember) PreCheckLeader() error {
if m.GetEtcdLeader() == 0 {
return errs.ErrEtcdLeaderNotFound
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/stretchr/testify v1.8.2
github.com/tikv/pd v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-20231101084237-a1a1eea8dafd
go.etcd.io/etcd v0.5.0-alpha.5.0.20220915004622-85b640cee793
go.uber.org/goleak v1.1.12
go.uber.org/zap v1.24.0
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/stretchr/testify v1.8.2
github.com/tikv/pd v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-20231101084237-a1a1eea8dafd
go.etcd.io/etcd v0.5.0-alpha.5.0.20220915004622-85b640cee793
go.uber.org/goleak v1.1.12
go.uber.org/zap v1.24.0
Expand Down
21 changes: 21 additions & 0 deletions tests/integrations/real/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 TiKV Authors
//
// 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 real

import flag "github.com/spf13/pflag"

var (
pdAddrs = flag.String("pd-addrs", "127.0.0.1:2379", "pd addrs")
)
41 changes: 41 additions & 0 deletions tests/integrations/real/min_resolved_ts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2023 TiKV Authors
//
// 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 real

import (
"context"
"fmt"
"github.com/stretchr/testify/require"
"testing"
)

func TestTS(t *testing.T) {
re := require.New(t)
_, cancel := context.WithCancel(context.Background())
defer cancel()

db := OpenTestDB(t)
db.MustExec("use test")
db.MustExec("drop table if exists t")
db.MustExec("create table t(a int, index i(a))")
db.MustExec("insert t values (1), (2), (3)")

var ts uint64
err := db.inner.Begin().Raw("select @@tidb_current_ts").Scan(&ts).Rollback()
re.NoError(err.Error)

fmt.Printf("ts: %s\n", GetTimeFromTS(ts))
db.MustClose()
}
81 changes: 81 additions & 0 deletions tests/integrations/real/mock_db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package real

import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
"moul.io/zapgorm2"
"testing"
"time"

"github.com/DATA-DOG/go-sqlmock"
mysqldriver "github.com/go-sql-driver/mysql"
"github.com/pingcap/log"
"github.com/stretchr/testify/require"
)

type TestDB struct {
inner *gorm.DB
require *require.Assertions

isUnderlyingMocked bool
mock sqlmock.Sqlmock
}

func OpenTestDB(t *testing.T, configModifier ...func(*mysqldriver.Config, *gorm.Config)) *TestDB {
r := require.New(t)

dsn := mysqldriver.NewConfig()
dsn.Net = "tcp"
dsn.Addr = "127.0.0.1:4000"
dsn.Params = map[string]string{"time_zone": "'+00:00'"}
dsn.ParseTime = true
dsn.Loc = time.UTC
dsn.User = "root"
dsn.DBName = "test"

config := &gorm.Config{
Logger: zapgorm2.New(log.L()),
}

for _, m := range configModifier {
m(dsn, config)
}

db, err := gorm.Open(mysql.Open(dsn.FormatDSN()), config)
r.NoError(err)

return &TestDB{
inner: db.Debug(),
require: r,
}
}

func (db *TestDB) MustClose() {
if db.isUnderlyingMocked {
db.mock.ExpectClose()
}

d, err := db.inner.DB()
db.require.NoError(err)

err = d.Close()
db.require.NoError(err)
}

func (db *TestDB) Gorm() *gorm.DB {
return db.inner
}

func (db *TestDB) MustExec(sql string, values ...interface{}) {
err := db.inner.Exec(sql, values...).Error
db.require.NoError(err)
}

func (db *TestDB) Mocker() sqlmock.Sqlmock {
db.require.True(db.isUnderlyingMocked)
return db.mock
}

func (db *TestDB) MustMeetMockExpectation() {
db.require.Nil(db.Mocker().ExpectationsWereMet())
}
18 changes: 18 additions & 0 deletions tests/integrations/real/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package real

import (
"time"
)

const physicalShiftBits = 18

// GetTimeFromTS extracts time.Time from a timestamp.
func GetTimeFromTS(ts uint64) time.Time {
ms := ExtractPhysical(ts)
return time.Unix(ms/1e3, (ms%1e3)*1e6)
}

// ExtractPhysical returns a ts's physical part.
func ExtractPhysical(ts uint64) int64 {
return int64(ts >> physicalShiftBits)
}
12 changes: 12 additions & 0 deletions tests/integrations/real/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package real

import (
"go.uber.org/goleak"
"testing"

"github.com/tikv/pd/pkg/utils/testutil"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m, testutil.LeakOptions...)
}
2 changes: 1 addition & 1 deletion tests/integrations/tso/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/pingcap/kvproto v0.0.0-20231018065736-c0689aded40c
github.com/stretchr/testify v1.8.4
github.com/tikv/pd v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-20231101084237-a1a1eea8dafd
github.com/tikv/pd/tests/integrations/mcs v0.0.0-00010101000000-000000000000
google.golang.org/grpc v1.54.0
)
Expand Down
2 changes: 1 addition & 1 deletion tools/pd-api-bench/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/tikv/pd v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-20231101084237-a1a1eea8dafd
go.uber.org/zap v1.24.0
google.golang.org/grpc v1.54.0
)
Expand Down

0 comments on commit c544fc5

Please sign in to comment.