Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Nov 28, 2024
1 parent 7782bd7 commit a5e5fa5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
12 changes: 0 additions & 12 deletions server/api/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/slice"
"github.com/tikv/pd/pkg/utils/apiutil"
"github.com/tikv/pd/pkg/utils/etcdutil"
"github.com/tikv/pd/pkg/utils/keypath"
Expand Down Expand Up @@ -71,10 +70,6 @@ func getMembers(svr *server.Server) (*pdpb.GetMembersResponse, error) {
if members.GetHeader().GetError() != nil {
return nil, errors.WithStack(errors.New(members.GetHeader().GetError().String()))
}
dclocationDistribution, err := svr.GetTSOAllocatorManager().GetClusterDCLocationsFromEtcd()
if err != nil {
return nil, errors.WithStack(err)
}
for _, m := range members.GetMembers() {
var e error
m.BinaryVersion, e = svr.GetMember().GetMemberBinaryVersion(m.GetMemberId())
Expand All @@ -100,13 +95,6 @@ func getMembers(svr *server.Server) (*pdpb.GetMembersResponse, error) {
log.Error("failed to load git hash", zap.Uint64("member", m.GetMemberId()), errs.ZapError(e))
continue
}
for dcLocation, serverIDs := range dclocationDistribution {
found := slice.Contains(serverIDs, m.MemberId)
if found {
m.DcLocation = dcLocation
break
}
}
}
return members, nil
}
Expand Down
34 changes: 13 additions & 21 deletions tests/integrations/mcs/tso/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,8 @@ func checkTSOPath(re *require.Assertions, isKeyspaceEnabled bool) {
re.NoError(pdLeader.BootstrapCluster())
backendEndpoints := pdLeader.GetAddr()
client := pdLeader.GetEtcdClient()
if isKeyspaceEnabled {
re.Equal(0, getEtcdTimestampKeyNum(re, client))
} else {
re.Equal(1, getEtcdTimestampKeyNum(re, client))
}
// PD will provide TSO service, so etcd has one key related to the timestamp.
re.Equal(1, getEtcdTimestampKeyNum(re, client))

_, cleanup := tests.StartSingleTSOTestServer(ctx, re, backendEndpoints, tempurl.Alloc())
defer cleanup()
Expand Down Expand Up @@ -278,13 +275,19 @@ func TestForwardTSORelated(t *testing.T) {
cfg := leaderServer.GetMicroServiceConfig().Clone()
cfg.EnableTSODynamicSwitching = false
leaderServer.SetMicroServiceConfig(*cfg)
// Unable to use the tso-related interface without tso server
suite.checkUnavailableTSO(re)
suite.checkAvailableTSO(re)
// If EnableTSODynamicSwitching is false, the tso server will be provided by PD.
// The tso server won't affect the PD.
tc, err := tests.NewTestTSOCluster(suite.ctx, 1, suite.backendEndpoints)
re.NoError(err)
defer tc.Destroy()
tc.WaitForDefaultPrimaryServing(re)
suite.checkAvailableTSO(re)

cfg = leaderServer.GetMicroServiceConfig().Clone()
cfg.EnableTSODynamicSwitching = true
leaderServer.SetMicroServiceConfig(*cfg)
suite.checkAvailableTSO(re)
}

func TestForwardTSOWhenPrimaryChanged(t *testing.T) {
Expand Down Expand Up @@ -464,17 +467,6 @@ func (suite *APIServerForward) addRegions() {
}
}

func (suite *APIServerForward) checkUnavailableTSO(re *require.Assertions) {
_, _, err := suite.pdClient.GetTS(suite.ctx)
re.Error(err)
// try to update gc safe point
_, err = suite.pdClient.UpdateServiceGCSafePoint(suite.ctx, "a", 1000, 1)
re.Error(err)
// try to set external ts
err = suite.pdClient.SetExternalTimestamp(suite.ctx, 1000)
re.Error(err)
}

func (suite *APIServerForward) checkAvailableTSO(re *require.Assertions) {
mcs.WaitForTSOServiceAvailable(suite.ctx, re, suite.pdClient)
// try to get ts
Expand Down Expand Up @@ -648,10 +640,10 @@ func TestTSOServiceSwitch(t *testing.T) {

// Wait for the configuration change to take effect
time.Sleep(300 * time.Millisecond)
// Verify PD is not providing TSO service multiple times
// PD should provide TSO service
for range 10 {
err = checkTSOMonotonic(ctx, pdClient, &globalLastTS, 1)
re.Error(err, "TSO service should not be available")
re.NoError(err, "TSO service should not be available")
time.Sleep(10 * time.Millisecond)
}

Expand All @@ -661,7 +653,7 @@ func TestTSOServiceSwitch(t *testing.T) {
cfg.EnableTSODynamicSwitching = true
pdLeader.GetServer().SetMicroServiceConfig(*cfg)

// Wait for PD to detect the change
// Wait for PD to detect the change, PD will keep providing TSO service
time.Sleep(300 * time.Millisecond)

// Verify PD is now providing TSO service and timestamps are monotonically increasing
Expand Down

0 comments on commit a5e5fa5

Please sign in to comment.